J'essaye de créer un exemple en utilisant le Keras construit dans la dernière version de TensorFlow de Google. Cet exemple devrait être capable de classer une image classique d'un éléphant. Le code ressemble à ceci:TensorFlow 1.2.1 et InceptionV3 pour classer une image
# Import a few libraries for use later
from PIL import Image as IMG
from tensorflow.contrib.keras.python.keras.preprocessing import image
from tensorflow.contrib.keras.python.keras.applications.inception_v3 import InceptionV3
from tensorflow.contrib.keras.python.keras.applications.inception_v3 import preprocess_input, decode_predictions
# Get a copy of the Inception model
print('Loading Inception V3...\n')
model = InceptionV3(weights='imagenet', include_top=True)
print ('Inception V3 loaded\n')
# Read the elephant JPG
elephant_img = IMG.open('elephant.jpg')
# Convert the elephant to an array
elephant = image.img_to_array(elephant_img)
elephant = preprocess_input(elephant)
elephant_preds = model.predict(elephant)
print ('Predictions: ', decode_predictions(elephant_preds))
Malheureusement, je me fais une erreur en essayant d'évaluer le modèle avec model.predict:
ValueError: Error when checking : expected input_1 to have 4 dimensions, but got array with shape (299, 299, 3)
Ce code est tiré et basé sur the excellent example coremltools-keras-inception et sera élargi plus quand il est compris.
Pourriez-vous partager tout le retraçage? –
Je peux le jeter en référence si vous voulez encore mais la réponse explique ce qui s'est passé et j'ai mentionné exactement quelle ligne a échoué. –
Je vois maintenant que vous avez posté une réponse, bon travail, ignorez mon dernier :) –