If the image as well as the mask have the same initial shape and you are applying the same transpose operations on these numpy arrays, the error might be raised by trying to stack different samples.
Could you check the shape of both arrays and make sure the height and width is equal for all samples?
PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier.