caffemodel转tensorflow模型

开源项目:将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 } }
}
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
将TensorFlow模型换为Caffe2模型可以按照以下步骤进行: 1. 将TensorFlow模型导出为SavedModel格式:使用TensorFlow的`tf.saved_model.save`函数将TensorFlow模型保存为SavedModel格式。 ```python import tensorflow as tf # 加载TensorFlow模型 model = tf.keras.applications.ResNet50(weights='imagenet') # 保存为SavedModel格式 saved_model_path = './saved_model' tf.saved_model.save(model, saved_model_path) ``` 2. 使用Caffe2的tf2caffe工具进行换:Caffe2提供了一个tf2caffe工具,可以将SavedModel换为Caffe2模型。你需要克隆Caffe2的GitHub仓库,并根据官方文档的说明进行安装和配置。 ```bash git clone https://github.com/pytorch/pytorch.git cd pytorch git submodule update --init cd caffe2 mkdir build cd build cmake .. make ``` 3. 运行tf2caffe换脚本:在Caffe2的build目录下,使用tf2caffe换脚本将SavedModel换为Caffe2模型。 ```bash ./build/tools/tf2caffe \ --data-output-path caffe_model/data \ --code-output-path caffe_model/model \ --net-output-path caffe_model/model.prototxt \ --init-net-output-path caffe_model/init_net.pb \ --predict-net-output-path caffe_model/predict_net.pb \ --input-dim 1,224,224,3 \ --input-type float \ --input-name input \ --output-name output \ --input-blob-name input_blob \ --output-blob-name output_blob \ --caffe-weights caffe_model/caffe_weights.caffemodel \ --tensorflow-model-path saved_model ``` 通过以上步骤,你就可以将TensorFlow模型换为Caffe2模型换后的Caffe2模型将包含模型结构和参数,并可以在Caffe2中进行推理操作。请注意,换过程中可能需要处理一些兼容性问题,因为TensorFlow和Caffe2具有不同的特性和支持的操作集。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值