torch7 调用caffe model 作为pretrain
torch7 调用caffe model 作为pretrain
torch7 通过 loadcaffe 包,可以调用caffe训练得到的model 参数作为自己网络的初始参数。
loadcaffe 的安装需要caffe的依赖项,所以首先执行如下指令
sudo apt-get install libprotobuf-dev protobuf-compiler
然后在ubuntu上安装loadcaffe包
sudo luarocks install loadcaffe
参考 loadcaffe
接下来,为了使用caffe model,需要下载caffe model。 caffe model zoo中提供了许多caffemodel的下载。
如何下载 caffemodel? 首先将BVLC/caffe中的包下载并解压,我是解压到 Documents/caffe_master文件夹下的
压缩包里面提供了一些bvlc的models的基本信息,所以可以使用指令
./scripts/download_model_binary.py (model_dir) 下载 (model_dir) 对应的model,看下面代码
~$ cd Documents/caffe_master/caffe_master
~$ sudo ./scripts/download_model_binary.py models/bvlc_reference_caffenet
这时候我的机子提示没有安装python的yaml库,所以在文件头require'yaml'时出错,那么安装yaml库
~$ sudo apt-get install python-yaml
再次执行上面的代码就没问题了,然后在 Documents/caffe_master/caffe_master/models/bvlc_reference_caffenet文件夹下出现的 .caffemodel文件
如下图

依次可以下载bvlc相关的model。
而对于不是bvlc下的model,比如VGG_CNN网络则可以使用 ./scripts/download_model_from_gist.sh (gist_id) (dirname) 指令下载对应caffemodel的元数据、结构以及配置信息等, (gist_id)是对应的gist上的ID号,可以在model zoo查看,(dirname)默认是models文件夹,所以没必要给出。比如在model zoo网站上我们可以查到VGG_CNN_M
的 gist_id是f194575702fae63b2829,那么可以如下代码
~$ cd Documents/caffe_master/caffe_master
~$ sudo ./scripts/download_model_from_gist.sh f194575702fae63b2829
但是这里优惠碰到一个问题,gist被墙了,链接不了,参考GitHub Gist 被墙
~$ sudo gedit /etc/hosts
添加
192.30.253.118 http://gist.github.com
192.30.253.119 http://gist.github.com
然后再执行上面的指令就好了
按照官方的文档
) To acquire a model:
) 1. download the model gist by ./scripts/download_model_from_gist.sh (gist_id) (dirname)to load the model metadata, architecture, solver configuration, and so on. (dirname) is optional and defaults to caffe/models).
) 2. download the model weights by ./scripts/download_model_binary.py (model_dir) where (model_dir) is the gist directory from the first step.
接下来使用./scripts/download_model_binary.py f194575702fae63b2829 指令就可以下载VGG_CNN_M的model了,但是我执行该指令之后出现如下错误:

注:这里我改成文件名 VGG_CNN_M了
查看download_model_binary.py文件可以发现,readme.md文件需要有三个键值:
required_keys = ['caffemodel', 'caffemodel_url', 'sha1']
自带的bvlc下model的readme文件如下:

而我们下载的VGG_CNN_M的readme文件缺少了sha1校验码,所以总是出错

