titu1994 / Keras-NASNet

"NASNet" models in Keras 2.0+ with weights
MIT License
199 stars 64 forks source link

Got ValueError #11

Closed DableUTeeF closed 6 years ago

DableUTeeF commented 6 years ago

I run the code on readme.md

from nasnet import NASNet
model = NASNet(input_shape=(331, 331, 3),
           penultimate_filters=4032,
           nb_blocks=6,
           stem_filters=96,
           skip_reduction=True,
           use_auxilary_branch=False,
           filters_multiplier=2,
           dropout=0.5,
           classes=1000)

And I got.

Traceback (most recent call last): File "<input>", line 12, in <module> File "/home/palm/PycharmProjects/lstm_test/nasnet.py", line 221, in NASNet x, p = _normal_A(x, p, filters, weight_decay, id='%d' % (i)) File "/home/palm/PycharmProjects/lstm_test/nasnet.py", line 665, in _normal_A x3 = add([x3, p], name='normal_add_3_%s' % id) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/layers/merge.py", line 455, in add return Add(**kwargs)(inputs) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 571, in __call__ self.build(input_shapes) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/layers/merge.py", line 84, in build output_shape = self._compute_elemwise_op_output_shape(output_shape, shape) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/layers/merge.py", line 55, in _compute_elemwise_op_output_shape str(shape1) + ' ' + str(shape2)) ValueError: Operands could not be broadcast together with shapes (331, 331, 168) (331, 331, 96)

titu1994 commented 6 years ago

NASNet is pretty exacting about it's input shape config and number of layers etc. This is due to several wierd padding and cropping and strided convs inside the normal and adjust blocks. Certain input sizes cause this error, though I have not seen such a large gap between the p and xi.

Are you trying to build a variant of the large model ?

DableUTeeF commented 6 years ago

Yes I trying the large NasNet. This also error.

from nasnet import NASNetLarge, NASNetMobile

model = NASNetLarge(input_shape=(331, 331, 3), dropout=0.5)

Traceback (most recent call last): File "<input>", line 1, in <module> File "/home/palm/PycharmProjects/lstm_test/nasnet.py", line 394, in NASNetLarge default_size=331) File "/home/palm/PycharmProjects/lstm_test/nasnet.py", line 217, in NASNet x, p = _reduction_A(x, p, filters // (filters_multiplier ** 2), weight_decay, id='stem_1') File "/home/palm/PycharmProjects/lstm_test/nasnet.py", line 707, in _reduction_A id='reduction_1_%s' % id) File "/home/palm/PycharmProjects/lstm_test/nasnet.py", line 569, in _separable_conv_block kernel_regularizer=l2(weight_decay))(x) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 596, in __call__ output = self.call(inputs, **kwargs) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/layers/convolutional.py", line 989, in call padding=self.padding) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 3212, in separable_conv2d rate=dilation_rate) File "/home/palm/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/nn_impl.py", line 486, in separable_conv2d channel_multiplier * in_channels, out_channels)) ValueError: Refusing to perform an overparameterized separable convolution: channel_multiplier * in_channels = 1 * 96 = 96 > 42 = out_channels

titu1994 commented 6 years ago

What version of Tensorflow do you use ? Can you upgrade to TF 1.5? I think the error is related to this : https://stackoverflow.com/questions/45193238/why-out-channels-must-be-greater-then-channel-multiplier-in-channels-in-pointw

The patch is available in TF 1.4+ I believe

DableUTeeF commented 6 years ago

That's works. Thanks.