Skip to content

Instantly share code, notes, and snippets.

@donflopez
Created May 24, 2017 20:19
Show Gist options
  • Save donflopez/6822cad81cbb64a4d5b44c501e014897 to your computer and use it in GitHub Desktop.
Save donflopez/6822cad81cbb64a4d5b44c501e014897 to your computer and use it in GitHub Desktop.
# convert the input file to RGB
img = Image.open(fil).convert(‘RGB’)
# get an array of pixeles as [(255, 255, 255),...]
data = img.getdata()
# create a numpy array
narr = numpy.array(data)
# flatten the array [255, 255, 255,...]
narr = narr.flatten()
# normalize the rgb channels now [0. - 1.]
narr = [ (255-j)*1.0/255.0 for j in narr ]
# predict the result over the numpy array with the image information
res = self.prediction.eval(feed_dict={self.x: [narr],
self.keep_prob: 0.5}, session=self.sess)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment