简体   繁体   English

评估预训练的 model 时遇到问题

[英]Trouble with evaluating pre-trained model

I have a fine-tuned version of the inceptionV3 model that I want to test on a new dataset.我有一个微调版本的 inceptionV3 model,我想在新数据集上进行测试。 However, I am getting error No model found in config file.但是,我收到错误No model found in config file.

This is my code,这是我的代码,

from tensorflow import keras
model = keras.models.load_model('/home/saved_model/CNN_inceptionv3.h5')

CLASS_1_data = '/home/spectrograms/data/c1'

def label_img(img):
    word_label = img[:5]
    if img[1] == '1':
      return [1,0]
    elif img[1] == '3':
      return [0,1]

def create_data(data,loc): #loads data into a list
    for img in tqdm(os.listdir(loc)):
        label = label_img(img)
        path = os.path.join(loc,img)
        img = Image.open(path) 
        img = ImageOps.grayscale(img) 
        # w,h = img.size
        # img = img.resize((w//3,h//3))
        data.append([np.array(img),np.array(label)])
    return data

def make_X_and_Y(set): #split data into numpy arrays of inputs and outputs
  set_X,set_Y = [],[]
  n = len(set)
  for i in range(n):
    set_X.append(set[i][0])
    set_Y.append(set[i][1])
  return np.array(set_X),np.array(set_Y)

data = []
data = create_data(data,CLASS_1_data)
data = np.array(data)

X_data,Y_data = make_X_and_Y(data)

X_data = X_data.astype('float32')

X_data /= 255 

results = model.evaluate(X-data, Y_data, batch_size=5)

What is the error here?这里有什么错误? How can I correct it and test my model?如何纠正并测试我的 model?

to load the model you have to use model.save in case you want to load onlyy the wieghts model.save_weights .要加载 model 您必须使用model.save以防您只想加载 wieghts model.save_weights In your case use model.save and it will upload the model.在您的情况下,使用model.save它将上传 model。 Let me know.让我知道。 Or you can load the model from json.或者您可以从 json 加载 model。

model_json = model.to_json()
with open("model.json", "w") as json_file:
    json_file.write(model_json)

You have the weights so... load json and create model你有重量,所以......加载 json 并创建 model

json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)

load weights into new model将砝码装入新的 model

loaded_model.load_weights("model.h5")
print("Loaded model from disk")

let me know!让我知道!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM