-
Notifications
You must be signed in to change notification settings - Fork 0
/
Traffic_Sign_Classifier.py
1239 lines (909 loc) · 47.5 KB
/
Traffic_Sign_Classifier.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# coding: utf-8
# # Self-Driving Car Engineer Nanodegree
#
# ## Deep Learning
#
# ## Project: Build a Traffic Sign Recognition Classifier
#
# In this notebook, a template is provided for you to implement your functionality in stages, which is required to successfully complete this project. If additional code is required that cannot be included in the notebook, be sure that the Python code is successfully imported and included in your submission if necessary.
#
# > **Note**: Once you have completed all of the code implementations, you need to finalize your work by exporting the iPython Notebook as an HTML document. Before exporting the notebook to html, all of the code cells need to have been run so that reviewers can see the final implementation and output. You can then export the notebook by using the menu above and navigating to \n",
# "**File -> Download as -> HTML (.html)**. Include the finished document along with this notebook as your submission.
#
# In addition to implementing code, there is a writeup to complete. The writeup should be completed in a separate file, which can be either a markdown file or a pdf document. There is a [write up template](https://github.com/udacity/CarND-Traffic-Sign-Classifier-Project/blob/master/writeup_template.md) that can be used to guide the writing process. Completing the code template and writeup template will cover all of the [rubric points](https://review.udacity.com/#!/rubrics/481/view) for this project.
#
# The [rubric](https://review.udacity.com/#!/rubrics/481/view) contains "Stand Out Suggestions" for enhancing the project beyond the minimum requirements. The stand out suggestions are optional. If you decide to pursue the "stand out suggestions", you can include the code in this Ipython notebook and also discuss the results in the writeup file.
#
#
# >**Note:** Code and Markdown cells can be executed using the **Shift + Enter** keyboard shortcut. In addition, Markdown cells can be edited by typically double-clicking the cell to enter edit mode.
# ---
# ## Step 0: Load The Data
# In[ ]:
# Load pickled data
import pickle
# TODO: Fill this in based on where you saved the training and testing data
training_file = "../data/traffic-signs-data/train.p"
validation_file = "../data/traffic-signs-data/valid.p"
testing_file = "../data/traffic-signs-data/test.p"
### Preprocessed file
training_pp_file = "../data/traffic-signs-data/train_pp.p"
### Preprocessed balanced file
training_pp_bal_file = "../data/traffic-signs-data/train_pp_bal.p"
def read_data_file(filename):
with open(filename, mode='rb') as f:
data = pickle.load(f)
return data['features'], data['labels']
#with open(training_file, mode='rb') as f:
# train = pickle.load(f)
#with open(validation_file, mode='rb') as f:
# valid = pickle.load(f)
#with open(testing_file, mode='rb') as f:
# test = pickle.load(f)
#X_train, y_train = train['features'], train['labels']
#X_valid, y_valid = valid['features'], valid['labels']
#X_test, y_test = test['features'], test['labels']
# ---
#
# ## Step 1: Dataset Summary & Exploration
#
# The pickled data is a dictionary with 4 key/value pairs:
#
# - `'features'` is a 4D array containing raw pixel data of the traffic sign images, (num examples, width, height, channels).
# - `'labels'` is a 1D array containing the label/class id of the traffic sign. The file `signnames.csv` contains id -> name mappings for each id.
# - `'sizes'` is a list containing tuples, (width, height) representing the the original width and height the image.
# - `'coords'` is a list containing tuples, (x1, y1, x2, y2) representing coordinates of a bounding box around the sign in the image. **THESE COORDINATES ASSUME THE ORIGINAL IMAGE. THE PICKLED DATA CONTAINS RESIZED VERSIONS (32 by 32) OF THESE IMAGES**
#
# Complete the basic data summary below. Use python, numpy and/or pandas methods to calculate the data summary rather than hard coding the results. For example, the [pandas shape method](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.shape.html) might be useful for calculating some of the summary results.
# ### Provide a Basic Summary of the Data Set Using Python, Numpy and/or Pandas
# In[ ]:
### Replace each question mark with the appropriate value.
### Use python, pandas or numpy methods rather than hard coding the results
## TODO: Number of training examples
#n_train = len(y_train)
#
## TODO: Number of testing examples.
#n_test = len(y_test)
#
## TODO: What's the shape of an traffic sign image?
#image_shape = X_train[0].shape
#
## TODO: How many unique classes/labels there are in the dataset.
#n_classes = len(set(y_train))
#
#print("Number of training examples =", n_train)
#print("Number of testing examples =", n_test)
#print("Image data shape =", image_shape)
#print("Number of classes =", n_classes)
# ### Include an exploratory visualization of the dataset
# Visualize the German Traffic Signs Dataset using the pickled file(s). This is open ended, suggestions include: plotting traffic sign images, plotting the count of each sign, etc.
#
# The [Matplotlib](http://matplotlib.org/) [examples](http://matplotlib.org/examples/index.html) and [gallery](http://matplotlib.org/gallery.html) pages are a great resource for doing visualizations in Python.
#
# **NOTE:** It's recommended you start with something simple first. If you wish to do more, come back to it after you've completed the rest of the sections.
# In[16]:
### Data exploration visualization code goes here.
### Feel free to use as many code cells as needed.
# Visualizations will be shown in the notebook.
# ----
#
# ## Step 2: Design and Test a Model Architecture
#
# Design and implement a deep learning model that learns to recognize traffic signs. Train and test your model on the [German Traffic Sign Dataset](http://benchmark.ini.rub.de/?section=gtsrb&subsection=dataset).
#
# There are various aspects to consider when thinking about this problem:
#
# - Neural network architecture
# - Play around preprocessing techniques (normalization, rgb to grayscale, etc)
# - Number of examples per label (some have more than others).
# - Generate fake data.
#
# Here is an example of a [published baseline model on this problem](http://yann.lecun.com/exdb/publis/pdf/sermanet-ijcnn-11.pdf). It's not required to be familiar with the approach used in the paper but, it's good practice to try to read papers like these.
#
# **NOTE:** The LeNet-5 implementation shown in the [classroom](https://classroom.udacity.com/nanodegrees/nd013/parts/fbf77062-5703-404e-b60c-95b78b2f3f9e/modules/6df7ae49-c61c-4bb2-a23e-6527e69209ec/lessons/601ae704-1035-4287-8b11-e2c2716217ad/concepts/d4aca031-508f-4e0b-b493-e7b706120f81) at the end of the CNN lesson is a solid starting point. You'll have to change the number of classes and possibly the preprocessing, but aside from that it's plug and play!
# ### Pre-process the Data Set (normalization, grayscale, etc.)
# Use the code cell (or multiple code cells, if necessary) to implement the first step of your project.
### TO TRY:
### 1) YUV
### 2) Grayscale
import cv2
import numpy as np
def YUV_center(imgs):
return np.array([cv2.cvtColor(i, cv2.COLOR_RGB2YUV) / 255 - 0.5 for i in imgs])
def YUV(imgs):
return np.array([cv2.cvtColor(i, cv2.COLOR_RGB2YUV) / 255 for i in imgs])
def equalizeHist(imgs):
### Contrast Limited Adaptive Histogram Equalization
### http://docs.opencv.org/3.1.0/d5/daf/tutorial_py_histogram_equalization.html
img_shape = imgs[0][:, :, 0].shape
yuvs = [cv2.cvtColor(i, cv2.COLOR_RGB2YUV) for i in imgs]
return np.array([np.dstack((cv2.equalizeHist(i[:, :, 0]) / 255, np.zeros(img_shape), np.zeros(img_shape))) for i in yuvs])
def CLAHE(imgs):
### Contrast Limited Adaptive Histogram Equalization
### http://docs.opencv.org/3.1.0/d5/daf/tutorial_py_histogram_equalization.html
img_shape = imgs[0][:, :, 0].shape
clahe = cv2.createCLAHE(tileGridSize=(4, 4))
yuvs = [cv2.cvtColor(i, cv2.COLOR_RGB2YUV) for i in imgs]
return np.array([np.dstack((clahe.apply(i[:, :, 0]) / 255, np.zeros(img_shape), np.zeros(img_shape))) for i in yuvs])
# In[4]:
### Preprocess the data here. Preprocessing steps could include normalization, converting to grayscale, etc.
### Feel free to use as many code cells as needed.
# ### Model Architecture
# In[ ]:
### Define your architecture here.
### Feel free to use as many code cells as needed.
### TO TRY:
### 1) sermanet architecture
### 2) Replace pooling with dropout
import tensorflow as tf
# Arguments used for tf.truncated_normal, randomly defines variables for the weights and biases for each layer
mu = 0
sigma = 0.1
# Activation function to use
activation = tf.nn.relu
def linear(x, W, b):
return tf.add(tf.matmul(x, W), b)
def conv2d(x, W, b, strides=1, padding='VALID'):
x = tf.nn.conv2d(x, W, strides=[1, strides, strides, 1], padding=padding)
return tf.nn.bias_add(x, b)
def dropout(x, keep_prob):
return tf.nn.dropout(x, keep_prob)
def maxpool2d(x, k=2, s=2):
return tf.nn.max_pool(
x,
ksize=[1, k, k, 1],
strides=[1, s, s, 1],
padding='SAME')
def gen_keep_prob():
return tf.placeholder(tf.float32, name="keep_prob")
def LeNet(x):
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2' : tf.Variable(tf.truncated_normal(shape=(5, 5, 6, 16), mean = mu, stddev = sigma)),
'flat3' : tf.Variable(tf.truncated_normal(shape=(400, 120), mean = mu, stddev = sigma)),
'flat4' : tf.Variable(tf.truncated_normal(shape=(120, 84), mean = mu, stddev = sigma)),
'flat5' : tf.Variable(tf.truncated_normal(shape=(84, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2' : tf.Variable(tf.zeros(16)),
'flat3' : tf.Variable(tf.zeros(120)),
'flat4' : tf.Variable(tf.zeros(84)),
'flat5' : tf.Variable(tf.zeros(43))
}
# Layer 1: Convolutional. Input = 32x32x3. Output = 28x28x6.
conv1 = conv2d(x, weights['conv1'], biases['conv1'])
# Activation
conv1 = activation(conv1)
# Pooling. Input = 28x28x6. Output = 14x14x6.
conv1 = maxpool2d(conv1, 2)
# Layer 2: Convolutional. Output = 10x10x16.
conv2 = conv2d(conv1, weights['conv2'], biases['conv2'])
# Activation.
conv2 = activation(conv2)
# Pooling. Input = 10x10x16. Output = 5x5x16.
conv2 = maxpool2d(conv2, 2)
# Flatten. Input = 5x5x16. Output = 400.
flat3 = tf.reshape(conv2, [-1, weights['flat3'].get_shape().as_list()[0]])
# Layer 3: Fully Connected. Input = 400. Output = 120.
flat3 = linear(flat3, weights['flat3'], biases['flat3'])
# Activation.
flat3 = activation(flat3)
# Layer 4: Fully Connected. Input = 120. Output = 84.
flat4 = linear(flat3, weights['flat4'], biases['flat4'])
# Activation.
flat4 = activation(flat4)
# Layer 5: Fully Connected. Input = 84. Output = 43.
logits = linear(flat4, weights['flat5'], biases['flat5'])
return logits
def LeNet3(x):
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2' : tf.Variable(tf.truncated_normal(shape=(3, 3, 6, 16), mean = mu, stddev = sigma)),
'conv3' : tf.Variable(tf.truncated_normal(shape=(3, 3, 16, 32), mean = mu, stddev = sigma)),
'flat4' : tf.Variable(tf.truncated_normal(shape=(800, 200), mean = mu, stddev = sigma)),
'flat5' : tf.Variable(tf.truncated_normal(shape=(200, 84), mean = mu, stddev = sigma)),
'flat6' : tf.Variable(tf.truncated_normal(shape=(84, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2' : tf.Variable(tf.zeros(16)),
'conv3' : tf.Variable(tf.zeros(32)),
'flat4' : tf.Variable(tf.zeros(200)),
'flat5' : tf.Variable(tf.zeros(84)),
'flat6' : tf.Variable(tf.zeros(43))
}
# Layer 1: Convolutional. Input = 32x32x3. Output = 28x28x6.
conv1 = conv2d(x, weights['conv1'], biases['conv1'])
# Activation
conv1 = activation(conv1)
# Pooling. Input = 28x28x6. Output = 14x14x6.
conv1 = maxpool2d(conv1, 2)
# Layer 2: Convolutional. Output = 12x12x16.
conv2 = conv2d(conv1, weights['conv2'], biases['conv2'])
# Activation.
conv2 = activation(conv2)
# Layer 3: Convolutional. Output = 10x10x32.
conv3 = conv2d(conv2, weights['conv3'], biases['conv3'])
# Activation.
conv3 = activation(conv3)
# Pooling. Input = 10x10x32. Output = 5x5x32.
conv3 = maxpool2d(conv3, 2)
# Flatten. Input = 5x5x32. Output = 800.
flat4 = tf.reshape(conv3, [-1, weights['flat4'].get_shape().as_list()[0]])
# Layer 4: Fully Connected. Input = 800. Output = 200.
flat4 = linear(flat4, weights['flat4'], biases['flat4'])
# Activation.
flat4 = activation(flat4)
# Layer 5: Fully Connected. Input = 200. Output = 84.
flat5 = linear(flat4, weights['flat5'], biases['flat5'])
# Activation.
flat5 = activation(flat5)
# Layer 6: Fully Connected. Input = 84. Output = 43.
logits = linear(flat5, weights['flat6'], biases['flat6'])
return logits
def LeNet3_dropout_fc(x, keep_prob):
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2' : tf.Variable(tf.truncated_normal(shape=(3, 3, 6, 16), mean = mu, stddev = sigma)),
'conv3' : tf.Variable(tf.truncated_normal(shape=(3, 3, 16, 32), mean = mu, stddev = sigma)),
'flat4' : tf.Variable(tf.truncated_normal(shape=(800, 200), mean = mu, stddev = sigma)),
'flat5' : tf.Variable(tf.truncated_normal(shape=(200, 84), mean = mu, stddev = sigma)),
'flat6' : tf.Variable(tf.truncated_normal(shape=(84, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2' : tf.Variable(tf.zeros(16)),
'conv3' : tf.Variable(tf.zeros(32)),
'flat4' : tf.Variable(tf.zeros(200)),
'flat5' : tf.Variable(tf.zeros(84)),
'flat6' : tf.Variable(tf.zeros(43))
}
# Layer 1: Convolutional. Input = 32x32x3. Output = 28x28x6.
conv1 = conv2d(x, weights['conv1'], biases['conv1'])
# Activation
conv1 = activation(conv1)
# Pooling. Input = 28x28x6. Output = 14x14x6.
conv1 = maxpool2d(conv1, 2)
# Layer 2: Convolutional. Output = 12x12x16.
conv2 = conv2d(conv1, weights['conv2'], biases['conv2'])
# Activation.
conv2 = activation(conv2)
# Layer 3: Convolutional. Output = 10x10x32.
conv3 = conv2d(conv2, weights['conv3'], biases['conv3'])
# Activation.
conv3 = activation(conv3)
# Pooling. Input = 10x10x32. Output = 5x5x32.
conv3 = maxpool2d(conv3, 2)
# Flatten. Input = 5x5x32. Output = 800.
flat4 = tf.reshape(conv3, [-1, weights['flat4'].get_shape().as_list()[0]])
# Layer 4: Fully Connected. Input = 800. Output = 200.
flat4 = linear(flat4, weights['flat4'], biases['flat4'])
# Activation.
flat4 = activation(flat4)
# Dropout
flat4 = dropout(flat4, keep_prob)
# Layer 5: Fully Connected. Input = 200. Output = 84.
flat5 = linear(flat4, weights['flat5'], biases['flat5'])
# Activation.
flat5 = activation(flat5)
# Dropout
flat5 = dropout(flat5, keep_prob)
# Layer 6: Fully Connected. Input = 84. Output = 43.
logits = linear(flat5, weights['flat6'], biases['flat6'])
return logits
def LeNet_dropout(x, keep_prob):
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2' : tf.Variable(tf.truncated_normal(shape=(9, 9, 6, 16), mean = mu, stddev = sigma)),
'flat3' : tf.Variable(tf.truncated_normal(shape=(1600, 400), mean = mu, stddev = sigma)),
'flat4' : tf.Variable(tf.truncated_normal(shape=(400, 120), mean = mu, stddev = sigma)),
'flat5' : tf.Variable(tf.truncated_normal(shape=(120, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2' : tf.Variable(tf.zeros(16)),
'flat3' : tf.Variable(tf.zeros(400)),
'flat4' : tf.Variable(tf.zeros(120)),
'flat5' : tf.Variable(tf.zeros(43))
}
# Layer 1: Convolutional. Input = 32x32x3. Output = 28x28x6.
conv1 = conv2d(x, weights['conv1'], biases['conv1'])
# Activation
conv1 = activation(conv1)
# Dropout
conv1 = dropout(conv1, keep_prob)
# Layer 2: Convolutional. Input = 28x28x6. Output = 10x10x16.
conv2 = conv2d(conv1, weights['conv2'], biases['conv2'], strides=2)
# Activation.
conv2 = activation(conv2)
# Dropout
conv2 = dropout(conv2, keep_prob)
# Flatten. Input = 10x10x16. Output = 1600.
flat3 = tf.reshape(conv2, [-1, weights['flat3'].get_shape().as_list()[0]])
# Layer 3: Fully Connected. Input = 1600. Output = 400.
flat3 = linear(flat3, weights['flat3'], biases['flat3'])
# Activation.
flat3 = activation(flat3)
# Layer 4: Fully Connected. Input = 400. Output = 120.
flat4 = linear(flat3, weights['flat4'], biases['flat4'])
# Activation.
flat4 = activation(flat4)
# Layer 5: Fully Connected. Input = 120. Output = 43.
logits = linear(flat4, weights['flat5'], biases['flat5'])
return logits
def Multi_Scale_LeNet(x):
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2' : tf.Variable(tf.truncated_normal(shape=(5, 5, 6, 16), mean = mu, stddev = sigma)),
'flat3' : tf.Variable(tf.truncated_normal(shape=(1576, 400), mean = mu, stddev = sigma)),
'flat4' : tf.Variable(tf.truncated_normal(shape=(400, 100), mean = mu, stddev = sigma)),
'flat5' : tf.Variable(tf.truncated_normal(shape=(100, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2' : tf.Variable(tf.zeros(16)),
'flat3' : tf.Variable(tf.zeros(400)),
'flat4' : tf.Variable(tf.zeros(100)),
'flat5' : tf.Variable(tf.zeros(43))
}
# Layer 1: Convolutional. Input = 32x32x3. Output = 28x28x6.
conv1 = conv2d(x, weights['conv1'], biases['conv1'])
# Activation
conv1 = activation(conv1)
# Pooling. Input = 28x28x6. Output = 14x14x6.
conv1 = maxpool2d(conv1, 2)
# Layer 2: Convolutional. Output = 10x10x16.
conv2 = conv2d(conv1, weights['conv2'], biases['conv2'])
# Activation.
conv2 = activation(conv2)
# Pooling. Input = 10x10x16. Output = 5x5x16.
conv2 = maxpool2d(conv2, 2)
# Flatten. Input = 14x14x6 + 5x5x16. Output = 1576.
flat_conv1 = tf.reshape(conv1, [-1, 14*14*6])
flat_conv2 = tf.reshape(conv2, [-1, 5*5*16])
flat3 = tf.concat(1, [flat_conv1, flat_conv2])
# Layer 3: Fully Connected. Input = 1576. Output = 400.
flat3 = linear(flat3, weights['flat3'], biases['flat3'])
# Activation.
flat3 = activation(flat3)
# Layer 4: Fully Connected. Input = 400. Output = 100.
flat4 = linear(flat3, weights['flat4'], biases['flat4'])
# Activation.
flat4 = activation(flat4)
# Layer 5: Fully Connected. Input = 100. Output = 43.
logits = linear(flat4, weights['flat5'], biases['flat5'])
return logits
def Multi_Scale_LeNet_pooling_dropout(x, keep_prob):
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2' : tf.Variable(tf.truncated_normal(shape=(5, 5, 6, 16), mean = mu, stddev = sigma)),
'flat3' : tf.Variable(tf.truncated_normal(shape=(1576, 400), mean = mu, stddev = sigma)),
'flat4' : tf.Variable(tf.truncated_normal(shape=(400, 100), mean = mu, stddev = sigma)),
'flat5' : tf.Variable(tf.truncated_normal(shape=(100, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2' : tf.Variable(tf.zeros(16)),
'flat3' : tf.Variable(tf.zeros(400)),
'flat4' : tf.Variable(tf.zeros(100)),
'flat5' : tf.Variable(tf.zeros(43))
}
# Layer 1: Convolutional. Input = 32x32x3. Output = 28x28x6.
conv1 = conv2d(x, weights['conv1'], biases['conv1'])
# Activation
conv1 = activation(conv1)
# Pooling. Input = 28x28x6. Output = 14x14x6.
conv1 = maxpool2d(conv1, 2)
# Dropout
conv1 = dropout(conv1, keep_prob)
# Layer 2: Convolutional. Output = 10x10x16.
conv2 = conv2d(conv1, weights['conv2'], biases['conv2'])
# Activation.
conv2 = activation(conv2)
# Pooling. Input = 10x10x16. Output = 5x5x16.
conv2 = maxpool2d(conv2, 2)
# Dropout
conv2 = dropout(conv2, keep_prob)
# Flatten. Input = 14x14x6 + 5x5x16. Output = 1576.
flat_conv1 = tf.reshape(conv1, [-1, 14*14*6])
flat_conv2 = tf.reshape(conv2, [-1, 5*5*16])
flat3 = tf.concat(1, [flat_conv1, flat_conv2])
# Layer 3: Fully Connected. Input = 1576. Output = 400.
flat3 = linear(flat3, weights['flat3'], biases['flat3'])
# Activation.
flat3 = activation(flat3)
# Dropout
flat3 = dropout(flat3, keep_prob)
# Layer 4: Fully Connected. Input = 400. Output = 100.
flat4 = linear(flat3, weights['flat4'], biases['flat4'])
# Activation.
flat4 = activation(flat4)
# Dropout
flat4 = dropout(flat4, keep_prob)
# Layer 5: Fully Connected. Input = 100. Output = 43.
logits = linear(flat4, weights['flat5'], biases['flat5'])
return logits
def Multi_Scale_LeNet_pooling_dropout_fc(x, keep_prob):
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2' : tf.Variable(tf.truncated_normal(shape=(5, 5, 6, 16), mean = mu, stddev = sigma)),
'flat3' : tf.Variable(tf.truncated_normal(shape=(1576, 400), mean = mu, stddev = sigma)),
'flat4' : tf.Variable(tf.truncated_normal(shape=(400, 100), mean = mu, stddev = sigma)),
'flat5' : tf.Variable(tf.truncated_normal(shape=(100, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2' : tf.Variable(tf.zeros(16)),
'flat3' : tf.Variable(tf.zeros(400)),
'flat4' : tf.Variable(tf.zeros(100)),
'flat5' : tf.Variable(tf.zeros(43))
}
# Layer 1: Convolutional. Input = 32x32x3. Output = 28x28x6.
conv1 = conv2d(x, weights['conv1'], biases['conv1'])
# Activation
conv1 = activation(conv1)
# Pooling. Input = 28x28x6. Output = 14x14x6.
conv1 = maxpool2d(conv1, 2)
# Layer 2: Convolutional. Output = 10x10x16.
conv2 = conv2d(conv1, weights['conv2'], biases['conv2'])
# Activation.
conv2 = activation(conv2)
# Pooling. Input = 10x10x16. Output = 5x5x16.
conv2 = maxpool2d(conv2, 2)
# Flatten. Input = 14x14x6 + 5x5x16. Output = 1576.
flat_conv1 = tf.reshape(conv1, [-1, 14*14*6])
flat_conv2 = tf.reshape(conv2, [-1, 5*5*16])
flat3 = tf.concat(1, [flat_conv1, flat_conv2])
# Layer 3: Fully Connected. Input = 1576. Output = 400.
flat3 = linear(flat3, weights['flat3'], biases['flat3'])
# Activation.
flat3 = activation(flat3)
# Dropout
flat3 = dropout(flat3, keep_prob)
# Layer 4: Fully Connected. Input = 400. Output = 100.
flat4 = linear(flat3, weights['flat4'], biases['flat4'])
# Activation.
flat4 = activation(flat4)
# Dropout
flat4 = dropout(flat4, keep_prob)
# Layer 5: Fully Connected. Input = 100. Output = 43.
logits = linear(flat4, weights['flat5'], biases['flat5'])
return logits
def Inception_dropout_fc(x, keep_prob):
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2_a_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 6, 8), mean = mu, stddev = sigma)),
'conv2_b_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 6, 8), mean = mu, stddev = sigma)),
'conv2_b_3_3' : tf.Variable(tf.truncated_normal(shape=(3, 3, 8, 32), mean = mu, stddev = sigma)),
'conv2_c_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 6, 8), mean = mu, stddev = sigma)),
'conv2_c_5_5' : tf.Variable(tf.truncated_normal(shape=(5, 5, 8, 16), mean = mu, stddev = sigma)),
'conv2_d_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 6, 8), mean = mu, stddev = sigma)),
'conv3_a_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 64, 80), mean = mu, stddev = sigma)),
'conv3_b_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 64, 80), mean = mu, stddev = sigma)),
'conv3_b_3_3' : tf.Variable(tf.truncated_normal(shape=(3, 3, 80, 232), mean = mu, stddev = sigma)),
'conv3_c_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 64, 80), mean = mu, stddev = sigma)),
'conv3_c_5_5' : tf.Variable(tf.truncated_normal(shape=(5, 5, 80, 120), mean = mu, stddev = sigma)),
'conv3_d_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 64, 80), mean = mu, stddev = sigma)),
'full_conn1' : tf.Variable(tf.truncated_normal(shape=(8192, 1420), mean = mu, stddev = sigma)),
'full_conn2' : tf.Variable(tf.truncated_normal(shape=(1420, 250), mean = mu, stddev = sigma)),
'full_conn3' : tf.Variable(tf.truncated_normal(shape=(250, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2_a_1_1' : tf.Variable(tf.zeros(8)),
'conv2_b_1_1' : tf.Variable(tf.zeros(8)),
'conv2_b_3_3' : tf.Variable(tf.zeros(32)),
'conv2_c_1_1' : tf.Variable(tf.zeros(8)),
'conv2_c_5_5' : tf.Variable(tf.zeros(16)),
'conv2_d_1_1' : tf.Variable(tf.zeros(8)),
'conv3_a_1_1' : tf.Variable(tf.zeros(80)),
'conv3_b_1_1' : tf.Variable(tf.zeros(80)),
'conv3_b_3_3' : tf.Variable(tf.zeros(232)),
'conv3_c_1_1' : tf.Variable(tf.zeros(80)),
'conv3_c_5_5' : tf.Variable(tf.zeros(120)),
'conv3_d_1_1' : tf.Variable(tf.zeros(80)),
'full_conn1' : tf.Variable(tf.zeros(1420)),
'full_conn2' : tf.Variable(tf.zeros(250)),
'full_conn3' : tf.Variable(tf.zeros(43))
}
# Layer 1: Normal Convolution. Input = 32x32x3. Output = 32x32x6
conv1 = conv2d(x, weights['conv1'], biases['conv1'], padding='SAME')
# Activation
conv1 = activation(conv1)
# Pooling. Input = 32x32x6. Output 16x16x6.
conv1 = maxpool2d(conv1, 2)
# Layer 2: Inception. Input 16x16x6. Output = 16x16x64
conv2_a = conv2d(conv1, weights['conv2_a_1_1'], biases['conv2_a_1_1'], padding='SAME')
conv2_b = conv2d(conv1, weights['conv2_b_1_1'], biases['conv2_b_1_1'], padding='SAME')
conv2_b = conv2d(conv2_b, weights['conv2_b_3_3'], biases['conv2_b_3_3'], padding='SAME')
conv2_c = conv2d(conv1, weights['conv2_c_1_1'], biases['conv2_c_1_1'], padding='SAME')
conv2_c = conv2d(conv2_c, weights['conv2_c_5_5'], biases['conv2_c_5_5'], padding='SAME')
conv2_d = maxpool2d(conv1, 3, 1)
conv2_d = conv2d(conv2_d, weights['conv2_d_1_1'], biases['conv2_d_1_1'], padding='SAME')
conv2 = tf.concat(3, [conv2_a, conv2_b, conv2_c, conv2_d])
# Activation
conv2 = activation(conv2)
# Pooling. Input = 16x16x64. Output 8x8x64.
conv2 = maxpool2d(conv2, 2)
# Layer 3: Inception. Input 8x8x64. Output = 8x8x512
conv3_a = conv2d(conv2, weights['conv3_a_1_1'], biases['conv3_a_1_1'], padding='SAME')
conv3_b = conv2d(conv2, weights['conv3_b_1_1'], biases['conv3_b_1_1'], padding='SAME')
conv3_b = conv2d(conv3_b, weights['conv3_b_3_3'], biases['conv3_b_3_3'], padding='SAME')
conv3_c = conv2d(conv2, weights['conv3_c_1_1'], biases['conv3_c_1_1'], padding='SAME')
conv3_c = conv2d(conv3_c, weights['conv3_c_5_5'], biases['conv3_c_5_5'], padding='SAME')
conv3_d = maxpool2d(conv2, 3, 1)
conv3_d = conv2d(conv3_d, weights['conv3_d_1_1'], biases['conv3_d_1_1'], padding='SAME')
conv3 = tf.concat(3, [conv3_a, conv3_b, conv3_c, conv3_d])
# Activation
conv3 = activation(conv3)
# Pooling. Input = 8x8x512. Output = 4x4x512
conv3 = maxpool2d(conv3, 2)
# Layer 4: Fully Connected. Input 8192. Output 1420
flat = tf.reshape(conv3, [-1, 4*4*512])
full1 = linear(flat, weights['full_conn1'], biases['full_conn1'])
# Activation
full1 = activation(full1)
# Dropout
full1 = dropout(full1, keep_prob)
# Layer 5: Fully Connected. Input 1420. Output 250
full2 = linear(full1, weights['full_conn2'], biases['full_conn2'])
# Activation
full2 = activation(full2)
# Dropout
full2 = dropout(full2, keep_prob)
# Layer 6: Fully Connected. Input 250. Output 43
logits = linear(full2, weights['full_conn3'], biases['full_conn3'])
return logits
def Inception2_dropout_fc(x, keep_prob):
### Based on Traffic Sign Classification Using Deep Inception Based Convolution Networks
### by Mrinhal Haloi
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2_a_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 6, 8), mean = mu, stddev = sigma)),
'conv2_b_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 6, 8), mean = mu, stddev = sigma)),
'conv2_b_3_3' : tf.Variable(tf.truncated_normal(shape=(3, 3, 8, 32), mean = mu, stddev = sigma)),
'conv2_c_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 6, 8), mean = mu, stddev = sigma)),
'conv2_c_5_5' : tf.Variable(tf.truncated_normal(shape=(5, 5, 8, 16), mean = mu, stddev = sigma)),
'conv2_d_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 6, 8), mean = mu, stddev = sigma)),
'conv2_d_3_3' : tf.Variable(tf.truncated_normal(shape=(3, 3, 8, 8), mean = mu, stddev = sigma)),
'conv3_a_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 64, 80), mean = mu, stddev = sigma)),
'conv3_b_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 64, 80), mean = mu, stddev = sigma)),
'conv3_b_3_3' : tf.Variable(tf.truncated_normal(shape=(3, 3, 80, 232), mean = mu, stddev = sigma)),
'conv3_c_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 64, 80), mean = mu, stddev = sigma)),
'conv3_c_5_5' : tf.Variable(tf.truncated_normal(shape=(5, 5, 80, 120), mean = mu, stddev = sigma)),
'conv3_d_1_1' : tf.Variable(tf.truncated_normal(shape=(1, 1, 64, 80), mean = mu, stddev = sigma)),
'conv3_d_3_3' : tf.Variable(tf.truncated_normal(shape=(3, 3, 80, 80), mean = mu, stddev = sigma)),
'full_conn1' : tf.Variable(tf.truncated_normal(shape=(8192, 1420), mean = mu, stddev = sigma)),
'full_conn2' : tf.Variable(tf.truncated_normal(shape=(1420, 250), mean = mu, stddev = sigma)),
'full_conn3' : tf.Variable(tf.truncated_normal(shape=(250, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2_a_1_1' : tf.Variable(tf.zeros(8)),
'conv2_b_1_1' : tf.Variable(tf.zeros(8)),
'conv2_b_3_3' : tf.Variable(tf.zeros(32)),
'conv2_c_1_1' : tf.Variable(tf.zeros(8)),
'conv2_c_5_5' : tf.Variable(tf.zeros(16)),
'conv2_d_1_1' : tf.Variable(tf.zeros(8)),
'conv2_d_3_3' : tf.Variable(tf.zeros(8)),
'conv3_a_1_1' : tf.Variable(tf.zeros(80)),
'conv3_b_1_1' : tf.Variable(tf.zeros(80)),
'conv3_b_3_3' : tf.Variable(tf.zeros(232)),
'conv3_c_1_1' : tf.Variable(tf.zeros(80)),
'conv3_c_5_5' : tf.Variable(tf.zeros(120)),
'conv3_d_1_1' : tf.Variable(tf.zeros(80)),
'conv3_d_3_3' : tf.Variable(tf.zeros(80)),
'full_conn1' : tf.Variable(tf.zeros(1420)),
'full_conn2' : tf.Variable(tf.zeros(250)),
'full_conn3' : tf.Variable(tf.zeros(43))
}
# Layer 1: Normal Convolution. Input = 32x32x3. Output = 32x32x6
conv1 = conv2d(x, weights['conv1'], biases['conv1'], padding='SAME')
# Activation
conv1 = activation(conv1)
# Pooling. Input = 32x32x6. Output 16x16x6.
conv1 = maxpool2d(conv1, 2)
# Layer 2: Inception. Input 16x16x6. Output = 16x16x64
conv2_a = conv2d(conv1, weights['conv2_a_1_1'], biases['conv2_a_1_1'], padding='SAME')
conv2_b = conv2d(conv1, weights['conv2_b_1_1'], biases['conv2_b_1_1'], padding='SAME')
conv2_b = conv2d(conv2_b, weights['conv2_b_3_3'], biases['conv2_b_3_3'], padding='SAME')
conv2_c = conv2d(conv1, weights['conv2_c_1_1'], biases['conv2_c_1_1'], padding='SAME')
conv2_c = conv2d(conv2_c, weights['conv2_c_5_5'], biases['conv2_c_5_5'], padding='SAME')
conv2_d = conv2d(conv1, weights['conv2_d_1_1'], biases['conv2_d_1_1'], padding='SAME')
conv2_d = conv2d(conv2_d, weights['conv2_d_3_3'], biases['conv2_d_3_3'], padding='SAME')
conv2_d = maxpool2d(conv2_d, 3, 1)
conv2 = tf.concat(3, [conv2_a, conv2_b, conv2_c, conv2_d])
# Activation
conv2 = activation(conv2)
# Pooling. Input = 16x16x64. Output 8x8x64.
conv2 = maxpool2d(conv2, 2)
# Layer 3: Inception. Input 8x8x64. Output = 8x8x512
conv3_a = conv2d(conv2, weights['conv3_a_1_1'], biases['conv3_a_1_1'], padding='SAME')
conv3_b = conv2d(conv2, weights['conv3_b_1_1'], biases['conv3_b_1_1'], padding='SAME')
conv3_b = conv2d(conv3_b, weights['conv3_b_3_3'], biases['conv3_b_3_3'], padding='SAME')
conv3_c = conv2d(conv2, weights['conv3_c_1_1'], biases['conv3_c_1_1'], padding='SAME')
conv3_c = conv2d(conv3_c, weights['conv3_c_5_5'], biases['conv3_c_5_5'], padding='SAME')
conv3_d = conv2d(conv2, weights['conv3_d_1_1'], biases['conv3_d_1_1'], padding='SAME')
conv3_d = conv2d(conv3_d, weights['conv3_d_3_3'], biases['conv3_d_3_3'], padding='SAME')
conv3_d = maxpool2d(conv3_d, 3, 1)
conv3 = tf.concat(3, [conv3_a, conv3_b, conv3_c, conv3_d])
# Activation
conv3 = activation(conv3)
# Pooling. Input = 8x8x512. Output = 4x4x512
conv3 = maxpool2d(conv3, 2)
# Layer 4: Fully Connected. Input 8192. Output 1420
flat = tf.reshape(conv3, [-1, 4*4*512])
full1 = linear(flat, weights['full_conn1'], biases['full_conn1'])
# Activation
full1 = activation(full1)
# Dropout
full1 = dropout(full1, keep_prob)
# Layer 5: Fully Connected. Input 1420. Output 250
full2 = linear(full1, weights['full_conn2'], biases['full_conn2'])
# Activation
full2 = activation(full2)
# Dropout
full2 = dropout(full2, keep_prob)
# Layer 6: Fully Connected. Input 250. Output 43
logits = linear(full2, weights['full_conn3'], biases['full_conn3'])
return logits
def Multi_Scale_LeNet3_pooling_dropout_fc(x, keep_prob):
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2' : tf.Variable(tf.truncated_normal(shape=(3, 3, 6, 16), mean = mu, stddev = sigma)),
'conv3' : tf.Variable(tf.truncated_normal(shape=(3, 3, 16, 32), mean = mu, stddev = sigma)),
'flat4' : tf.Variable(tf.truncated_normal(shape=(2552, 800), mean = mu, stddev = sigma)),
'flat5' : tf.Variable(tf.truncated_normal(shape=(800, 200), mean = mu, stddev = sigma)),
'flat6' : tf.Variable(tf.truncated_normal(shape=(200, 84), mean = mu, stddev = sigma)),
'flat7' : tf.Variable(tf.truncated_normal(shape=(84, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2' : tf.Variable(tf.zeros(16)),
'conv3' : tf.Variable(tf.zeros(32)),
'flat4' : tf.Variable(tf.zeros(800)),
'flat5' : tf.Variable(tf.zeros(200)),
'flat6' : tf.Variable(tf.zeros(84)),
'flat7' : tf.Variable(tf.zeros(43))
}
# Layer 1: Convolutional. Input = 32x32x3. Output = 28x28x6.
conv1 = conv2d(x, weights['conv1'], biases['conv1'])
# Activation
conv1 = activation(conv1)
# Pooling. Input = 28x28x6. Output = 14x14x6.
conv1 = maxpool2d(conv1, 2)
# Layer 2: Convolutional. Output = 12x12x16.
conv2 = conv2d(conv1, weights['conv2'], biases['conv2'])
# Activation.
conv2 = activation(conv2)
# Layer 3: Convolutional. Output = 10x10x32.
conv3 = conv2d(conv2, weights['conv3'], biases['conv3'])
# Activation.
conv3 = activation(conv3)
# Pooling. Input = 10x10x32. Output = 5x5x32.
conv3 = maxpool2d(conv3, 2)
# Flatten. Input = 14x14x6 + 6x6x16 + 5x5x32. Output = 2552.
flat_conv1 = tf.reshape(conv1, [-1, 14*14*6])
flat_conv2 = tf.reshape(maxpool2d(conv2, 2), [-1, 6*6*16])
flat_conv3 = tf.reshape(conv3, [-1, 5*5*32])
flat3 = tf.concat(1, [flat_conv1, flat_conv2, flat_conv3])
# Layer 4: Full Connected. Input 2552. Output 800.
flat4 = linear(flat3, weights['flat4'], biases['flat4'])
# Activation.
flat4 = activation(flat4)
# Dropout
flat4 = dropout(flat4, keep_prob)
# Layer 5: Fully Connected. Input = 800. Output = 200.
flat5 = linear(flat4, weights['flat5'], biases['flat5'])
# Activation.
flat5 = activation(flat5)
# Dropout
flat5 = dropout(flat5, keep_prob)
# Layer 6: Fully Connected. Input = 200. Output = 84.
flat6 = linear(flat5, weights['flat6'], biases['flat6'])
# Activation.
flat6 = activation(flat6)
# Dropout
flat6 = dropout(flat6, keep_prob)
# Layer 7: Fully Connected. Input = 84. Output = 43.
logits = linear(flat6, weights['flat7'], biases['flat7'])
return logits
def Multi_Scale_LeNet_dropout(x, keep_prob):
print("Don't waste time running this one")
return
### Did not work as well as LeNet and LeNet dropout
### Things to try:
### 1) add max pooling back in
### 2) add 3rd convolution layer
### 3) dropout only the fully connected layers
weights = {
'conv1' : tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma)),
'conv2' : tf.Variable(tf.truncated_normal(shape=(9, 9, 6, 16), mean = mu, stddev = sigma)),
'flat3' : tf.Variable(tf.truncated_normal(shape=(6304, 1260), mean = mu, stddev = sigma)),
'flat4' : tf.Variable(tf.truncated_normal(shape=(1260, 252), mean = mu, stddev = sigma)),
'flat5' : tf.Variable(tf.truncated_normal(shape=(252, 43), mean = mu, stddev = sigma))
}
biases = {
'conv1' : tf.Variable(tf.zeros(6)),
'conv2' : tf.Variable(tf.zeros(16)),
'flat3' : tf.Variable(tf.zeros(1260)),
'flat4' : tf.Variable(tf.zeros(252)),
'flat5' : tf.Variable(tf.zeros(43))
}
# Layer 1: Convolutional. Input = 32x32x3. Output = 28x28x6.
conv1 = conv2d(x, weights['conv1'], biases['conv1'])