slavavs:

Why, when changing batch size, do the weights of neurons change?


The weights do not change based on the batch size or the forward pass alone.
Could you explain this issue a bit more?



 slavavs:

If I test new data with a batch size equal to the size with which I trained NN, then the results are good. If you change the batch size, the results are bad.


Make sure to call model.eval() before evaluating your model, as otherwise e.g. the running estimates of batchnorm layers will be updated, which depends on the used batch size.