I think your functions will work fine for evaluation, but I do not think will not work if you want to use them for training (gradient optimization). I found Loss Function Library - Keras & PyTorch | Kaggle 4 very helpful. You can also modify these functions, e.g. threshold for IoU and add a multiclass version for mIoU, and use them for faster evaluation on GPU.