ND Blob 支持 caffe:对于大于 4 轴的 blob,旧式访问器失败

ND Blob support caffe: legacy accessors fail for blobs > 4 axes

我在执行以下 .prototxt 时遇到错误,我完全不知道为什么会出现错误:

layer {
    name: "conv"
    type: "Convolution"
    bottom: "image"
    top: "conv"
    convolution_param {
        num_output: 2
        kernel_size: 5
        pad: 2
        stride: 1
        weight_filler {
            type: "xavier"
        }
        bias_filler {
            type: "constant"
            value: 0
        }
    }
}

这是错误输出。正如我在最新的 caffe-master-branch 中看到的那样,应该可以使用 5D-Blobs.

I1202 14:54:58.617269  2393 hdf5_data_layer.cpp:93] Number of HDF5 files: 9
I1202 14:54:58.631134  2393 hdf5.cpp:35] Datatype class: H5T_INTEGER
I1202 14:54:59.159739  2393 net.cpp:150] Setting up train-data
I1202 14:54:59.159760  2393 net.cpp:157] Top shape: 1 1 1 128 128 (16384)
I1202 14:54:59.159765  2393 net.cpp:157] Top shape: 1 1 8 128 128 (131072)
I1202 14:54:59.159766  2393 net.cpp:165] Memory required for data: 589824
I1202 14:54:59.159773  2393 layer_factory.hpp:77] Creating layer down_level_0_conv
I1202 14:54:59.159790  2393 net.cpp:100] Creating Layer down_level_0_conv
I1202 14:54:59.159795  2393 net.cpp:434] down_level_0_conv <- image
I1202 14:54:59.159804  2393 net.cpp:408] down_level_0_conv -> down_level_0_conv
F1202 14:54:59.159915  2393 blob.hpp:140] Check failed: num_axes() <= 4 (5 vs. 4) Cannot use legacy accessors on Blobs with > 4 axes.

我需要去某个分行吗?我刚刚再次从 caffe-master-branch 中拉出以确保它是最新版本。然后我做了一个 make clean make all 命令,它仍然不起作用。

当我删除 line 140 blob.hpp 中的检查时,它确实有效。这是解决问题的一种方法,但不是最好的方法。

(但这不是正确的解决方案。还有其他方法吗?)

AFAIK,此错误来自 "Xavier" 填充器:此填充器计算输入和输出通道之间的比率。如果你用不同的填充物替换它,你应该可以使用 ND blob。

作为, in order to be compatible with the ND Convolution and InnerProduct layer, the "Xavier" filler code

的补充
virtual void Fill(Blob<Dtype>* blob) {
...
int fan_in = blob->count() / blob->num();
int fan_out = blob->count() / blob->channels();
Dtype n = fan_in;  // default to fan_in
...
Dtype scale = sqrt(Dtype(3) / n);
caffe_rng_uniform<Dtype>(blob->count(), -scale, scale,
        blob->mutable_cpu_data());
CHECK_EQ(this->filler_param_.sparse(), -1)
         << "Sparsity not supported by this Filler.";
}

在caffe中,应该更像这样:

...
int fan_in = blob->count() / blob->shape(0);
int fan_out = blob->num_axis() == 2 ? blob->shape(0) : blob->count() / blob->shape(1);
...//original stuff 

这个小改动应该也能让你的 prototxt 工作。