Skip to content

Instantly share code, notes, and snippets.

@pranjal-joshi
Last active April 24, 2017 10:11
Show Gist options
  • Save pranjal-joshi/e8098cde45bf655c5a856578bb7ccf05 to your computer and use it in GitHub Desktop.
Save pranjal-joshi/e8098cde45bf655c5a856578bb7ccf05 to your computer and use it in GitHub Desktop.
def preprocess_img(path):
print "preprocess: " + path
i = load_img(path,target_size=(img_nrows,img_ncols))
i = img_to_array(i)
i = np.expand_dims(i,axis=0)
i = vgg16.preprocess_input(i)
return i
def deprocess_img(i):
i = i.reshape((3,img_nrows,img_ncols))
i = i.transpose((1,2,0))
i[:,:,0] += 103.939
i[:,:,1] += 116.779
i[:,:,2] += 123.68
i = i[:,:,::-1]
i = np.clip(i,0,255).astype('uint8')
return i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment