-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_numpy.py
More file actions
61 lines (51 loc) · 2.16 KB
/
test_numpy.py
File metadata and controls
61 lines (51 loc) · 2.16 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
#########################################################
# 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
#########################################################
# 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(1, activation='relu')(x)
x = Activation('sigmoid')(x)
model = Model(inputs, x)
model.compile(loss='binary_crossentropy',
optimizer='adam', metrics=['acc'])
xt,yt = np.random.uniform(size=(1000,128,128,3)) , np.random.randint(0,2,size=[1000,]).astype('float32')
print("GroundTruth: {}".format(model.evaluate(xt,yt,batch_size=32)))
myDataGen = ImageDataGenerator()
for sshuffle in [False,True]:
flow_test = myDataGen.flow(xt,yt,batch_size=32,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)))