Problems Using BatchNorm1d

Hey, I’m trying to use BatchNorm1d in a simple neural network of a bunch of fully connected layers with a 1-dimensional input. My code is similar to the code in the tutorials, but it doesn’t run for some reason. I get the following error:

RuntimeError: running_mean should contain 1 elements not 32

Searching around for related terms hasn’t turned up much. When I try setting track_running_stats to false in the declaration, I get the error that track_running_stats isn’t a valid setting. I’m pretty confused and would appreciate some help.

Pictures of my code:


You should be looking at the docs for the version of pytorch that you have installed, not the docs for the development version.
If you have pytorch 0.3.1, then the docs are at

What shape is the input data?

Oh, thanks for pointing that out. I didn’t know documentation defaulted to the development version.

A single example of my input data is just a vector of 17 numerical features. I’m passing in a minibatch of 100 examples, so the final input to the network is should be 100 x 16. The batchnorm layer takes 32 activations from the first layer, which I think is where the 32 in the error message is coming from.

I have the exact same problem. Did you find a solution? Could you please post how you solved the problem, if you did.

1 Like

what the size of the tensor going to batch normalization
maybe you are trying to use batch normalization without giving it a batch
when you do not have a batch freeze batch normalization using:
state = torch.from_numpy(state).float()
NetworkName.eval() # Sets the module in evaluation mode (no batchnorm or dropout)
with torch.no_grad(): # no need to calculate gradients now, we are not training (save resources)
action_values = NetworkName(state)
NetworkName.train() # # Sets the module back in training mode

when you have a batch use: