6 channel input with Imagefolder up

username: medhani
cooked: <p>I have two separate datasets. Each set has 3<em>224</em>224 images. I want to input those datasets into a network as a 6 channel input. Both datasets have the same labels. I want to use Imagefolder for this.</p>
<pre><code class="lang-python">trainset_cort = torchvision.datasets.ImageFolder(root=data_dir_train_cort,
                                transform=transform)

                        
                                          
trainset_slice = torchvision.datasets.ImageFolder(root=data_dir_train_slice,
                                transform=transform)
                                
  

      

trainloader= torch.utils.data.DataLoader(trainset_new
             , 
             batch_size=4,shuffle=True, num_workers=2)



testset_cort = torchvision.datasets.ImageFolder(root=data_dir_val_cort,
                                transform=transform)

                                          
testset_slice = torchvision.datasets.ImageFolder(root=data_dir_val_slice,
                                                 transform=transform)
                                                 


testloader= torch.utils.data.DataLoader(testset_new
             , batch_size=4,shuffle=True, num_workers=2)
             
             
</code></pre>
<p>I’m trying above code. i want to create both trainset_new and testset_new as 6 by 224  by 224 imageset</p>

username: ptrblck
cooked: <p>You could create your own <code>Dataset</code> and concatenate both images:</p>
<pre><code class="lang-python">class MyDataset(Dataset):
    def __init__(self, path_cort, path_slice, transform=None):
        self.data_cort = datasets.ImageFolder(
            root=path_cort, transform=transform)
        self.data_slice = datasets.ImageFolder(
            root=path_slice, transform=transform)
        
    def __getitem__(self, index):
        x_cort, y = self.data_cort[index]
        x_slice, _ = self.data_slice[index]
        x = torch.cat((x_cort, x_slice), dim=1)
        return x, y
    
    def __len__(self):
        return len(self.data_cort) # assert both datasets have equal length
</code></pre>

username: medhani
cooked: <p>Thank you. I’ll try this method.</p>

username: Rohit_Kundu
cooked: <p>using this I get the error as:</p>
<pre><code class="lang-auto">module.__init__() takes at most 2 arguments (3 given)
</code></pre>
<p>I am using google colab for this and the code I ran is this:</p>
<pre><code class="lang-auto">import torch
import torch.nn as nn
import torch.optim as optim
from torch.optim import lr_scheduler
import numpy as np
import torchvision
from torchvision import datasets, models, transforms
import matplotlib.pyplot as plt
import time
import os
import copy

class CustomDataset(datasets):
    def __init__(self, path_cort, path_slice, transform):
        self.data_cort = datasets.ImageFolder(
            root=path_cort, transform=transform)
        self.data_slice = datasets.ImageFolder(
            root=path_slice, transform=transform)
        
    def __getitem__(self, index):
        x_cort, y = self.data_cort[index]
        x_slice, _ = self.data_slice[index]
        x = torch.cat((x_cort, x_slice), dim=1)
        return x, y
    
    def __len__(self):
        return len(self.data_cort) # assert both datasets have equal length

root = "/content/drive/MyDrive/Rohit/Human Pose Estimation/UTD MHAD/"
transform = transforms.Compose([
                                transforms.Resize((224,224)),
                                transforms.ToTensor(),
                                transforms.Normalize(mean, std)
                                ])
Dataset = CustomDataset(root+"angle/train", root+"anglevel/train", transform)

num_classes = 27
</code></pre>
<p>Inside the respective train folders, each class has several images.</p>
<p>Hope you will help me out, thanks in advance</p>

username: ptrblck
cooked: <p>Could you device the <code>CustomDataset</code> from <code>torch.utils.data.Dataset</code> instead of <code>torchvision.datasets</code> and check, if it would solve the issue?</p>