caffe 能不能把 transformer 进行“持久化”存储下来?以免每次加载都很耗时

2017-04-27 16:47:43 +08:00
 Reign
caffe 中示例的如下代码:
import numpy as np
import sys,os
caffe_root = '/opt/caffe/'
sys.path.insert(0, caffe_root + 'python')
import caffe
os.chdir(caffe_root)
net_file=caffe_root + 'deploy.prototxt'
caffe_model=caffe_root + 'test.caffemodel'
mean_file=caffe_root + 'mean.npy'
net = caffe.Net(net_file,caffe_model,caffe.TEST)
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
transformer.set_transpose('data', (2,0,1))
transformer.set_mean('data', np.load(mean_file).mean(1).mean(1))
transformer.set_raw_scale('data', 255)
transformer.set_channel_swap('data', (2,1,0))
#把 transformer 持久化存储下来
im=caffe.io.load_image(caffe_root+'/sample/1.jpg')
net.blobs['data'].data[...] = transformer.preprocess('data',im)
out = net.forward()
print out
服务器没 GPU,每次加载一个 transformer 非常耗时,我就在想只加载一次,能不能持久化把这个 transformer 存储下来,以后每次测试图片直接调用就行了?
另外,如果使用别人已经建立好了的 caffemodel 来测试,是不是有了 GPU 会更快些?
机器学习新手问题估计比较幼稚,还是先谢谢了
5159 次点击
所在节点    Caffe
1 条回复
thomaspaine
2017-04-28 10:35:18 +08:00
python 自己的序列化反序列化不行吗?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/357747

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX