删除图层后保存caffe模型

2024-05-07 02:18:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个caffe模型,其中有crop层,因此将其转换为TensorFlow会带来问题。
我已成功加载模型并删除了crop层,现在我想保存相应的model.prototxtmodel.caffemodel
我在StackOverflow上发现了以下问题,但它们是关于替换层而不是永久删除层的:
Layer drop and update caffe model
How to modify the Imagenet Caffe Model?

当我使用caffe.Net.save()保存模型时,只保存model.caffemodel文件,而不保存相应的.prototxt。怎么办?
模型文件:https://github.com/Charrin/RetinaFace-Cpp/tree/master/convert_models/mnet
迄今为止使用的代码-

import caffe
net = caffe.Net('mnet.prototxt', 'mnet.caffemodel' , caffe.TEST)
del net.layer_dict['crop1']
del net.layer_dict['crop0']
net.save('new_model.caffemodel')

Tags: 文件模型croplayernetmodelsavetensorflow