titu1994 / keras-efficientnets

Keras Implementation of EfficientNets
MIT License
187 stars 63 forks source link

Add CI and fail it #10

Closed vmarkovtsev closed 5 years ago

vmarkovtsev commented 5 years ago

Signed-off-by: Vadim Markovtsev vadim@sourced.tech

B1-B6 cannot be constructed. I guess that different hyperparameters should be used.

======================================================================
ERROR: test_b1 (tests.test_weights.ImagenetPretrainedWeightsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/tests/test_weights.py", line 30, in test_b1
    self._test_b("1", 240)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/tests/test_weights.py", line 22, in _test_b
    include_top=True, weights='imagenet')
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 680, in EfficientNetB1
    default_size=240)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 377, in EfficientNet
    batch_norm_momentum, batch_norm_epsilon, data_format)(x)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 204, in block
    x = layers.Add()([x, inputs])
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/engine/base_layer.py", line 431, in __call__
    self.build(unpack_singleton(input_shapes))
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/layers/merge.py", line 91, in build
    shape)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/layers/merge.py", line 61, in _compute_elemwise_op_output_shape
    str(shape1) + ' ' + str(shape2))
ValueError: Operands could not be broadcast together with shapes (120, 120, 24) (120, 120, 16)
======================================================================
ERROR: test_b2 (tests.test_weights.ImagenetPretrainedWeightsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/tests/test_weights.py", line 33, in test_b2
    self._test_b("2", 260)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/tests/test_weights.py", line 22, in _test_b
    include_top=True, weights='imagenet')
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 750, in EfficientNetB2
    default_size=260)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 377, in EfficientNet
    batch_norm_momentum, batch_norm_epsilon, data_format)(x)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 180, in block
    data_format)(x)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 120, in block
    out = layers.Multiply()([x, inputs])
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/engine/base_layer.py", line 431, in __call__
    self.build(unpack_singleton(input_shapes))
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/layers/merge.py", line 91, in build
    shape)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/layers/merge.py", line 61, in _compute_elemwise_op_output_shape
    str(shape1) + ' ' + str(shape2))
ValueError: Operands could not be broadcast together with shapes (1, 1, 16) (130, 130, 32)
======================================================================
ERROR: test_b3 (tests.test_weights.ImagenetPretrainedWeightsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/tests/test_weights.py", line 36, in test_b3
    self._test_b("3", 300)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/tests/test_weights.py", line 22, in _test_b
    include_top=True, weights='imagenet')
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 820, in EfficientNetB3
    default_size=300)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 377, in EfficientNet
    batch_norm_momentum, batch_norm_epsilon, data_format)(x)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 180, in block
    data_format)(x)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 120, in block
    out = layers.Multiply()([x, inputs])
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/engine/base_layer.py", line 431, in __call__
    self.build(unpack_singleton(input_shapes))
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/layers/merge.py", line 91, in build
    shape)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/layers/merge.py", line 61, in _compute_elemwise_op_output_shape
    str(shape1) + ' ' + str(shape2))
ValueError: Operands could not be broadcast together with shapes (1, 1, 24) (150, 150, 40)
======================================================================
ERROR: test_b4 (tests.test_weights.ImagenetPretrainedWeightsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/tests/test_weights.py", line 39, in test_b4
    self._test_b("4", 380)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/tests/test_weights.py", line 22, in _test_b
    include_top=True, weights='imagenet')
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 890, in EfficientNetB4
    default_size=380)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 377, in EfficientNet
    batch_norm_momentum, batch_norm_epsilon, data_format)(x)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 180, in block
    data_format)(x)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 120, in block
    out = layers.Multiply()([x, inputs])
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/engine/base_layer.py", line 431, in __call__
    self.build(unpack_singleton(input_shapes))
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/layers/merge.py", line 91, in build
    shape)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/layers/merge.py", line 61, in _compute_elemwise_op_output_shape
    str(shape1) + ' ' + str(shape2))
ValueError: Operands could not be broadcast together with shapes (1, 1, 32) (190, 190, 48)
======================================================================
ERROR: test_b5 (tests.test_weights.ImagenetPretrainedWeightsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/tests/test_weights.py", line 42, in test_b5
    self._test_b("5", 456)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/tests/test_weights.py", line 22, in _test_b
    include_top=True, weights='imagenet')
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 960, in EfficientNetB5
    default_size=456)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 377, in EfficientNet
    batch_norm_momentum, batch_norm_epsilon, data_format)(x)
  File "/home/travis/build/vmarkovtsev/keras-efficientnets/keras_efficientnets/efficientnet.py", line 204, in block
    x = layers.Add()([x, inputs])
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/engine/base_layer.py", line 431, in __call__
    self.build(unpack_singleton(input_shapes))
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/layers/merge.py", line 91, in build
    shape)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/keras/layers/merge.py", line 61, in _compute_elemwise_op_output_shape
    str(shape1) + ' ' + str(shape2))
ValueError: Operands could not be broadcast together with shapes (228, 228, 40) (228, 228, 48)
titu1994 commented 5 years ago

Just a personal preference but please switch to pytest instead of unittest.

Asto why they fail to build, I have no clue. They surely build under normal conditions.

vmarkovtsev commented 5 years ago

@titu1994 can you provide a working snippet for, say, loading and running B1? As you see in the code, there is nothing extraordinary inside.

titu1994 commented 5 years ago

The error faced by this code was due to earlier versions overriding the shared DEFAULT_BLOCKS_LIST, so now it instead generates a new list for each model and then builds it, thereby removing the issue.

As to the tests, thank you for your contribution. B0-B5 are now being tested (with slight modifications) from your codebase.

Edit: To elaborate, it was possible to build a single model without issue. The subsequent models would however not be built correctly. This is now fixed via e2b1654a677b3a629c0c2df3ee895a45116fe817

vmarkovtsev commented 5 years ago

@titu1994 Please note that rewriting external contributions discourages people from contributing again. Open source relations 101. Thanks for fixing!

titu1994 commented 5 years ago

You're right that it discourages contributions, but there were significant alterations required compared to your code, and given my somewhat hectic weekend schedule, I acted hastily.

Some points would be that -

Still, you are indeed correct that I should have waited for your corrections.