Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export efficientnet_b0b model failed #32

Closed
waquey opened this issue Sep 3, 2019 · 1 comment
Closed

export efficientnet_b0b model failed #32

waquey opened this issue Sep 3, 2019 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@waquey
Copy link

waquey commented Sep 3, 2019

Hello, I've tried to export efficientnet_b0b. However, it failed.

The following is my code segment:

net = glcv2_get_model("efficientnet_b0b", pretrained=True)
net.hybridize()

x = np.zeros([1,3,224,244])
x = mx.nd.array(x)

net.forward(x)
net.export('efficientnet_b0b')

And the error message is as following:

File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/block.py", line 915, in forward
return self._call_cached_op(x, *args)
File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/block.py", line 805, in _call_cached_op
self._build_cache(*args)
File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/block.py", line 757, in _build_cache
data, out = self._get_graph(*args)
File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/block.py", line 749, in _get_graph
out = self.hybrid_forward(symbol, *grouped_inputs, **params) # pylint: disable=no-value-for-parameter
File "/usr/local/lib/python2.7/dist-packages/gluoncv2/models/efficientnet.py", line 393, in hybrid_forward
x = self.features(x)
File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/block.py", line 548, in call
out = self.forward(*args)
File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/block.py", line 932, in forward
return self.hybrid_forward(symbol, x, *args, **params)
File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/nn/basic_layers.py", line 117, in hybrid_forward
x = block(x)
File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/block.py", line 548, in call
out = self.forward(*args)
File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/block.py", line 932, in forward
return self.hybrid_forward(symbol, x, *args, **params)
File "/usr/local/lib/python2.7/dist-packages/gluoncv2/models/efficientnet.py", line 274, in hybrid_forward
x = F.pad(x, mode="constant", pad_width=calc_tf_padding(x, kernel_size=3, strides=2), constant_value=0)
File "/usr/local/lib/python2.7/dist-packages/gluoncv2/models/efficientnet.py", line 43, in calc_tf_padding
height, width = x.shape[2:]
AttributeError: 'Symbol' object has no attribute 'shape'

Do you know how to modify it? Thanks

@osmr osmr self-assigned this Sep 3, 2019
@osmr osmr added the enhancement New feature or request label Sep 3, 2019
@osmr
Copy link
Owner

osmr commented Sep 3, 2019

Hi, yes, the current implementation of the TF-like EfficientNet models (models with b-suffix) does not allow hybridization. EfficientNet models without b-suffix don't have such a problem.

For the EfficientNet-b model, you need to exclude the calculation of x.shape in the calc_tf_padding function. This requires careful modification of the model script (the weights will be preserved.) I can’t do this right now due to lack of time.

The standard way in this situation is to analyze what values are obtained in these places during the debug of a non-hybridized network (they will be different depending on the size of the network input!) And pass the valid values of height and width to calc_tf_padding function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants