镜像自地址
https://github.com/xming521/CTAI.git
已同步 2025-12-07 07:06:48 +00:00
upload train code
这个提交包含在:
38
CTAI_model/utils/dice_loss.py
普通文件
38
CTAI_model/utils/dice_loss.py
普通文件
@@ -0,0 +1,38 @@
|
||||
import numpy as np
|
||||
|
||||
|
||||
def dice(im1, im2):
|
||||
"""
|
||||
Computes the Dice coefficient, a measure of set similarity.
|
||||
Parameters
|
||||
----------
|
||||
im1 : array-like, bool
|
||||
Any array of arbitrary size. If not boolean, will be converted.
|
||||
im2 : array-like, bool
|
||||
Any other array of identical size. If not boolean, will be converted.
|
||||
Returns
|
||||
-------
|
||||
dice : float
|
||||
Dice coefficient as a float on range [0,1].
|
||||
Maximum similarity = 1
|
||||
No similarity = 0
|
||||
|
||||
Notes
|
||||
-----
|
||||
The order of inputs for `dice` is irrelevant. The result will be
|
||||
identical if `im1` and `im2` are switched.
|
||||
"""
|
||||
im1 = np.asarray(im1).astype(np.bool)
|
||||
im2 = np.asarray(im2).astype(np.bool)
|
||||
|
||||
if im1.shape != im2.shape:
|
||||
raise ValueError("Shape mismatch: im1 and im2 must have the same shape.")
|
||||
|
||||
# 俩都为全黑
|
||||
if not (im1.any() or im2.any()):
|
||||
return 1.0
|
||||
|
||||
# Compute Dice coefficient
|
||||
intersection = np.logical_and(im1, im2)
|
||||
res = 2. * intersection.sum() / (im1.sum() + im2.sum())
|
||||
return np.round(res, 5)
|
||||
在新工单中引用
屏蔽一个用户