It seems to me that batch norm is not applicable to your situation.

For the training phase, it could actually work. In practice B and M can change from one batch to another.
For the test phase, it wouldn’t be possible. A CNN’s output for a certain example is always independent of other examples. If you predict on image X1 alone, it will give you a result y1. If you predict on a batch [X1,X2], you want the output for X1 to be y1, the same as before; not some value dependent on X2.
Therefore, during the test phase, the mean and variance vectors used by batch norm are fixed; thus, their size (M) is also fixed.

EDIT: Here I assume some basic understanding of batch norm. See this article I’ve written for more details: https://vitalab.github.io/deep-learning/2017/02/09/batch-norm.html 58. You can also ask me questions here if you feel my answer is not so clear.