Created
July 30, 2017 04:15
-
-
Save joelouismarino/aa565be7cc5a450b117fefee8d9440f0 to your computer and use it in GitHub Desktop.
This file contains 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
img = imread('cat.jpg', mode='RGB') | |
height,width = img.shape[:2] | |
img = img.astype('float32') | |
# subtract means | |
img[:, :, 0] -= 123.68 | |
img[:, :, 1] -= 116.779 | |
img[:, :, 2] -= 103.939 | |
img[:,:,[0,1,2]] = img[:, :, [2, 1, 0]] # swap channels | |
img = img.transpose((2, 0, 1)) # re-order dimensions | |
img = img[:,(height-224)//2:(height+224)//2, (width-224)//2:(width+224)//2] #crop | |
img = np.expand_dims(img, axis=0) # add dimension for batch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment