-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreseau.py
113 lines (91 loc) · 4.64 KB
/
reseau.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d, avg_pool_2d
from tflearn.layers.estimator import regression
from tflearn.data_preprocessing import ImagePreprocessing
from tflearn.data_augmentation import ImageAugmentation
import tflearn
import settings
import loadData as ld
def getReseau():
size = settings.size
nb_filter = settings.nb_filter
filter_size = settings.filter_size
# Make sure the data is normalized
img_prep = ImagePreprocessing()
img_prep.add_featurewise_zero_center()
img_prep.add_featurewise_stdnorm()
# Create extra synthetic training data by flipping, rotating and blurring the
# images on our data set.
img_aug = ImageAugmentation()
img_aug.add_random_flip_leftright()
img_aug.add_random_rotation(max_angle=25.)
img_aug.add_random_blur(sigma_max=3.)
# Define our network architecture:
# Input is a 32x32 image with 3 color channels (red, green and blue)
network = input_data(shape=[None, size, size, 3],
data_preprocessing=img_prep,
data_augmentation=img_aug)
reseau = settings.reseau
if reseau == 1:
# Step 1: Convolution
network = conv_2d(network, nb_filter, filter_size, activation='relu')
# Step 2: Max pooling
network = max_pool_2d(network, 2)
# Step 3: Convolution again
network = conv_2d(network, nb_filter * 2, filter_size, activation='relu')
# Step 4: Convolution yet again
network = conv_2d(network, nb_filter * 2, filter_size, activation='relu')
# Step 5: Max pooling again
network = max_pool_2d(network, 2)
# Step 6: Fully-connected 512 node neural network
network = fully_connected(network, nb_filter * 8, activation='relu')
# Step 7: Dropout - throw away some data randomly during training to prevent over-fitting
network = dropout(network, 0.5)
elif reseau == 2:
network = conv_2d(network, 32, 3, activation='relu')
network = conv_2d(network, 32, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 32, 3, activation='relu')
network = conv_2d(network, 32, 3, activation='relu')
network = max_pool_2d(network, 2)
network = fully_connected(network, 512, activation='relu')
network = fully_connected(network, 512, activation='relu')
elif reseau == 3:
network = conv_2d(network, 32, 3, activation='relu')
network = avg_pool_2d(network, 2)
network = conv_2d(network, 32, 3, activation='relu')
network = avg_pool_2d(network, 2)
network = conv_2d(network, 32, 3, activation='relu')
network = avg_pool_2d(network, 2)
network = fully_connected(network, 512, activation='relu')
network = fully_connected(network, 512, activation='relu')
network = dropout(network, 0.5)
elif reseau == 4:
network = conv_2d(network, 32, 3, activation='relu')
network = conv_2d(network, 32, 3, activation='relu')
network = conv_2d(network, 32, 5, padding='valid', activation='relu')
network = conv_2d(network, 32, 3, activation='relu')
network = conv_2d(network, 32, 3, activation='relu')
network = conv_2d(network, 32, 5, padding='valid', activation='relu')
network = fully_connected(network, 512, activation='relu')
network = dropout(network, 0.5)
elif reseau == 5:
network = conv_2d(network, 64, 3, activation='relu')
network = conv_2d(network, 64, 3, activation='relu')
network = avg_pool_2d(network, 2)
network = conv_2d(network, 32, 3, activation='relu')
network = conv_2d(network, 32, 3, activation='relu')
network = max_pool_2d(network, 2)
network = fully_connected(network, 512, activation='relu')
network = fully_connected(network, 512, activation='relu')
# Step 8: Fully-connected neural network with three outputs (0=isn't a bird, 1=is a bird) to make the final prediction
network = fully_connected(network, ld.getLabelsNumber(), activation='softmax')
# Tell tflearn how we want to train the network
network = regression(network, optimizer='adam',
loss='categorical_crossentropy',
learning_rate=settings.learning_rate)
# Wrap the network in a model object
# model = tflearn.DNN(network, tensorboard_verbose=0, checkpoint_path='dataviz-classifier.tfl.ckpt')
model = tflearn.DNN(network,
tensorboard_verbose=0) # , checkpoint_path='data-classifier/dataviz-classifier.tfl.ckpt')
return model