0

I am attempting to analyse images of brains as practice implementing segmentation solutions. It is all in one Jupyter Notebook in python 3.8.2. I have a class below:

class BrainSet(Dataset):
   def __init__(self, df, transforms):

       self.df = df
       self.transforms = transforms

   def __len__(self):
       return len(self.df)

   def __getitem__(self, idx):
       image = cv2.imread(self.df.iloc[idx, 1])
       mask = cv2.imread(self.df.iloc[idx, 2], 0)

       augmented = self.transforms(image=image, 
                                mask=mask)

       image = augmented['image']
       mask = augmented['mask']   

       return image, mask

I then run through transforms and then separate into train, test and validation sets which all show correct ouputs. I then augment the images like:

    def show_aug(inputs, nrows=5, ncols=5, image=True):
        plt.figure(figsize=(10, 10))
        plt.subplots_adjust(wspace=0., hspace=0.)
        i_ = 0

        if len(inputs) > 25:
           inputs = inputs[:25]

        for idx in range(len(inputs)):

    # normalization
            if image is True:           
               img = inputs[idx].numpy().transpose(1,2,0)
               mean = [0.485, 0.456, 0.406]
               std = [0.229, 0.224, 0.225] 
               img = (img*std+mean).astype(np.float32)
            else:
               img = inputs[idx].numpy().astype(np.float32)
               img = img[0,:,:]

    #plot

            plt.subplot(nrows, ncols, i_+1)
            plt.imshow(img); 
            plt.axis('off')

            i_ += 1

     return plt.show()


  images, masks = next(iter(train_dataloader))

  print(images.shape, masks.shape)

  show_aug(images)
  show_aug(masks, image=False)

This returns AttributeError: Can't get attribute 'BrainSet' on <module '__main__' (built-in)>I have seen Multiprocessing example giving AttributeError and AttributeError: Can't get attribute on <module '__main__' from 'manage.py'> which suggests to do from __main__ import BrainSet. I have tried this and have the same error thrown. Any ideas would be greatly appreciated!

Aidan01
  • 25
  • 1
  • 7
  • 1
    You have not posted your whole code and also full traceback is missing. Very difficult to help you, if not all code try posting some sample code which has same error. Still I recommend you to check this thread - https://stackoverflow.com/questions/36533134/cant-get-attribute-abc-on-module-main-from-abc-h-py – anuragal Jun 02 '20 at 07:10
  • Thanks @anuragal - I will remember for future posts. I have tried to implement this Kaggle notebook found https://www.kaggle.com/bonhart/brain-mri-data-visualization-unet-fpn and have just changed the BrainMriDataset to BrainSet – Aidan01 Jun 02 '20 at 07:51

0 Answers0