Advertisement
Guest User

Untitled

a guest
Mar 11th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #Load the image
  2. image= caffe.io.load_image(TEST_IMAGE)
  3. plt.imshow(image)
  4. plt.show()
  5.  
  6. #Load the mean image
  7. mean_image = np.load(MEAN_IMAGE)
  8. mu = mean_image.mean(1).mean(1) # average over pixels to obtain the mean (BGR) pixel values
  9.  
  10. # create transformer for the input called 'data'
  11. transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
  12. transformer.set_transpose('data', (2,0,1)) # move image channels to outermost dimension
  13. transformer.set_mean('data', mu) # subtract the dataset-mean value in each channel
  14. transformer.set_raw_scale('data', 255) # rescale from [0, 1] to [0, 255]
  15. transformer.set_channel_swap('data', (2,1,0)) # swap channels from RGB to BGR
  16. # 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)
  17. net.blobs['data'].reshape(1, # batch size
  18. 3, # 3-channel (BGR) images
  19. 227, 227) # image size is 227x227
  20.  
  21. transformed_image = transformer.preprocess('data', image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement