neural network - Passing Individual Channels of Tensors to Layers in Keras -


i trying emulate equivalent separableconvolution2d layer theano backend (it exists tensorflow backend). first step need pass 1 channel tensor next layer. have 2d convolution layer called conv1 16 filters produces output shape: (batch_size, 16, height, width) need select subtensor shape (: , 0, : , : ) , pass next layer. simple enough right?

this code:

from keras import backend k  image_input = input(batch_shape = (batch_size, 1, height, width ), name = 'image_input' )  conv1 = convolution2d(16, 3, 3, name='conv1', activation = 'relu')(image_input)  conv2_input = k.reshape(conv1[:,0,:,:] , (batch_size, 1, height, width))  conv2 = convolution2d(16, 3, 3, name='conv1', activation = 'relu')(conv2_input) 

this throws:

exception: tried call layer "conv1". layer has no information expected input shape, , cannot built. can build manually via: layer.build(batch_input_shape)

why layer not have required shape information? i'm using reshape theano backend. right way of passing individual channels next layer?

i asked question on keras-user group , got answer there:

https://groups.google.com/forum/#!topic/keras-users/bbq5cbvxt1e

quoting it:

you need use lambda layer, like: lambda(x: x[:, 0:1, :, :], output_shape=lambda x: (x[0], 1, x[2], x[3]))

note such manual implementation of separable convolution horribly inefficient. correct solution use tensorflow backend.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -