def __init__(self, sample_df, data_path, output_size=512, mask_img=True): """ Constructor of the dataset. ---------- INPUT |---- sample_df (pandas.DataFrame) the dataframe containing the | samples' filenames, labels, (semi-labels and mask-filename). |---- data_path (str) the path to the data filenames specified in the sample_df |---- output_size (int) the size of the output squared image. |---- mask_img (bool) whether to mask image. """ data.Dataset.__init__(self) self.sample_df = sample_df self.data_path = data_path self.transform = tf.Compose( tf.Grayscale(), tf.AutoContrast(cutoff=1), tf.RandomHorizontalFlip(p=0.5), tf.RandomScaling(scale_range=(0.8, 1.2)), tf.RandomRotation(degree_range=(-45, 45)), tf.ResizeMax(max_len=output_size), tf.PadToSquare(), tf.RandomCropResize((output_size, output_size), scale=(0.4, 1.0), ratio=(4. / 5., 5. / 4.)), tf.ColorDistorsion(s=0.5), tf.GaussianBlur(p=0.5, sigma=(0.1, 2.0)), tf.MinMaxNormalization(), tf.MaskImage(mask_img), tf.ToTorchTensor())
def __init__(self, sample_df, data_path, mask_img=True, output_size=512, data_augmentation=True): """ Constructor of the dataset. ---------- INPUT |---- sample_df (pandas.DataFrame) the dataframe containing the | samples' filenames, labels, (semi-labels and mask-filename). |---- data_path (str) the path to the data filenames specified in the sample_df |---- mask_img (bool) whether to mask the image. |---- output_size (int) the size of the output squared image. |---- data_augmentation (bool) whether to perform data augmentation. """ data.Dataset.__init__(self) self.sample_df = sample_df self.data_path = data_path if data_augmentation: self.transform = tf.Compose(tf.Grayscale(), \ tf.AutoContrast(cutoff=1), \ tf.RandomHorizontalFlip(p=0.5), \ tf.RandomVerticalFlip(p=0.5), \ tf.RandomBrightness(lower=0.8, upper=1.2), \ tf.RandomScaling(scale_range=(0.8,1.2)), \ tf.RandomRotation(degree_range=(-20,20)), \ tf.ResizeMax(output_size), \ tf.PadToSquare(), \ tf.MinMaxNormalization(), \ tf.MaskImage(mask_img), \ tf.ToTorchTensor()) else: self.transform = tf.Compose(tf.Grayscale(), \ tf.AutoContrast(cutoff=1), \ tf.ResizeMax(output_size), \ tf.PadToSquare(), \ tf.MinMaxNormalization(), \ tf.MaskImage(mask_img), \ tf.ToTorchTensor())
color='limegreen', alpha=0.4) ax.set_title(part.title(), fontsize=12) ax.ticklabel_format(style='sci', axis='x', scilimits=(0, 0)) fig.savefig(FIGURE_PATH + 'score_distribution.pdf', dpi=dpi, bbox_inches='tight') plt.show() #%%############################################################################# # 10 highest scores by body part # ################################################################################ img_transform = tf.Compose(tf.Grayscale(), tf.ResizeMax(max_len=512), tf.PadToSquare(), tf.ToTorchTensor()) j = 1 for label, low_ad in zip([1, 1, 0, 0], [False, True, False, True]): fig, axs = plt.subplots(7, 10, figsize=(20, 14), gridspec_kw={ 'hspace': 0.25, 'wspace': 0.0 }) if transparent: fig.set_alpha(0.0) for ax_row, part in zip(axs, BodyPart_list): df_high = df[(df.body_part == part) & (df.abnormal_XR == label)].sort_values(