属性错误:无法在Jupyter中的<module'__main __'(内置)>上获取属性'BrainSet'

时间:2020-06-02 06:59:15

标签: python

在尝试实施细分解决方案时,我正在尝试分析大脑的图像。一切都在python 3.8.2中的Jupyter Notebook中。我下面有一个课程:

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

然后我进行转换,然后分成训练,测试和验证集,它们全部显示正确的输出。然后,我将图像放大:

    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)

返回AttributeError: Can't get attribute 'BrainSet' on <module '__main__' (built-in)>我已经看到Multiprocessing example giving AttributeErrorAttributeError: Can't get attribute on <module '__main__' from 'manage.py'>的建议这样做from __main__ import BrainSet。我已经试过了,并抛出了同样的错误。任何想法将不胜感激!

0 个答案:

没有答案