Help me, please
I try this code with many directory data set and work fine in visualization
but with this data directory, it produced a weird visualization
import os
import torch
from torchvision import datasets, transforms
from torch.utils.data import Dataset, DataLoader
import torch
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import cv2
import numpy as np
Write data loaders for training, validation, and test sets
Specify appropriate transforms, and batch_sizes
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
number of subprocesses to use for data loading
num_workers = 0
how many samples per batch to load
batch_size = 16
data_transform_train = transforms.Compose([
transforms.Resize(256),

transforms.CenterCrop(224),

transforms.RandomHorizontalFlip(),

transforms.ToTensor(),

# transforms.Normalize((.5), (.5))

])

data_transform_test = transforms.Compose([
transforms.Resize(256),

transforms.CenterCrop(224),

transforms.ToTensor(),

# transforms.Normalize((0.5), (0.5))

])

data_dir = ‘/content/gdrive/MyDrive/graduation_project_dataset/Mammogram’
train_dir = os.path.join(data_dir, ‘train’)
valid_dir = os.path.join(data_dir, ‘valid’)
test_dir = os.path.join(data_dir, ‘test’)
train_data = datasets.ImageFolder(train_dir, transform=data_transform_train)
valid_data = datasets.ImageFolder(valid_dir, transform=data_transform_test)
test_data = datasets.ImageFolder(test_dir, transform=data_transform_test)
train_loader = torch.utils.data.DataLoader(train_data, batch_size=batch_size, num_workers=num_workers, shuffle=True)
valid_loader = torch.utils.data.DataLoader(valid_data, batch_size=batch_size, num_workers=num_workers, shuffle=True)
test_loader = torch.utils.data.DataLoader(test_data, batch_size=batch_size, num_workers=num_workers, shuffle=True)
loaders_scratch = {
'train' : train_loader,

'valid' : valid_loader,

'test'  : test_loader

}
dataiter = iter(train_loader)
images, labels = dataiter.next()
images = images.numpy()
#plot
fig = plt.figure(figsize=(25,4))
for idx in np.arange(3):
ax = fig.add_subplot(1, 10/2, idx+2, xticks=[], yticks=[])
plt.imshow(np.transpose(images[idx] * 255, (1,2,0)))
ax.set_title(train_data.classes[idx])
print(images.shape)

dd1219×429 17.3 KB

Thanks