-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDemo_AlexNet.py
More file actions
36 lines (21 loc) · 915 Bytes
/
Copy pathDemo_AlexNet.py
File metadata and controls
36 lines (21 loc) · 915 Bytes
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
from tensorflow import keras
from sklearn.model_selection import train_test_split
from DL import pre_data
from DL.alexnet import jho
import numpy as np
# load data
(xtrain, ytrain), (xtest, ytest) = keras.datasets.cifar10.load_data()
classes = np.unique(ytrain)
num_class = len(classes)
# I only use small amount of images for training and validation
x1, x2, y1, y2 = train_test_split(xtrain, ytrain, test_size=0.2, stratify=ytrain)
# small amount of validation set
xtrain, xvalid, ytrain, yvalid = train_test_split(x2, y2, test_size=0.1, stratify=y2)
del x1, x2, y1, y2
# prepare image data
batch_size = 64
train_ds, valid_ds, test_ds = pre_data.alexnet(xtrain, xvalid, xtest, ytrain, yvalid, ytest, batch_size)
# train & validate model
model, history = jho(train_ds, valid_ds, num_class)
# test model with unseen data
loss, acc = model.evaluate(test_ds)