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

Function val_single_volume

utils/utils.py:239–274  ·  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

237 return metric_list
238
239def val_single_volume(image, label, net, classes, patch_size=[256, 256], test_save_path=None, case=None, z_spacing=1):
240 image, label = image.squeeze(0).cpu().detach().numpy(), label.squeeze(0).cpu().detach().numpy()
241
242 if len(image.shape) == 3:
243 prediction = np.zeros_like(label)
244 for ind in range(image.shape[0]):
245 slice = image[ind, :, :]
246 x, y = slice.shape[0], slice.shape[1]
247 if x != patch_size[0] or y != patch_size[1]:
248 slice = zoom(slice, (patch_size[0] / x, patch_size[1] / y), order=3) # previous using 0
249 input = torch.from_numpy(slice).unsqueeze(0).unsqueeze(0).float().cuda()
250 net.eval()
251 with torch.no_grad():
252 P = net(input)
253 outputs = 0.0
254 outputs = P[-1]
255 out = torch.argmax(torch.softmax(outputs, dim=1), dim=1).squeeze(0)
256 out = out.cpu().detach().numpy()
257 if x != patch_size[0] or y != patch_size[1]:
258 pred = zoom(out, (x / patch_size[0], y / patch_size[1]), order=0)
259 else:
260 pred = out
261 prediction[ind] = pred
262 else:
263 input = torch.from_numpy(image).unsqueeze(
264 0).unsqueeze(0).float().cuda()
265 net.eval()
266 with torch.no_grad():
267 P = net(input)
268 outputs = P[-1]
269 out = torch.argmax(torch.softmax(outputs, dim=1), dim=1).squeeze(0)
270 prediction = out.cpu().detach().numpy()
271 metric_list = []
272 for i in range(1, classes):
273 metric_list.append(calculate_dice_percase(prediction == i, label == i))
274 return metric_list
275
276def horizontal_flip(image):
277 image = image[:, ::-1, :]

Callers 1

inferenceFunction · 0.90

Calls 1

calculate_dice_percaseFunction · 0.85

Tested by

no test coverage detected