IOU metric in sematic segmentation

thank you
the threshold is to binarize the predicated output I don’t now why they threshold out.
i have 5 class in output so the size is
8x5x512x512
and the gt (ground truth) is 8x512x512
how can i calculate the semantic segmentation metric (IOU and F1 ) ?
any suggestion !