但同时我们可以发现readme文件中有一项: caffemodel_url
所以我们可以自己下载caffemodel
直接打开 VGG_CNN_M的readme文件中的 caffemodel_url指示的链接 http://www.robots.ox.ac.uk/~vgg/software/deep_eval/releases/bvlc/VGG_CNN_M.caffemodel 便可以下载到对应的caffemodel了,将对应的deploy.prototxt和 .caffemodel放在一起就可以使用 torch7中loadcaffe包调用了
~$ th
th) require 'loadcaffe'
th) proto='VGG_CNN_M_deploy.prototxt'
th) caffemodel = 'VGG_CNN_M.caffemodel'
th) net=loadcaffe.load(proto,caffemodel,'nn')
输出
Successfully loaded VGG_CNN_M.caffemodel
conv1: 96 3 7 7
conv2: 256 96 5 5
conv3: 512 256 3 3
conv4: 512 512 3 3
conv5: 512 512 3 3
fc6: 1 1 18432 4096
fc7: 1 1 4096 4096
fc8: 1 1 4096 1000
OK,至此表示我们已经可以使用torch加载caffemodel了,关于caffemodel如何使用,后面我们继续来看。
references:
gist:
https://www.zhihu.com/question/20732532
http://blog.csdn.net/chclvzxx/article/details/50098515
http://ruby-china.org/topics/22594
model zoo:
http://www.modelzoo.co/
http://caffe.berkeleyvision.org/model_zoo.html
https://github.com/BVLC/caffe/wiki/Model-Zoo
caffeload:
https://github.com/szagoruyko/loadcaffe
http://blog.csdn.net/DreamD1987/article/details/52397906
yaml:
http://blog.csdn.net/philip502/article/details/12838953
torch7 调用caffe model 作为pretrain的更多相关文章
- 如何在程序中调用Caffe做图像分类
Caffe是目前深度学习比较优秀好用的一个开源库,采样c++和CUDA实现,具有速度快,模型定义方便等优点.学习了几天过后,发现也有一个不方便的地方,就是在我的程序中调用Caffe做图像分类没有直接的 ...
- windows下用c++调用caffe做前向
参考博客: https://blog.csdn.net/muyouhang/article/details/54773265 https://blog.csdn.net/hhh0209/article ...
- 创建新的C++工程来调用Caffe对图片进行识别
前段时间一直在跑Caffe训练数据.之前用训练好的caffemodel对图片进行分类都是用的命令行指令,于是就想着自己新建一个工程来调用caffe,结合classification的代码来对图片进行分 ...
- 【神经网络与深度学习】Caffe Model Zoo许多训练好的caffemodel
Caffe Model Zoo 许多的研究者和工程师已经创建了Caffe模型,用于不同的任务,使用各种种类的框架和数据.这些模型被学习和应用到许多问题上,从简单的回归到大规模的视觉分类,到Siames ...
- python调用caffe实现预测
对于已经训练完成的caffemodel,对于单个的图片预测,用python接口来调用是一件非常方便的事情,下面就来讲述如何用python调用已经训练完成的caffemodel,以及prototxt,网 ...
- Windows下caffe的配置和调用caffe库(二)
二. Caffe库的调用: 新建空白项目,将配置管理器更改为x64运行方式.(release和Debug均可). Debug配置: 1) 包含目录: D:\caffe-master\incl ...
- python调用caffe环境配置
背景是这样的,项目需要,必须将训练的模型通过C++进行调用,所以必须使用caffe或者mxnet,而caffe是用C++实现,所以有时候简单的加载一张图片然后再进行预测十分不方便 用caffe写pro ...
- Thinkhphp5控制器调用的Model层的方法总结
控制器器里: <?php /** * Created by PhpStorm. * User: Haima * Date: 2018/7/8 * Time: 15:58 */ namespace ...
- Windows下caffe的配置和调用caffe库(一)
一.Windows下caffe的配置: 1. 下载caffe官网提供的开发包,https://github.com/microsoft/caffe 2. 将caffe-master目录下的Window ...
随机推荐
- Web 框架 Flask
Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收http请求并对请求进行预处理,然后 ...
- JS传参中文乱码问题.NET
前台js代码 window.location.href = "/product.aspx?id=2&title=" +encodeURIComponent(strtitle ...
- 卷积网络训练太慢?Yann LeCun:已解决CIFAR-10,目标 ImageNet
原文连接:http://blog.kaggle.com/2014/12/22/convolutional-nets-and-cifar-10-an-interview-with-yan-lecun/ ...
- centos7 离线安装docker-ce
测试的时候,在VM中安装了一个minimal安装的centos7.因为发现在已经安装好环境的系统中,执行下面,并不会下载依赖的rpm.#下载docker-ce和其需要的依赖rpm yum instal ...
- 转载:逻辑回归的python实现
转载自:http://blog.csdn.net/zouxy09/article/details/20319673 一.逻辑回归(LogisticRegression) Logistic regres ...
- zookeeper 监听事件 CuratorWatcher
zookeeper 监听事件 CuratorWatcher CuratorWatcher一次注册只监听一次,不监听查询. 1.监听测试类 package com.qy.learn.zk.curator ...
- Ubuntu 16.04 安装Postman
Ubuntu 16.04 安装Postman: 1.官网下载地址:https://www.getpostman.com/根据机器类型选择64位下载. 2.进入下载目录,解压该文件sudo tar -x ...
- 让boost.variant支持lambda表达式访问
前言 之前写个过一篇博客叫<浅谈boost.variant的几种访问方式>,里面讲到了可以通过访问者方式来获取variant的值,但是在重载函数operator()里面只能够获取varia ...
- Poi读取Excle报错 java.util.zip.ZipException: invalid stored block lengths
一:Poi读取Excle报错 java.util.zip.ZipException: invalid stored block lengths 系统中需要导出excle签收单,excle模板是预设好 ...
- JAVA面试题整理(3)-Spring
1.BeanFactory 和 FactoryBean? 2.Spring IOC 的理解,其初始化过程? 3.BeanFactory 和 ApplicationContext? 4.Spring B ...