I’ve followed two tutorials now:
and
Literally copying and pasting for the most part.
In both cases, when I try to run predict() with my model, I get identical results no matter what image I feed in, eg:
======================================
https://storage.googleapis.com/download.tensorflow.org/example_images/592px-Red_sunflower.jpg
1/1 [==============================] - 0s 253ms/step
[[ -3.505105 -11.280068 3.311004 4.456965 5.7767043]]
tf.Tensor([6.8850248e-05 2.8925562e-08 6.2820844e-02 1.9760065e-01 7.3950970e-01], shape=(5,), dtype=float32)
This image most likely belongs to tulips with a 73.95 percent confidence.
======================================
http://www.photos-public-domain.com/wp-content/uploads/2012/04/pink-tulip-with-one-petal-open.jpg
1/1 [==============================] - 0s 18ms/step
[[ -3.505105 -11.280068 3.311004 4.456965 5.7767043]]
tf.Tensor([6.8850248e-05 2.8925562e-08 6.2820844e-02 1.9760065e-01 7.3950970e-01], shape=(5,), dtype=float32)
This image most likely belongs to tulips with a 73.95 percent confidence.
======================================
http://extension.msstate.edu/sites/default/files/sg20140428_hybrid_300.jpg
1/1 [==============================] - 0s 20ms/step
[[ -3.505105 -11.280068 3.311004 4.456965 5.7767043]]
tf.Tensor([6.8850248e-05 2.8925562e-08 6.2820844e-02 1.9760065e-01 7.3950970e-01], shape=(5,), dtype=float32)
This image most likely belongs to tulips with a 73.95 percent confidence.
What could I be doing wrong?
This is my script for testing out the model:
class_names = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']
model = tf.keras.models.load_model('scripts/my_tutorial_model')
batch_size = 32
img_height = 180
img_width = 180
list = [ "https://storage.googleapis.com/download.tensorflow.org/example_images/592px-Red_sunflower.jpg", \
"http://www.photos-public-domain.com/wp-content/uploads/2012/04/pink-tulip-with-one-petal-open.jpg", \
"http://extension.msstate.edu/sites/default/files/sg20140428_hybrid_300.jpg" ]
for i in list:
print('======================================')
print(i)
sunflower_url = i
sunflower_path = tf.keras.utils.get_file('Red_sunflower', origin=sunflower_url)
img = tf.keras.utils.load_img(
sunflower_path, target_size=(img_height, img_width)
)
img_array = tf.keras.utils.img_to_array(img)
img_array = tf.expand_dims(img_array, 0) # Create a batch
predictions = model.predict(img_array)
print(predictions)
score = tf.nn.softmax(predictions[0])
print(score)
print(
"This image most likely belongs to {} with a {:.2f} percent confidence."
.format(class_names[np.argmax(score)], 100 * np.max(score))
)
Is it the model itself? Or am I doing something daft in my actual script.