V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Reign
V2EX  ›  Caffe

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

  •  
  •   Reign · 2017-04-27 16:47:43 +08:00 · 5124 次点击
    这是一个创建于 2527 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 会更快些?
    机器学习新手问题估计比较幼稚,还是先谢谢了
    1 条回复    2017-04-28 10:35:18 +08:00
    thomaspaine
        1
    thomaspaine  
       2017-04-28 10:35:18 +08:00
    python 自己的序列化反序列化不行吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5301 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 07:16 · PVG 15:16 · LAX 00:16 · JFK 03:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.