Esempio n. 1
0
# Path to save the model h5 file.
model_fname = os.path.join(model_path, "model.h5")

os.makedirs(model_path, exist_ok=True)

img_height = 299

model = Net(weights="imagenet", input_shape=(img_height, img_height, 3))

# Load the image for prediction.
img = image.load_img(img_path, target_size=(img_height, img_height))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

preds = model.predict(x)
# decode the results into a list of tuples (class, description, probability)
# (one such list for each sample in the batch)
print("Predicted:", decode_predictions(preds, top=3)[0])
# Predicted: [(u'n02504013', u'Indian_elephant', 0.82658225), (u'n01871265', u'tusker', 0.1122357), (u'n02504458', u'African_elephant', 0.061040461)]

# Save the h5 file to path specified.
model.save(model_fname)

# ## Benchmark Keras prediction speed.

# In[2]:

import time

times = []