Hello, I’m currently participating in the Human Protein Analysis Kaggle competition, and was wondering what would be the best way to load 4 channel images using fastai v1.
Right now, we’ve written an ImageDataset class that gets passed into a Pytorch dataloader, which then gets passed into an ImageDataBunch.
class ImageDataset(Dataset):
def __init__(self, csv_path, matrices_path, transform=None):
self.csv_file = pd.read_csv(csv_path)
self.matrices_path = matrices_path
self.transform = transform
def __len__(self):
return len(self.csv_file)
def __getitem__(self, idx):
#csv_file=train_labels
#img_path="D:/Human Protein Atlas Image Classification/train/"
#idx=0
#path= img_path+csv_file.iloc[idx, 0]
path = self.matrices_path+self.csv_file.iloc[idx, 0]+".npy"
im = np.load(path)
im=torch.Tensor(im)
label = self.csv_file["Target"][idx].split()
label = [int(s) for s in label]
return im, label
dataset = ImageDataset(label_csv,matrixpath)
dataloader = DataLoader(dataset, batch_size=4,
shuffle=True, num_workers=4)
bunch = ImageDataBunch(dataloader, dataloader)
bunch.show_batch(rows=3)
Is this the best way to implement this in fastai v1? We’ve seen that people have used fastai v.7 to create models with 4 channels with success here: https://www.kaggle.com/zhugds/resnet34-with-rgby-fast-ai-fork/comments