1、caffe.io.load_image()与cv2.imread()的区别与联系
from __future__ import division
a=caffe.io.load_image("1.jpg")
b=cv2.imread("1.jpg")
则a=b/255
2、
transformed_image = self.transformer.preprocess('data', image)
self.net.blobs['data'].data[...] = transformed_image
用datetime.datetime.now()测了一下caffe中这两句话的耗时,我的天,20几个毫秒,抵得上前向耗费的时间了。
3、之前一直都是一次前向,一副图片,今天看到了一次前向,一个batch的图片的代码,记录下
bs = len(fnames) # batch size
in_shape = net.blobs['data'].data.shape
in_shape[0] = bs # set new batch size
net.blobs['data'].reshape(*in_shape)
net.reshape()
for i, f in enumerate(fnames):
img = Image.open(f)
# scale all images to 256x256
img = img.resize((256,256), PIL.Image.ANTIALIAS)
img = numpy.array(img).astype(numpy.float32)
transformed_image = transformer.preprocess('data', img)
#print transformed_image.shape
# put the image into i-th place in batch
net.blobs['data'].data[i,:,:,:] = transformed_image
# after reading all images into batch, forward once:
net.forward()