caffemodel2pytorch使用记录

前言

caffemodel2pytorch是用于对caffe模型转PyTorch模型的工具。对于需要对模型进行框架间的迁移帮助很大。

在这里插入图片描述

caffemodel2pytorch安装和测试

安装所需依赖环境

安装protobuf,注意使用root安装,或使用sudo权限安装。

wget https://github.com/google/protobuf/archive/v2.6.1.zip
unzip protobuf-2.6.1.zip
cd protobuf-2.6.1

如果网络能ping通google,则直接运行./autogen.sh 生成configure文件。如果不能则需要修改脚本对应部分的三行内容:

# Check that gtest is present.  Usually it is already there since the
# directory is set up as an SVN external.
if test ! -e gtest; then
  #echo "Google Test not present.  Fetching gtest-1.5.0 from the web..."
  #curl http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 | tar jx
  #mv gtest-1.5.0 gtest
  wget https://github.com/google/googletest/archive/release-1.5.0.tar.gz
  tar xzvf release-1.5.0.tar.gz
  mv googletest-release-1.5.0 gtest
fi

修改完后执行./autogen.sh 生成configure文件。

编译安装:

./configure
make -j8
make check
make install

注:

  1. 可能需要sudo ldconfig,否则可能会报错:
protoc: error while loading shared libraries: libprotoc.so.9: cannot open shared object file: No such file or directory  
  1. 如果不安装protobuf,则caffemodel2pytorch工具使用时会报错:
FileNotFoundError: [Errno 2] No such file or directory: 'protoc': 'protoc'

下载caffemodel2pytorch并测试

git clone https://github.com/vadimkantorov/caffemodel2pytorch.git
cd caffemodel2pytorch

使用caffemodel文件pose_iter_584000.caffemodel作为输入:
在这里插入图片描述
转换:

python -m caffemodel2pytorch pose_iter_584000.caffemodel

得到PyTorch模型文件pose_iter_584000.caffemodel.pt
在这里插入图片描述
注:如果github连接失败,则手动下载caffe.proto放在caffemodel2pytorch目录下:

wget https://raw.githubusercontent.com/BVLC/caffe/master/src/caffe/proto/caffe.proto

并修改对应使用文件路径:

local_caffe_proto = 'caffe.proto'  #os.path.join(codegen_dir, os.path.basename(caffe_proto))

版权说明

本文为原创文章,独家发布在blog.csdn.net/TracelessLe。未经个人允许不得转载。如需帮助请email至tracelessle@163.com或扫描个人介绍栏二维码咨询。
在这里插入图片描述

参考资料

[1] linux下安装google protobuf(详细)_jackytse_的博客-CSDN博客_linux protobuf
[2] FileNotFoundError: [Errno 2] No such file or directory: ‘protoc’: ‘protoc’ · Issue #17 · vadimkantorov/caffemodel2pytorch
[3] protobuf-2.6.1.zip-深度学习文档类资源-CSDN文库
[4] vadimkantorov/caffemodel2pytorch: Convert Caffe models to PyTorch

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TracelessLe

❀点个赞加个关注再走吧❀

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值