zaidalyafeai / ml-projects

Implementation of web friendly ML models using TensorFlow.js. pix2pix, face segmentation, fast style transfer and many more ...
MIT License
647 stars 254 forks source link

How to run predictions on saved images/drawings ? #19

Open shubhank008 opened 5 years ago

shubhank008 commented 5 years ago

Tried to make a prediction on a .jpg/.png saved image of random drawings (from quick draw data set, directly saved the image). However, the prediction came off quite wrong and can't seem to get it working and my guess is on due to the image processing before feeding to the model.

This is what I am using

from PIL import Image
import cv2
import matplotlib.pyplot as plt
from random import randint
%matplotlib inline  

clock = qd.get_drawing("clock")
apple = clock

img = apple.image.convert("L")
img = img.resize((28,28),Image.BILINEAR)
img = np.array(img)
img = cv2.bitwise_not(img)

img = img.reshape(28,28,1)
img = img.astype('float32')
img /= 255.0

print(img.shape)
plt.imshow(img.squeeze()) 
print(img)

Yellowish image is the original one in npy format, the other is processed using above code.

chrome_2019-06-06_10-01-14 chrome_2019-06-06_10-01-27
zaidalyafeai commented 5 years ago

@shubhank008, can you explain more ? which model are you using ? Are you using this notebook ?

shubhank008 commented 5 years ago

@shubhank008, can you explain more ? which model are you using ? Are you using this notebook ?

Yes, exactly that. Initially I tried to re-write how you were doing inference on drawings in web app (tensorflowjs) to python (using saved drawing images .jpg .png) but that did not work, then I started trying various image pre-processing alternatives as I am pretty sure its the whole image reading, processing and feeding part that I am messing up.

shubhank008 commented 5 years ago

@zaidalyafeai anything ?

zyqq commented 1 year ago

Did you find a solution?