Bilal Ch
Bilal Ch

Reputation: 378

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
    }
}

Upvotes: 6

Views: 3808

Answers (1)

Marcin Możejko
Marcin Możejko

Reputation: 40506

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.

Upvotes: 8

Related Questions