There are several repositories where it was already implemented (probably in the correct way):

https://github.com/pytorch/vision/blob/master/references/segmentation/utils.py#L95 152
https://github.com/pytorch/ignite/blob/master/ignite/metrics/confusion_matrix.py#L129 79

In your case, as far as I understand the difference is the following:

first implementation computes the mean over N images of Jaccard Index per image
second implementation computes Jaccard Index as all N images were concat.

Maybe, the second is more standard.
HTH