Flattening output before calculating metrics
You need to evaluate the percentage of pixels in the output map which were correctly classified, and it doesn't matter whether it is represented as 2D or 1D. The demand is just that mask's and the ground truth pixels have to match each other.

You can find an example about Pixel Accuracy here.

So, if you would like, you can convert (stretch 2D) into a 1D vector. However, you can also implement computation of precision and recall by yourself. If you use python, it's easy to leverage construction with np.sum(mask), np.sum(target), or np.sum(mask*target) to calculate it for 2D:

TP = np.sum(mask*target)
FP = np.sum(mask*np.where(target == 0, 1, 0))
FN = np.sum(np.where(mask == 0, 1, 0)*target)
Precision = TP / ( TP + FP )
Recall = TP / ( TP + FN )
F1_measure = 2 * Precision * Recall /(Precision+Recall)