Skip to content
Advertisement

Tensorflow: Incompatible shapes: [1,2] vs. [1,4,4,2048]

I have the following tensorflow model:

JavaScript

I have simplified this somewhat in an attempt to narrow down the problem,

When I run this I get the following error:

JavaScript

This error always seems to occur on a different input image. All my images are exactly the same dimennsions.

I am using tensorflow 2.4.1

What am I missing?

Advertisement

Answer

The ResNet50 model outputs a tensor with the shape (4,4,2048) and you are expecting a shape of (2,), so you will definitely have to reduce the size of that tensor by applying further dense layers. Here is a simple working example but but I would recommend using a deep network with more layers.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement