Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slice/split a layer in keras as in caffe

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
    }
}
like image 832
Bilal Ch Avatar asked Mar 27 '17 02:03

Bilal Ch


1 Answers

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.

like image 151
Marcin Możejko Avatar answered Nov 07 '22 16:11

Marcin Możejko