You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The image-to-json.py conversion script used in chapter 13 does not preprocess the data, instead leaving all inputs as values between 0-255. If used with the model from chapter 3, the predictions will be more or less random.
An easy solution is to convert the value to floating-point numbers. Here's the script I use:
importjsonimportnumpyasnpimporttensorflowastffromPILimportImagemodel=tf.keras.models.load_model('cats_vs_dogs_01')
# The layer name of the input needs to be present in the JSON file.input_layer_name=model.layers[0].nameimg=Image.open('data/cats-vs-dogs/cat.9827.jpg')
# Because the values are floating-point, don't make the image to largeimg.thumbnail((128, 128), Image.ANTIALIAS)
# Preprocess the datadata=np.asarray(img) /255.withopen('cat_image.json', 'w') asfp:
json.dump({input_layer_name: data.tolist()}, fp)
The image-to-json.py conversion script used in chapter 13 does not preprocess the data, instead leaving all inputs as values between 0-255. If used with the model from chapter 3, the predictions will be more or less random.
An easy solution is to convert the value to floating-point numbers. Here's the script I use:
This script can now be used as such:
The text was updated successfully, but these errors were encountered: