本文主要是介绍内涵:caffe踩过的一些坑,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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 256x256img = 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 batchnet.blobs['data'].data[i,:,:,:] = transformed_image # after reading all images into batch, forward once:
net.forward()
这篇关于内涵:caffe踩过的一些坑的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!