Flattening output before calculating metrics I use scikit-learn to calculate precision, recall and f1 scores which only accept 1D arrays, but my model's outputs are 2D (binary segmentation maps). My question is, is it ok to simply flatten the outputs, or is there some other function I should use to calculate the metrics in my case?
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)