load and image and predict tensorflow 1

load and image and predict tensorflow

from PIL import Image
img = Image.open("image_file_path").convert('L').resize((28, 28), Image.ANTIALIAS)
img = np.array(img)
model.predict(img[None,:,:])

Here is what the above code is Doing:
1. Open the image file and convert it to grayscale.
2. Resize the image to 28×28 pixels.
3. Convert the image to a numpy array.
4. Add a new dimension to the image array.
5. Make a prediction using the model.

Similar Posts