caffe - net surgery pycaffe 复制权重和 reshape

标签 caffe pycaffe

我正在尝试将预训练模型的大小为 3x3x3 的层“con_1”的学习权重复制到新层“con_1_1”,以便新层的大小为 6x3x3(6 个 channel )。我实际上是在尝试将大小为 3x3x3 的权重复制到 6x3x3。我怎样才能使用 pycaffe 做到这一点。

      layer name: 'con_1'
      size: 3x3x3

      new layer name: 'con_1_1'
      size: 6x3x3

      con_1_1 should be [con_1, con_1] % just concatenation of two con_1 weights

最佳答案

您必须使用 .prototxt 文件和 .caffemodel 文件读取网络。然后将原始网络中的权重复制到一个变量中,然后将它们复制到编辑后的网络中。

net = caffe.Net('path/to/conv.prototxt', 'path/to/conv.caffemodel', caffe.TEST)
W = net.params['con_1'][0].data[...]
b = net.params['con_1'][1].data[...]

net = caffe.Net('path/to/conv2.prototxt', 'path/to/conv2.caffemodel', caffe.TEST)
W_1 = numpy.concatenate(W, W, axis=2)
b_1 = numpy.concatenate(b, b, axis=0)
net.params['con_1_1'][0].data[...] = W_1
net.params['con_1_1'][1].data[...] = b_1

看看这个link还有这个link获取更多信息。

关于caffe - net surgery pycaffe 复制权重和 reshape ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38873549/

相关文章:

caffe - 将同一网络的某些节点放在 GPU 上,将其他节点放在 CPU 上?

ubuntu - Caffe 编译错误 - 虚拟框中的 Ubuntu 18.04.4 Live Server

python - caffe 可以同时接收一批不同分辨率的输入吗?如果是这样怎么办?

machine-learning - 连体网络输出

c++ - 未调用 Caffe Layer 函数

python - pyplot 轴标题不显示

tensorflow - 适用于 TensorFlow 的更快 RCNN

python - 当我在没有 MKL 的情况下安装 pycaffe 时出现导入错误

machine-learning - 推理时间取决于参数数量吗?

python - 使用 python 编译 caffe 的问题,对 `std::__cxx11::....' 的 undefined reference