text_plain_output_1.png
from torch.utils.data import Dataset, DataLoader, ConcatDataset

from torchvision.transforms import transforms

import cv2

import cv2

import os

import os

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import torch

import torchvision

import numpy as np
import pandas as pd
import os

data_lebel = pd.read_csv('/kaggle/input/soft-computing-even-id-dataset/training-a.csv')

img = cv2.imread('/kaggle/input/soft-computing-even-id-dataset/training-a/a00000.png')

IMAGE_SIZE = 40
transform = transforms.Compose([transforms.ToPILImage(), torchvision.transforms.ColorJitter(brightness=0.4, saturation=0.4, contrast=0.4, hue=0.4), transforms.RandomRotation(20, expand=True), transforms.Resize(IMAGE_SIZE), transforms.CenterCrop(IMAGE_SIZE), transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

class digit_Dataset(Dataset):
    def __init__(self, csv_file, root_dir, transform=True):
        self.annotations = pd.read_csv(csv_file)
        self.root_dir = root_dir
        self.transform = transform
    def __len__(self):
        return len(self.annotations)
    def __getitem__(self, index):
        img_path = os.path.join(self.root_dir, self.annotations.iloc[index, 0])
        image = cv2.imread(img_path)
        y_label = torch.tensor(int(self.annotations.iloc[index, 3]))
        if self.transform:
            image = self.transform(image)
        return (image, y_label)

dataset = digit_Dataset(csv_file='/kaggle/input/soft-computing-even-id-dataset/training-a.csv', root_dir='/kaggle/input/soft-computing-even-id-dataset/training-a', transform=transform)

train_set, test_set = torch.utils.data.random_split(dataset, [15702, 4000])
train_loader = DataLoader(dataset=train_set, batch_size=16, shuffle=True)
test_loader = DataLoader(dataset=test_set, batch_size=16, shuffle=True)

data_iter = iter(train_loader)
images, labels = data_iter.next()
images.shape