Error in Model compling and defining

While defining and compling the model i am receiving the following error:


Is the code correct:
def bounding_box_regression(x):
### YOUR CODE HERE ###

# Dense layer named `bounding_box`
### END CODE HERE ###
    return bounding_box_regression_output

def final_model(inputs):
### YOUR CODE HERE ###

### END CODE HERE ###


return model

def define_and_compile_model():

### YOUR CODE HERE ###
### END CODE HERE ###


return model

@Fareed_Ahmad, I removed your code since it is against community guidelines to share your code here.

I didn’t notice anything that stood out in the code you shared that would cause the error you’re seeing, though. To debug, expand the 4 frames to see which line in define_and_compile_model() is causing the error. The error you’re getting is that the inputs to the layer aren’t right, so narrow down on the line that is causing the problem to see what could be causing that error.

2 Likes

Dear Wendy thanks for your response. Plz see the frames

Yeah you have a problem with the bounding_box_regression_ouput layer. This output is supposed to give you numerical range coordinates and I leave it to you to find where the simple mistake is!

1 Like

Sir
I tried my best but couldn’t locate the error in the regression layer can you plz help
Regards
Fareed

Dont use an activation.

Sir
Thank for your guidance I removed the activation but the error persists.
Plz see the attachment
Regards
Fareed

def bounding_box_regression(x):

YOUR CODE HERE

Dense layer named bounding_box

bounding_box_regression_output = tf.keras.layers.Dense(4, name=‘bounding_box’)(x)

END CODE HERE

image.png

return bounding_box_regression_output
TypeError Traceback (most recent call last)

in
1 # define your model
----> 2 model = define_and_compile_model()
3 # print model layers
4 model.summary()

4 frames

in define_and_compile_model()
8
9 # create the model
—> 10 model = final_model(inputs)
11
12 # compile your model

in final_model(inputs)
9
10 # bounding box
—> 11 bounding_box_output = bounding_box_regression(last_dense_layer)
12
13 # define the TensorFlow Keras model using the inputs and outputs to your model

in bounding_box_regression(x)
3
4 # Dense layer named bounding_box
----> 5 bounding_box_regression_output = tf.keras.layers.Dense(4, name=‘bounding_box’)(x)
6 ### END CODE HERE ###
7

/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.traceback)
—> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb

/usr/local/lib/python3.8/dist-packages/keras/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
195 # have a shape attribute.
196 if not hasattr(x, ‘shape’):
→ 197 raise TypeError(f’Inputs to a layer should be tensors. Got: {x}')
198
199 if len(inputs) != len(input_spec):

TypeError: Inputs to a layer should be tensors. Got: <keras.layers.core.dense.Dense object at 0x7fb215e8a730>

@Fareed_Ahmad,
The error says that the input to a layer should be tensors, and the line you are getting the error on is:

bounding_box_regression_output = tf.keras.layers.Dense(4, name=‘bounding_box’)(x)

so I would try printing out what x is and if it is the wrong type, then go back to figure out how to make it right

1 Like