-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataloader.py
50 lines (37 loc) · 1.7 KB
/
dataloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from cProfile import label
import tensorflow as tf
def load_MNIST(data_dir):
"""
Load MNIST dataset and data preprocessing.
:param data_dir: Path where to find the data file.
:return: Tuple of numpy arrays: (x_train, y_train), (x_test, y_test).
"""
# Initialize Data
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data(data_dir)
x_train = tf.image.resize(x_train, (64, 64))
y_train = tf.keras.utils.to_categorical(y_train, num_class=8)
x_test = tf.image.resize(x_test, (64, 64))
y_test = tf.keras.utils.to_categorical(y_test, num_class=8)
return (x_test, y_train), (x_test, y_test)
def load_CIFAR10(data_dir):
"""
Load CIFAR10 dataset and data preprocessing.
:param data_dir: Path where to find the data file.
:return: Tuple of numpy arrays: (x_train, y_train), (x_test, y_test).
"""
# Initialize Data
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar10.load_data(data_dir)
y_train = tf.keras.utils.to_categorical(y_train, num_class=10)
y_test = tf.keras.utils.tp_categorical(y_test, num_class=10)
return (x_train, y_train), (x_test, y_test)
def load_CIFAR100(data_dir):
"""
Load CIFAR100 dataset and data preprocessing.
:param data_dir: Path where to find the data file.
:return: Tuple of numpy arrays: (x_train, y_train), (x_test, y_test).
"""
# Initialize Data
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar100.load_data(data_dir, label_mode='fine')
y_train = tf.keras.utils.to_categorical(y_train, num_class=100)
y_test = tf.keras.utils.to_categorical(y_test, num_class=100)
return (x_train, y_train), (x_test, y_test)