Exactly the same code:
class MyDataset(Dataset):
    def __init__(self, mnist_transform=None, svhn_transform=None):
        mnist = datasets.MNIST(
            root='./data/mnist',
            train=False,
            download= True
        )
                
        svhn = datasets.SVHN(
            root='./data/svhn',
            download=True
        )
        
        self.mnist_len = 100
        self.svhn_len = 10
        
        rand_idx = torch.randperm(len(mnist.test_data))[:self.mnist_len]
        self.mnist_data = mnist.test_data[rand_idx]
        
        rand_idx = torch.randperm(len(svhn.data))[:self.svhn_len]
        self.svhn_data = svhn.data[rand_idx]

        self.mnist_transform = mnist
        self.svhn_transform = svhn_transform
        
    def __getitem__(self, index):
        if index < self.mnist_len:
            x = self.mnist_data[index]
            if self.mnist_transform:
                x = self.mnist_transform(x)
            print('Returning MNIST sample at index {}'.format(index))
            return x
        else:
            index = index - self.mnist_len
            x = self.svhn_data[index]
            if self.svhn_transform:
                x = self.svhn_transform(x)
            print('Returning SVHN data at index {}'.format(index))
            return x
        
    def __len__(self):
        return self.mnist_len + self.svhn_len

        

mnist_transform = transforms.Compose([
    transforms.ToPILImage(),
    transforms.Resize((32, 32)),
    transforms.Grayscale(num_output_channels=3),
    transforms.ToTensor(),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])
    
svhn_transform = transforms.Compose([
    transforms.Resize((32, 32)),
    transforms.ToPILImage(),
    transforms.ToTensor(),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])
    
dataset_new = MyDataset(
    mnist_transform=mnist_transform,
    svhn_transform=svhn_transform
)


loader = DataLoader(
    dataset_new,
    batch_size=100,
    shuffle=True,
    num_workers=4
)

for data in loader:
    output = model2(data)
    print(output)

TypeError: ‘MNIST’ object is not callable