MCPcopy Create free account
hub / github.com/SLDGroup/MERIT / val_single_volume

Function val_single_volume

utils/utils.py:249–292  ·  view source on GitHub ↗
(image, label, net, classes, patch_size=[256, 256], test_save_path=None, case=None, z_spacing=1)

Source from the content-addressed store, hash-verified

247
248
249def val_single_volume(image, label, net, classes, patch_size=[256, 256], test_save_path=None, case=None, z_spacing=1):
250 image, label = image.squeeze(0).cpu().detach().numpy(), label.squeeze(0).cpu().detach().numpy()
251
252 if len(image.shape) == 3:
253 prediction = np.zeros_like(label)
254 for ind in range(image.shape[0]):
255 slice = image[ind, :, :]
256 x, y = slice.shape[0], slice.shape[1]
257 if x != patch_size[0] or y != patch_size[1]:
258 slice = zoom(slice, (patch_size[0] / x, patch_size[1] / y), order=3) # previous using 0
259 input = torch.from_numpy(slice).unsqueeze(0).unsqueeze(0).float().cuda()
260 net.eval()
261 with torch.no_grad():
262
263 P = net(input)
264 #print(len(P))
265
266 outputs = 0.0
267 for idx in range(len(P)):
268 outputs += P[idx]
269 out = torch.argmax(torch.softmax(outputs, dim=1), dim=1).squeeze(0)
270 out = out.cpu().detach().numpy()
271 if x != patch_size[0] or y != patch_size[1]:
272 pred = zoom(out, (x / patch_size[0], y / patch_size[1]), order=0)
273 else:
274 pred = out
275 prediction[ind] = pred
276 else:
277 input = torch.from_numpy(image).unsqueeze(
278 0).unsqueeze(0).float().cuda()
279 net.eval()
280 with torch.no_grad():
281
282 P = net(input)
283
284 outputs = 0.0
285 for idx in range(len(P)):
286 outputs += P[idx]
287 out = torch.argmax(torch.softmax(outputs, dim=1), dim=1).squeeze(0)
288 prediction = out.cpu().detach().numpy()
289 metric_list = []
290 for i in range(1, classes):
291 metric_list.append(calculate_dice_percase(prediction == i, label == i))
292 return metric_list
293
294def val_single_volume_1out(image, label, net, classes, patch_size=[256, 256], test_save_path=None, case=None, z_spacing=1):
295 image, label = image.squeeze(0).cpu().detach().numpy(), label.squeeze(0).cpu().detach().numpy()

Callers 1

inferenceFunction · 0.90

Calls 1

calculate_dice_percaseFunction · 0.85

Tested by

no test coverage detected