titu1994 / keras-efficientnets

Keras Implementation of EfficientNets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shape mismatch on model initialization

alekseisolovev opened this issue · comments

Error while initializing an EfficientNetB0 model:
ValueError: Operands could not be broadcast together with shapes (1, 1, 24) (112, 112, 32)
Same with EfficientNetB1:
ValueError: Operands could not be broadcast together with shapes (1, 1, 24) (120, 120, 32)
Finally EfficientNetB2:
ValueError: Operands could not be broadcast together with shapes (1, 1, 24) (130, 130, 32)

Is this occuring in the latest release ?

Just installed it, Ubuntu 16.04.

keras-base 2.2.4 py36_0
tensorflow 1.13.1 gpu_py36h3991807_0 anaconda
tensorflow-base 1.13.1 gpu_py36h8d69cac_0 anaconda
tensorflow-gpu 1.13.1 h0d30ee6_0 anaconda

Interesting. I am able to build all above models on v0.1.4 of this library.

The issue occured on v0.1.1 and v0.1.2 for some people but I patched that in v0.1.3

Hi,

This issue also appears for me. However, it only appears if I try to instanciate multiple EfficientNet models (either Both B3 variants or one B3 and one B0, same result).

The error I get comes from out = layers.Multiply()([x, inputs]), line 120 and the error message is Operands could not be broadcast together with shapes (1, 1, 32) (None, None, 40) . I also tried creating models in the python interpreter: The first creation goes fine, then the second gives me the above error. However, the next time I try creating a model, the shape difference error appears at line 204: x = layers.Add()([x, inputs]).

I'm using Keras 2.2.4 and EfficientNets v0.1.4

This bug was my mistake. Fixed via e2b1654

The root cause was that I was passing a single shared list of the DEFAULT_BLOCK_ARGS, but during model building, this arg list was being edited. Therefore the second model being built was receiving incorrect config.

Now I simply build a new list for each model call, and that resolves this issue.