caffemodel转tensorflow模型

本文介绍如何使用开源工具将Caffe模型转换为TensorFlow模型,并针对转换过程中可能遇到的错误提供了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开源项目:将caffe的模型(prototxt和caffemodel)转换为tensorflow(py和npy)
https://github.com/ethereon/caffe-tensorflow

解压caffe-tensorflow到某个目录,并进入。
转换指令:

python convert.py googlenet.prototxt --caffemodel googlenet.caffemodel --code-output-path=googlenet.py --data-output-path=googlenet.npy

转换完成显示如下
这里写图片描述

遇见的问题:
1.TypeError: Descriptors should not be created directly, but only retrieved from their parent.
尝试的解决办法:
将kaffe/caffe/caffepb.py改名为caffe_pb2.py
将kaffe/caffe/resolver.py中的17 18行内容

 from . import caffepb
 self.caffepb = caffepb

改为

 from . import caffe_pb2
 self.caffepb = caffe_pb2

2.Error encountered: Unknown layer type encountered
由于caffe版本不同,解决方法:使用安装的caffe版本更新prototxt和caffemodel

更新prototxt:

/root/caffe/build/tools/upgrade_net_proto_text old.prototxt new.prototxt

更新caffemodel:

/root/caffe/build/tools/upgrade_net_proto_binary old.caffemodel new.caffemodel

3.Error encountered: Multiple top nodes are not supported
网络中的层不允许有两个输出top

解决方法:更改层中两个输出为一个输出

4.Error encountered: Cannot determine dimensions of data layer.
See comments in function shape_data for more info
数据层输入格式必须为(dim:batchsize dim:channels dim:weight dim:heigh)

layer {
  name: "data"
  type: "Input"
  top: "data"
  input_param { shape: { dim: 64 dim: 1 dim: 28 dim: 28 } }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值