xiaolai-sqlai / mobilenetv3

mobilenetv3 with pytorch,provide pre-train model

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

batchnorm handing issue when inference

lucasjinreal opened this issue · comments

When inference on single image (batch size = 1) got error:

mobilenetv3.py", line 199, in forward
    out = self.hs3(self.bn3(self.linear3(out)))
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/batchnorm.py", line 76, in forward
    exponential_average_factor, self.eps)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py", line 1619, in batch_norm
    raise ValueError('Expected more than 1 value per channel when training, got input size {}'.format(size))
ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 1280])

I had the same problem. How to solve this problem?

You can heed https://arxiv.org/pdf/1905.02244.pdf that there is no bn in the SEmodule.
When the AdaptiveAvgpool option make the feature_map to channelsX1X1 and the batch size is One, the batch normalization will wrong.
So just remove the BN option in the SEmodule will be ok!

commented

Same question, interesting problem hah hah