-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_flow_from_dir.py
More file actions
67 lines (56 loc) · 2.38 KB
/
test_flow_from_dir.py
File metadata and controls
67 lines (56 loc) · 2.38 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#########################################################
# Imports
#########################################################
######################################
# Keras
######################################
import keras
from keras.models import Model
from keras.layers import Input, Conv2D, MaxPooling2D, Activation, Flatten, Dense
######################################
# Utils
######################################
from util.extendable_datagen import ImageDataGenerator, random_transform,standardize
import numpy as np
# Run parameters
batch_size = 32
epochs = 10
# Data specific constants
image_size = 128,128
num_classes = 5
#########################################################
# Network Architecture
#########################################################
inputs = Input((image_size[0], image_size[1], 3)) #RGB
x = Conv2D(6, kernel_size=(5,5), strides=(1, 1), padding='same')(inputs)
x = Activation('relu')(x)
x = MaxPooling2D()(x)
x = Conv2D(12, kernel_size=(3, 3), strides=(1, 1), padding='same')(x)
x = Activation('relu')(x)
x = MaxPooling2D()(x)
x = Conv2D(12, kernel_size=(3, 3), strides=(1, 1), padding='same')(x)
x = Activation('relu')(x)
x = MaxPooling2D()(x)
x = Conv2D(12, kernel_size=(3, 3), strides=(1, 1), padding='same')(x)
x = Activation('relu')(x)
x = MaxPooling2D()(x)
x = Flatten()(x)
x = Dense(num_classes, activation='relu')(x)
x = Activation('softmax')(x)
model = Model(inputs, x)
opt = optimizers.Adam()
model.compile(loss='categorical_crossentropy',
optimizer=opt, metrics=['acc'])
model.summary()
datagen = ImageDataGenerator()
datagen.set_pipeline([random_transform,standardize])
xt,yt=next(iter(datagen.flow_from_directory('./hdrvdp',batch_size=1000,target_size=(128,128),shuffle=True)))
print("GroundTruth: {}".format(model.evaluate(xt,yt,128)))
myDataGen = ImageDataGenerator()
for sshuffle in [False,True]:
flow_test = myDataGen.flow_from_directory('./hdrvdp',batch_size=32,target_size=(128,128),shuffle=sshuffle)
for multiProc in [False,True]:
for workers in [1,8]:
print('Evaluating datagen, shuffle={} , multiprocessing={}, workers={} - results {}'.format(sshuffle,
multiProc, workers,
model.evaluate_generator(flow_test,workers=workers,use_multiprocessing=multiProc)))