1. 程式人生 > >keras 模型讀取和預測

keras 模型讀取和預測

from keras.preprocessing import image
import numpy as np
from keras.models import load_model

img_path = "data2/train/dogs/3046.jpg"
img = image.load_img(img_path, target_size=(113, 113))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
model = load_model('model_weight.h5') 
preds = model.predict(x)
print(preds)