簡體   English   中英

評估預訓練的 model 時遇到問題

[英]Trouble with evaluating pre-trained model

我有一個微調版本的 inceptionV3 model,我想在新數據集上進行測試。 但是,我收到錯誤No model found in config file.

這是我的代碼,

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)

這里有什么錯誤? 如何糾正並測試我的 model?

要加載 model 您必須使用model.save以防您只想加載 wieghts model.save_weights 在您的情況下,使用model.save它將上傳 model。 讓我知道。 或者您可以從 json 加載 model。

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

你有重量,所以......加載 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)

將砝碼裝入新的 model

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

讓我知道!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM