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!