Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Load the image
- image= caffe.io.load_image(TEST_IMAGE)
- plt.imshow(image)
- plt.show()
- #Load the mean image
- mean_image = np.load(MEAN_IMAGE)
- mu = mean_image.mean(1).mean(1) # average over pixels to obtain the mean (BGR) pixel values
- # create transformer for the input called 'data'
- transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
- transformer.set_transpose('data', (2,0,1)) # move image channels to outermost dimension
- transformer.set_mean('data', mu) # subtract the dataset-mean value in each channel
- transformer.set_raw_scale('data', 255) # rescale from [0, 1] to [0, 255]
- transformer.set_channel_swap('data', (2,1,0)) # swap channels from RGB to BGR
- # set the size of the input (we can skip this if we're happy with the default; we can also change it later, e.g., for different batch sizes)
- net.blobs['data'].reshape(1, # batch size
- 3, # 3-channel (BGR) images
- 227, 227) # image size is 227x227
- transformed_image = transformer.preprocess('data', image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement