It looks like you are already printing the shape so you should be able to see what N, and D are here.
Flatten can work, but rather than reshaping to (-1, something), you should reshape to (batch_size, -1).