def dsc_distribution(volumes): dsc_dict = {} for p in volumes: y_pred = volumes[p][1] y_true = volumes[p][2] dsc_dict[p] = dsc(y_pred, y_true, lcc=False) return dsc_dict
def dsc_per_volume(validation_pred, validation_true): assert len(validation_pred) == len(validation_true) dsc_list = [] for p in range(len(validation_pred)): y_pred = np.array([validation_pred[p]]) y_true = np.array([validation_true[p]]) dsc_list.append(dsc(y_pred, y_true)) return dsc_list
def get_batch_dsc(y_pred_batch, mask): batch_dsc = [] batch_size = mask.shape[0] for case in range(batch_size): y_pred = y_pred_batch[case, 0, :] # get a 3d volume for each case y_true = mask[case, 0, :] batch_dsc.append(dsc(y_pred, y_true)) return batch_dsc
def dsc_per_volume(validation_pred, validation_true, patient_slice_index): dsc_list = [] num_slices = np.bincount([p[0] for p in patient_slice_index]) index = 0 for p in range(len(num_slices)): y_pred = np.array(validation_pred[index : index + num_slices[p]]) y_true = np.array(validation_true[index : index + num_slices[p]]) dsc_list.append(dsc(y_pred, y_true)) index += num_slices[p] return dsc_list
num_slices = np.bincount([p[0] for p in loader.dataset.patient_slice_index]) index = 0 for p in range(len(num_slices)): volume_in = np.array(input_list[index : index + num_slices[p]]) volume_pred = np.round(np.array(pred_list[index : index + num_slices[p]])).astype(int) volume_pred = largest_connected_component(volume_pred) volume_true = np.array(true_list[index : index + num_slices[p]]) volumes[loader.dataset.patients[p]] = (volume_in, volume_pred, volume_true) index += num_slices[p] dsc_dict = {} for p in volumes: y_pred = volumes[p][1] y_true = volumes[p][2] dsc_dict[p] = dsc(y_pred, y_true, lcc=False) y_positions = np.arange(len(dsc_dict)) dsc_dict = sorted(dsc_dict.items(), key=lambda x: x[1]) values = [x[1] for x in dsc_dict] labels = [x[0] for x in dsc_dict] labels = ["_".join(l.split("_")[1:-1]) for l in labels] fig = plt.figure(figsize=(12, 8)) canvas = FigureCanvasAgg(fig) plt.barh(y_positions, values, align="center", color="skyblue") plt.yticks(y_positions, labels) plt.xticks(np.arange(0.0, 1.0, 0.1)) plt.xlim([0.0, 1.0]) plt.gca().axvline(np.mean(values), color="tomato", linewidth=2) plt.gca().axvline(np.median(values), color="forestgreen", linewidth=2)