MCPcopy Create free account
hub / github.com/SooLab/CGFormer / intersectionAndUnionGPU

Function intersectionAndUnionGPU

utils/misc.py:147–166  ·  view source on GitHub ↗
(output, target, K, threshold=0.5)

Source from the content-addressed store, hash-verified

145
146
147def intersectionAndUnionGPU(output, target, K, threshold=0.5):
148 # 'K' classes, output and target sizes are N or N * L or N * H * W, each value in range 0 to K - 1.
149 assert (output.dim() in [1, 2, 3])
150 assert output.shape == target.shape
151 output = output.view(-1)
152 target = target.view(-1)
153
154 output = torch.sigmoid(output)
155 output[output < threshold] = 0.
156 output[output >= threshold] = 1.
157
158 intersection = output[output == target]
159 area_intersection = torch.histc(intersection.float(),
160 bins=K,
161 min=0,
162 max=K - 1)
163 area_output = torch.histc(output.float(), bins=K, min=0, max=K - 1)
164 area_target = torch.histc(target.float(), bins=K, min=0, max=K - 1)
165 area_union = area_output + area_target - area_intersection
166 return area_intersection[1], area_union[1]
167
168
169def group_weight(weight_group, module, lr):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected