Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Predict the sample with the provided model
model.predict([sample_index], return_output=False)
# Load the sample
sample = model.preprocessor.data_io.sample_loader(sample_index,
load_seg=True,
load_pred=True)
# Access image, truth and predicted segmentation data
img, seg, pred = sample.img_data, sample.seg_data, sample.pred_data
# Calculate classwise dice score
dice_scores = compute_dice(seg, pred, len(classes))
# Save detailed validation scores to file
scores = [sample_index]
scores.extend(dice_scores)
backup_evaluation(scores, evaluation_path, start=False)
# Visualize the truth and prediction segmentation
visualize_evaluation(sample_index, img, seg, pred, evaluation_path)
score_kidney, score_tumor = kits19_score(truth, pred)
# Save kits19 score to file
save_evaluation([id, score_kidney, score_tumor],
config["evaluation_path"],
"kits19_scoring." + suffix + ".tsv")
# Calculate class frequency per slice
if config["class_freq"]:
class_freq = calc_ClassFrequency(truth, pred)
for i in range(len(class_freq)):
print(str(id) + "\t" + str(i) + "\t" + str(class_freq[i]))
# Visualize the truth and prediction segmentation
if config["visualize"]:
# Load the volume
vol = load_volume_nii(id, config["data_path"]).get_data()
# Run visualization
visualize_evaluation(id, vol, truth, pred, config["evaluation_path"])