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

BatchNormalization.lua:87: got 32-feature tensor, expected 0 #1327

Closed
emredog opened this issue May 21, 2022 · 1 comment
Closed

BatchNormalization.lua:87: got 32-feature tensor, expected 0 #1327

emredog opened this issue May 21, 2022 · 1 comment

Comments

@emredog
Copy link

emredog commented May 21, 2022

Hello,

I have a model that makes use of the nn.SpatialBatchNormalization, and I got the error in the title.

I want to make inference on a single image (3x224x224). I've tried both "unsqueezed" (1x3x224x224) and the original, both lead to the same error.

The relevant part of the network is as follows:

  (1): nn.SpatialConvolution(3 -> 32, 3x3, 1,1, 1,1) without bias
  (2): nn.SpatialBatchNormalization (4D) (0)

I've added the following prints to the checkInput function that throws the error:

function BN:checkInputDim(input)
   local iDim = input:dim()
   assert(iDim == self.nDim or
              (iDim == self.nDim - 1 and self.train == false), string.format(
      'only mini-batch supported (%dD tensor), got %dD tensor instead',
      self.nDim, iDim))
   local featDim = (iDim == self.nDim - 1) and 1 or 2
   print("train mode?", self.train)
   print("featDim", featDim)
   print("runningMean:nElement", self.running_mean:nElement())
   print("input size:", input:size())
   assert(input:size(featDim) == self.running_mean:nElement(), string.format(
      'got %d-feature tensor, expected %d',
      input:size(featDim), self.running_mean:nElement()))
end

this yields the following output for the unsqueezed image:

train mode?	false	
featDim	2	
runningMean:nElement	0	
input size:	   1
  32
 224
 224
[torch.LongStorage of size 4]

Any help or lead to what to try next is much appreciated, thanks!

@emredog
Copy link
Author

emredog commented May 21, 2022

I believe this is caused by the lack of the running_mean being null (0 element). Another person encountered probably the same error as me: gaobb/DLDL-v2#4

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

No branches or pull requests

1 participant