added a way to show an example of stuff in the dataset
This commit is contained in:
parent
0567db2f07
commit
c72a00dc0d
2 changed files with 15 additions and 9 deletions
|
@ -4,7 +4,7 @@ import torchvision.transforms as transforms
|
||||||
CIFAR_DIR = Path('Data/CIFAR10')
|
CIFAR_DIR = Path('Data/CIFAR10')
|
||||||
CIFAR_DIR.mkdir(exist_ok = True)
|
CIFAR_DIR.mkdir(exist_ok = True)
|
||||||
|
|
||||||
|
#you can add more and bump the numbers even more up
|
||||||
normalize = transforms.Compose([
|
normalize = transforms.Compose([
|
||||||
transforms.ToTensor(),
|
transforms.ToTensor(),
|
||||||
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
|
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
|
||||||
|
|
22
dataset.py
22
dataset.py
|
@ -1,20 +1,26 @@
|
||||||
import torchvision
|
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:
|
#optional transformations:
|
||||||
# https://pytorch.org/vision/0.11/transforms.html
|
# https://pytorch.org/vision/0.11/transforms.html
|
||||||
|
|
||||||
#training data using torchvision cifar.
|
#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.
|
#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
|
# 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 it's easier to perform
|
# and dogs, so we can apply a different form of classification so
|
||||||
example_data = cifar_data_train[0]
|
r = random.randint(1, len(DogCatDataset(TRAIN_DATA)))
|
||||||
print(f'items in an instance of cifar10: {len(example_data)}')
|
# print(r)
|
||||||
example_data[0].show()
|
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]}')
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue