conv neural network - Keras PReLU layer not working with variable input size -
i want implement sample pnet model this paper. purpose using functional api instead of sequential model, since @ end need concatenate 2 outputs.
this code:
from keras import backend k keras.models import sequential, model, input keras.layers import conv2d, maxpooling2d, dense, activation keras.layers.advanced_activations import prelu k.set_image_dim_ordering('tf') def get_p_net(): main_input = input(shape=(none, none, 3), dtype='float32', name='main_input') x = conv2d(10, (3, 3), strides=(1, 1), padding='valid', name='conv1')(main_input) x = prelu(name='prelu1', alpha_constraint=none)(x) x = maxpooling2d(pool_size=(2, 2), strides=(2,2), padding='same', name='pool1')(x) x = conv2d(16, (3, 3), strides=(1,1), padding='valid', name='conv2')(x) x = prelu(name='prelu2')(x) x = conv2d(32, (3, 3), strides=(1,1), padding='valid', name='conv3')(x) x = prelu(name='prelu3')(x) binary_face_output = conv2d(2, (1, 1), strides=(1,1), padding='same', name='conv4-1')(x) binary_face_output = dense(2, activation='softmax', name='prob1')(binary_face_output) bbox_output = conv2d(4, (1, 1), strides=(1,1), padding='same', name='conv4-2')(x) model = model(inputs=[main_input], outputs=[binary_face_output, bbox_output]) model.summary() # model.compile(optimizer='rmsprop', loss='binary_crossentropy', # loss_weights=[1., 1.]) get_p_net()
this exception:
file "p_net.py", line 23, in <module> get_p_net() file "p_net.py", line 9, in get_p_net x = prelu(name='prelu1', alpha_constraint=none)(x) file "d:\anaconda2\envs\tensorflow\lib\site-packages\keras\engine\topology.py", line 569, in __call__ self.build(input_shapes[0]) file "d:\anaconda2\envs\tensorflow\lib\site-packages\keras\layers\advanced_activations.py", line 111, in build constraint=self.alpha_constraint) file "d:\anaconda2\envs\tensorflow\lib\site-packages\keras\legacy\interfaces.py", line 87, in wrapper return func(*args, **kwargs) file "d:\anaconda2\envs\tensorflow\lib\site-packages\keras\engine\topology.py", line 391, in add_weight weight = k.variable(initializer(shape), dtype=dtype, name=name) file "d:\anaconda2\envs\tensorflow\lib\site-packages\keras\initializers.py", line 29, in __call__ return k.constant(0, shape=shape, dtype=dtype) file "d:\anaconda2\envs\tensorflow\lib\site-packages\keras\backend\tensorflow_backend.py", line 358, in constant return tf.constant(value, dtype=dtype, shape=shape, name=name) file "d:\anaconda2\envs\tensorflow\lib\site-packages\tensorflow\python\framework\constant_op.py", line 102, in constant tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape)) file "d:\anaconda2\envs\tensorflow\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 371, in make_tensor_proto if np.prod(shape) == 0: file "d:\anaconda2\envs\tensorflow\lib\site-packages\numpy\core\fromnumeric.py", line 2518, in prod out=out, **kwargs) file "d:\anaconda2\envs\tensorflow\lib\site-packages\numpy\core\_methods.py", line 35, in _prod return umr_prod(a, axis, dtype, out, keepdims) typeerror: unsupported operand type(s) *: 'nonetype' , 'nonetype'
it clear somehow not input shape of layer (output of last convolutional layer). so, changing first line to:
main_input = input(shape=(12, 12, 3), dtype='float32', name='main_input')
fixed problem , model summary. want ask if there way of processing variable size inputs through network contains prelu
layers.
Comments
Post a Comment