51
51
BS = 600 # batch size
52
52
validation_split = 0.01
53
53
batch_per_epoch = np .ceil (len (df ['image' ]) / BS ).astype (int )
54
- epochs = 100
54
+ epochs = 40
55
55
alpha = 0.01
56
- lr = 0.000001
56
+ lr = 0.00001
57
57
mom = 0.000002
58
+ optimizer = 'SGD'
58
59
59
60
# ########################################################
60
61
# Create training data labels and target
@@ -67,7 +68,7 @@ def training_gen():
67
68
try :
68
69
if len (training_data ) != BS :
69
70
70
- image = cv2 .imread (f"small_training_images /{ img } .png" , 1 )
71
+ image = cv2 .imread (f"smaller_training_images /{ img } .png" , 1 )
71
72
#image = cv2.resize(image, (400,400))
72
73
image = cv2 .cvtColor (image , cv2 .COLOR_BGR2RGB )
73
74
@@ -77,12 +78,12 @@ def training_gen():
77
78
78
79
else :
79
80
X = [image for image , angle , normal_v in training_data ]
80
- other_inp = [image for image , angle , normal_v in training_data ]
81
- Y = [image for image , angle , normal_v in training_data ]
81
+ other_inp = [normal_v for image , angle , normal_v in training_data ]
82
+ Y = [angle for image , angle , normal_v in training_data ]
82
83
83
84
training_data = []
84
85
85
- X = np .array (image ). reshape (- 1 , 400 , 400 ,3 )
86
+ X = ( np .array (image )/ 255. ). reshape (- 1 , 300 , 250 ,3 )
86
87
Y = np .array ([angle ])
87
88
other_inp = np .array ([velocity ])
88
89
@@ -95,7 +96,7 @@ def training_gen():
95
96
# ########################################################
96
97
# Create test data labels and target
97
98
test_data = []
98
- _iterator_obj = list (zip (df ['image' ], df ['steering_angle' ], df ['outcome' ], test_df ['normal_velocity' ]))
99
+ _iterator_obj = list (zip (df ['image' ], df ['steering_angle' ], df ['outcome' ], df ['normal_velocity' ]))
99
100
random .shuffle (_iterator_obj )
100
101
101
102
for img , angle , outcome , velocity in _iterator_obj :
@@ -104,7 +105,7 @@ def training_gen():
104
105
if len (test_data ) == int (len (df ['image' ]) * validation_split ):
105
106
break
106
107
107
- test_image = cv2 .imread (f"small_training_images /{ img } .png" , 1 )
108
+ test_image = cv2 .imread (f"smaller_training_images /{ img } .png" , 1 )
108
109
#test_image = cv2.resize(test_image, (400,400))
109
110
test_image = cv2 .cvtColor (test_image , cv2 .COLOR_BGR2RGB )
110
111
@@ -120,7 +121,7 @@ def training_gen():
120
121
test_Y = [label for img , label , velocity in test_data ]
121
122
test_other_inp = [velocity for img , label , velocity in test_data ]
122
123
123
- test_X = np .array (test_X ).reshape (- 1 , 400 , 400 ,3 )
124
+ test_X = np .array (test_X ).reshape (- 1 , 300 , 250 ,3 )
124
125
test_Y = np .array (test_Y )
125
126
test_other_inp = np .array (test_other_inp )
126
127
print (test_other_inp .shape )
@@ -129,31 +130,30 @@ def training_gen():
129
130
# Create Model
130
131
def create_model ():
131
132
# model = Sequential()
132
- input1 = Input (shape = (400 , 400 ,3 ))
133
+ input1 = Input (shape = (300 , 250 ,3 ))
133
134
134
135
# model.add(Flatten(input_shape = (940,940,3)))
135
- conv1 = Conv2D (36 , (3 , 3 ), strides = (2 , 2 ))(input1 )
136
- #conv1 = model.add(Conv2D(20, (5, 5), strides=(2, 2), input_shape = (940,940,3)))
136
+ conv1 = Conv2D (36 , (3 , 3 ), strides = (2 , 2 ), padding = 'same' )(input1 )
137
137
activ1 = LeakyReLU (alpha = alpha )(conv1 )
138
- pool1 = MaxPooling2D (pool_size = (2 , 2 ))(activ1 )
138
+ pool1 = MaxPooling2D (pool_size = (2 , 2 ), padding = 'valid' )(activ1 )
139
139
140
- conv2 = Conv2D (25 , (3 , 3 ), strides = (2 , 2 ))(pool1 )
140
+ conv2 = Conv2D (25 , (3 , 3 ), strides = (2 , 2 ), padding = 'same' )(pool1 )
141
141
activ2 = LeakyReLU (alpha = alpha )(conv2 )
142
- pool2 = MaxPooling2D (pool_size = (2 , 2 ))(activ2 )
142
+ pool2 = MaxPooling2D (pool_size = (2 , 2 ), padding = 'valid' )(activ2 )
143
143
144
- conv3 = Conv2D (16 , (3 , 3 ), strides = (2 , 2 ))(pool2 )
144
+ conv3 = Conv2D (16 , (3 , 3 ), strides = (2 , 2 ), padding = 'same' )(pool2 )
145
145
activ3 = LeakyReLU (alpha = alpha )(conv3 )
146
- pool3 = MaxPooling2D (pool_size = (2 , 2 ))(activ3 )
146
+ pool3 = MaxPooling2D (pool_size = (2 , 2 ), padding = 'valid' )(activ3 )
147
147
148
- conv4 = Conv2D (9 , (3 , 3 ), strides = 1 )(pool3 )
149
- activ4 = LeakyReLU (alpha = alpha )(conv4 )
150
- pool4 = MaxPooling2D (pool_size = (1 , 1 ))(activ4 )
148
+ # conv4 = Conv2D(9, (3, 3), strides=(1, 1), padding='valid' )(pool3)
149
+ # activ4 = LeakyReLU(alpha=alpha)(conv4)
150
+ # pool4 = MaxPooling2D(pool_size=(1, 1), padding='valid' )(activ4)
151
151
152
- conv5 = Conv2D (4 , (3 , 3 ), strides = 1 )( pool4 )
153
- activ5 = LeakyReLU (alpha = alpha )(conv5 )
154
- pool5 = MaxPooling2D (pool_size = (1 , 1 ))(activ5 )
152
+ # conv5 = Conv2D(4, (3, 3), strides=(1, 1), padding='valid')(activ4 )
153
+ # activ5 = LeakyReLU(alpha=alpha)(conv5)
154
+ # pool5 = MaxPooling2D(pool_size=(1, 1))(activ5)
155
155
156
- flat1 = Flatten ()(pool5 )
156
+ flat1 = Flatten ()(pool3 )
157
157
158
158
input2 = Input (shape = (1 , ))
159
159
concat1 = Concatenate (axis = 1 )([flat1 , input2 ])
@@ -167,7 +167,7 @@ def create_model():
167
167
model = Model (inputs = [input1 , input2 ], outputs = dense4 )
168
168
169
169
model .compile (loss = 'mean_squared_error' ,
170
- metrics = ['accuracy' , 'mae' , 'mse' ], optimizer = 'sgd' )
170
+ metrics = ['accuracy' , 'mae' , 'mse' ], optimizer = optimizer )
171
171
172
172
optimizers .SGD (lr = lr , momentum = mom )
173
173
#optimizers.RMSprop(lr=lr)
@@ -205,4 +205,8 @@ def create_model():
205
205
206
206
207
207
loss_graph = plt .plot (loss )
208
+ plt .title (f'MSE of { round (float (loss [- 1 ]), 6 )} over { epochs } epochs with { optimizer } optimizer \n and 3 hidden conv layers' )
208
209
plt .show ()
210
+
211
+ with open (f'results/{ optimizer } _3.txt' , 'a' ) as f :
212
+ print (loss , file = f )
0 commit comments