ssd_keras icon indicating copy to clipboard operation
ssd_keras copied to clipboard

Symbolic tensor expected as input to flatten

Open sidgan opened this issue 7 years ago • 2 comments

I'm new to Keras so all help is appreciated. This is Keras 2.0 and python 3.0 with Tensorflow backend. Tensorflow has been installed and works well with python3. I've converted the names from Keras 1.0 to Keras 2.0 according to the documentation. The ssd.py file that I am using is on gist here.

The error comes from this line 195 in file ssd.py

net['conv4_3_norm_mbox_loc_flat'] = flatten(inputs=net['conv4_3_norm_mbox_loc'])

which is supposed to expect a symbolic tensor but gets a conv2D type input.

Error:

ValueError                                Traceback (most recent call last)
~/.local/lib/python3.5/site-packages/keras/engine/topology.py in assert_input_compatibility(self, inputs)
    418             try:
--> 419                 K.is_keras_tensor(x)
    420             except ValueError:

~/.local/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py in is_keras_tensor(x)
    392                           tf.SparseTensor)):
--> 393         raise ValueError('Unexpectedly found an instance of type `' + str(type(x)) + '`. '
    394                          'Expected a symbolic tensor instance.')

ValueError: Unexpectedly found an instance of type `<class 'keras.layers.convolutional.Conv2D'>`. Expected a symbolic tensor instance.

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-24-b8c5c018f8c1> in <module>()
      2 #print(input_shape, 'from ipython')
      3 #print(NUM_CLASSES, 'from ipython')
----> 4 model = SSD300(input_shape, num_classes=NUM_CLASSES)
      5 
      6 #model.load_weights('ssd_keras/weights_SSD300.hdf5', by_name=True)

/newmodel/bendyna-nexar/ssd_keras/ssd.py in SSD300(input_shape, num_classes)
    193     line 370
    194     '''
--> 195     net['conv4_3_norm_mbox_loc_flat'] = flatten(inputs=net['conv4_3_norm_mbox_loc'])
    196 
    197 

~/.local/lib/python3.5/site-packages/keras/engine/topology.py in __call__(self, inputs, **kwargs)
    550                 # Raise exceptions in case the input is not compatible
    551                 # with the input_spec specified in the layer constructor.
--> 552                 self.assert_input_compatibility(inputs)
    553 
    554                 # Collect input shapes to build layer.

~/.local/lib/python3.5/site-packages/keras/engine/topology.py in assert_input_compatibility(self, inputs)
    423                                  'Received type: ' +
    424                                  str(type(x)) + '. Full input: ' +
--> 425                                  str(inputs) + '. All inputs to the layer '
    426                                  'should be tensors.')
    427 

ValueError: Layer conv4_3_norm_mbox_loc_flat was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.convolutional.Conv2D'>. Full input: [<keras.layers.convolutional.Conv2D object at 0x7f85839dab38>]. All inputs to the layer should be tensors.

Any ideas for how to fix this?

I've changed the function definition as was mentioned in the previous errors (#60 , #72 , and #84 )

def compute_output_shape(self, input_shape):
        num_priors_ = len(self.aspect_ratios)
        layer_width = input_shape[self.waxis]
        layer_height = input_shape[self.haxis]
        num_boxes = num_priors_ * layer_width * layer_height
        return input_shape[0], num_boxes, 8

sidgan avatar Aug 23 '17 23:08 sidgan

Read the error. It says you pass to the inputs not the tensor, but the layer object itself. Try to delete inputs=

Stanpol avatar Aug 24 '17 06:08 Stanpol

If I remove inputs= and the line becomes net['conv4_3_norm_mbox_loc_flat'] = flatten(net['conv4_3_norm_mbox_loc']). I still get the same error:

ValueError: Layer conv4_3_norm_mbox_loc_flat was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.convolutional.Conv2D'>. Full input: [<keras.layers.convolutional.Conv2D object at 0x7f28a7717a58>]. All inputs to the layer should be tensors.

From what I understand, the error says the data type of the input should be a symbolic tensor and not a conv2d type. So, I need to get the symbolic tensor from net['conv4_3_norm_mbox_loc'] and send it as the input to flatten. Is this not correct? Could you please elaborate on what your thinking is.

Thank you very much for your help!

sidgan avatar Aug 24 '17 18:08 sidgan