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 = [] for i in range(20): start_time = time.time() preds = model.predict(x) delta = time.time() - start_time times.append(delta) mean_delta = np.array(times).mean() fps = 1 / mean_delta