slice/split a layer in keras as in caffe

妖精的绣舞 提交于 2020-01-13 02:13:15

问题


I have used this converter to convert a Caffe model to Keras. But one of my layers is of type slice and it needs to be converted as well but the converter currently does not support this and raises an exception. Is there any work around for it? Here is my layer:

layer {
    name: "slice_label"
    type: SLICE
    bottom: "label"
    top: "label_wpqr"
    top: "label_xyz"
    slice_param {
        slice_dim: 1
        slice_point: 4
    }
}

回答1:


It seems that you want to use a Lambda layer. In this case you may do the following:

sliced = Lambda(lambda x: x[:,slicing_indeces], output_shape=(sliced_shape))(input)

Note that in x you need to take into account the samples axis whereas in output_shape it's not needed anymore.



来源:https://stackoverflow.com/questions/43037258/slice-split-a-layer-in-keras-as-in-caffe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!