Commit
·
e384564
1
Parent(s):
565cebb
Update eda.py
Browse files
eda.py
CHANGED
@@ -33,17 +33,48 @@ def run():
|
|
33 |
|
34 |
|
35 |
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
batch_size = 256
|
38 |
img_size = (64, 64)
|
39 |
-
# Define paths to the data folders
|
40 |
-
dataset_path = 'andrewsunanda/fast_food_image_classification'
|
41 |
|
42 |
-
|
43 |
# Define the paths to the train, validation, and test folders
|
44 |
train_path = os.path.join(dataset_path, 'Train')
|
45 |
valid_path = os.path.join(dataset_path, 'Valid')
|
46 |
test_path = os.path.join(dataset_path, 'Test')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
# Create data generators for training, validation, and testing
|
48 |
train_datagen = ImageDataGenerator(
|
49 |
rescale=1./255,
|
|
|
33 |
|
34 |
|
35 |
|
36 |
+
import os
|
37 |
+
import torch
|
38 |
+
import torchvision.transforms as transforms
|
39 |
+
from torch.utils.data import DataLoader
|
40 |
+
from datasets import load_dataset
|
41 |
+
|
42 |
+
# Define the path to the dataset
|
43 |
+
dataset_path = 'andrewsunanda/fast_food_image_classification'
|
44 |
+
|
45 |
+
# Load the dataset from Hugging Face
|
46 |
+
dataset = load_dataset(dataset_path)
|
47 |
+
|
48 |
+
# Define the batch size and image size
|
49 |
batch_size = 256
|
50 |
img_size = (64, 64)
|
|
|
|
|
51 |
|
|
|
52 |
# Define the paths to the train, validation, and test folders
|
53 |
train_path = os.path.join(dataset_path, 'Train')
|
54 |
valid_path = os.path.join(dataset_path, 'Valid')
|
55 |
test_path = os.path.join(dataset_path, 'Test')
|
56 |
+
|
57 |
+
# Define the transforms for the dataset
|
58 |
+
transform = transforms.Compose([
|
59 |
+
transforms.Resize(img_size),
|
60 |
+
transforms.ToTensor(),
|
61 |
+
])
|
62 |
+
|
63 |
+
# Load the training dataset
|
64 |
+
train_dataset = dataset['train']
|
65 |
+
train_dataset = train_dataset.map(lambda x: {'image': transform(x['image']), 'label': x['label']})
|
66 |
+
train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True)
|
67 |
+
|
68 |
+
# Load the validation dataset
|
69 |
+
valid_dataset = dataset['validation']
|
70 |
+
valid_dataset = valid_dataset.map(lambda x: {'image': transform(x['image']), 'label': x['label']})
|
71 |
+
valid_loader = DataLoader(valid_dataset, batch_size=batch_size, shuffle=False)
|
72 |
+
|
73 |
+
# Load the testing dataset
|
74 |
+
test_dataset = dataset['test']
|
75 |
+
test_dataset = test_dataset.map(lambda x: {'image': transform(x['image']), 'label': x['label']})
|
76 |
+
test_loader = DataLoader(test_dataset, batch_size=batch_size, shuffle=False)
|
77 |
+
|
78 |
# Create data generators for training, validation, and testing
|
79 |
train_datagen = ImageDataGenerator(
|
80 |
rescale=1./255,
|