added a way to show an example of stuff in the dataset

This commit is contained in:
Artem 2025-03-20 15:50:33 -04:00
parent 0567db2f07
commit c72a00dc0d
2 changed files with 15 additions and 9 deletions

View file

@ -4,7 +4,7 @@ import torchvision.transforms as transforms
CIFAR_DIR = Path('Data/CIFAR10')
CIFAR_DIR.mkdir(exist_ok = True)
#you can add more and bump the numbers even more up
normalize = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))

View file

@ -1,20 +1,26 @@
import torchvision
from consts import CIFAR_DIR
from consts import TRAIN_DATA
import torchvision.transforms as transforms
from dogs_cats_ds import DogCatDataset
import random
#optional transformations:
# https://pytorch.org/vision/0.11/transforms.html
#training data using torchvision cifar.
cifar_data_train = torchvision.datasets.CIFAR10(root = CIFAR_DIR, train = True, transform = None, download = True)
#example of cifar data sample. It is an image, class example.
# here, the image is the image (PIL, or pillow) and the corresponding label, frog. I've chopped the dataset to only include cats
# and dogs, so we can apply a different form of classification so it's easier to perform
example_data = cifar_data_train[0]
print(f'items in an instance of cifar10: {len(example_data)}')
example_data[0].show()
# here, the image is the image (PIL, or pillow) and the corresponding label. I've chopped the dataset to only include cats
# and dogs, so we can apply a different form of classification so
r = random.randint(1, len(DogCatDataset(TRAIN_DATA)))
# print(r)
example_data = DogCatDataset(TRAIN_DATA)[r]
print(f'items in an instance of the dataset: {len(example_data)}')
print(f'class corresponding to image: {example_data[1]}')
sample_img = torchvision.transforms.functional.to_pil_image(example_data[0])
sample_img = sample_img.resize((224,224))
sample_img.show()