Last active
April 24, 2017 10:11
-
-
Save pranjal-joshi/e8098cde45bf655c5a856578bb7ccf05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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