简体   繁体   中英

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. However, I am getting error 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?

to load the model you have to use model.save in case you want to load onlyy the wieghts model.save_weights . In your case use model.save and it will upload the model. Let me know. Or you can load the model from json.

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_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

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

let me know!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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