Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我在使用keras.load_模型加载模型后得到零分(准确度)?_Python_Tensorflow_Machine Learning_Keras_Deep Learning - Fatal编程技术网

Python 为什么我在使用keras.load_模型加载模型后得到零分(准确度)?

Python 为什么我在使用keras.load_模型加载模型后得到零分(准确度)?,python,tensorflow,machine-learning,keras,deep-learning,Python,Tensorflow,Machine Learning,Keras,Deep Learning,有人能帮我吗?我花了12个小时训练4个模型,当我加载_模型进一步评估它们(打印混淆矩阵和ROC曲线)时,精确度和F1分数完全为零 这是我以前保存模型的方式,该模型产生(1.0 F1分数) 然后这是另一本笔记本上的代码,我用它来创建我需要的曲线,为我的分类报告生成全零 reconstructed_model = keras.models.load_model("C:/model.h5") reconstructed_model.compile(optimizer=Adam(0.

有人能帮我吗?我花了12个小时训练4个模型,当我加载_模型进一步评估它们(打印混淆矩阵和ROC曲线)时,精确度和F1分数完全为零

这是我以前保存模型的方式,该模型产生(1.0 F1分数)

然后这是另一本笔记本上的代码,我用它来创建我需要的曲线,为我的分类报告生成全零

reconstructed_model = keras.models.load_model("C:/model.h5")
reconstructed_model.compile(optimizer=Adam(0.0001),
             loss='categorical_crossentropy',
             metrics=['accuracy'])



test_generator.reset() 

from sklearn.metrics import multilabel_confusion_matrix,classification_report
import sklearn.preprocessing
import matplotlib.pyplot as plt

predictions = reconstructed_model.predict_generator(generator=test_generator,
                                       steps=test_generator.samples/test_generator.batch_size,
                                       max_queue_size=10,
                                       use_multiprocessing=False,
                                       verbose=1)


y_pred = np.argmax(predictions, axis=1)

true_classes = test_generator.classes

class_labels = list(test_generator.class_indices.keys())   

print(class_labels)

print(multilabel_confusion_matrix(test_generator.classes, y_pred))

report = classification_report(true_classes, y_pred, target_names=class_labels)
print(report)



我使用生成器来加载数据,我确保代码是相同的,并且我以完全相同的方式进行了预处理。。我使用的是TF=2.3.0,我读到它可能在load_模型上有一个缺陷(我尝试了sparse_Cateogral_crossentropy,不起作用…),而且我还有另一个迁移学习模型,我几天前以完全相同的方式训练过它,并使用了TF 2.3.0,它不会产生同样的问题


有人能帮我一下吗?我已经很忙了,有人在吗?????????
reconstructed_model = keras.models.load_model("C:/model.h5")
reconstructed_model.compile(optimizer=Adam(0.0001),
             loss='categorical_crossentropy',
             metrics=['accuracy'])



test_generator.reset() 

from sklearn.metrics import multilabel_confusion_matrix,classification_report
import sklearn.preprocessing
import matplotlib.pyplot as plt

predictions = reconstructed_model.predict_generator(generator=test_generator,
                                       steps=test_generator.samples/test_generator.batch_size,
                                       max_queue_size=10,
                                       use_multiprocessing=False,
                                       verbose=1)


y_pred = np.argmax(predictions, axis=1)

true_classes = test_generator.classes

class_labels = list(test_generator.class_indices.keys())   

print(class_labels)

print(multilabel_confusion_matrix(test_generator.classes, y_pred))

report = classification_report(true_classes, y_pred, target_names=class_labels)
print(report)