Browse Source

choose final version

James Jeon 2 years ago
parent
commit
cb0a4415c5
100 changed files with 12 additions and 19310 deletions
  1. 0
    198
      0.3_mnist/networks.py
  2. 0
    33
      0.3_mnist/train_network.py
  3. BIN
      0.4_mnist/MNIST_data/t10k-images-idx3-ubyte.gz
  4. BIN
      0.4_mnist/MNIST_data/t10k-labels-idx1-ubyte.gz
  5. BIN
      0.4_mnist/MNIST_data/train-images-idx3-ubyte.gz
  6. BIN
      0.4_mnist/MNIST_data/train-labels-idx1-ubyte.gz
  7. 0
    99
      0.4_mnist/model.py
  8. 0
    5
      0.4_mnist/params.py
  9. 0
    74
      0.4_mnist/train.py
  10. 0
    5
      can_data/can.txt
  11. 0
    27
      can_data/get_can_bus.py
  12. BIN
      can_data/left_to_right.npy
  13. 0
    10191
      can_data/left_to_right.txt
  14. BIN
      can_data/right_to_left.npy
  15. 0
    5847
      can_data/right_to_left.txt
  16. 0
    20
      can_data/show_saved_data.py
  17. 5
    0
      data_size.txt
  18. 0
    0
      find_bad_data.py
  19. 0
    0
      get_train_data.py
  20. 0
    0
      get_val_data.py
  21. 1
    5
      model.py
  22. 0
    0
      params.py
  23. 6
    16
      train.py
  24. 0
    64
      ver_0.1/collect_raw_data.py
  25. 0
    76
      ver_0.1/data_collect.py
  26. 0
    65
      ver_0.1/eval_model.py
  27. 0
    30
      ver_0.1/fix_raw_data_with_white_fixels.py
  28. 0
    43
      ver_0.1/get_cam.py
  29. 0
    14
      ver_0.1/get_can_bus.py
  30. 0
    1
      ver_0.1/mount.sh
  31. 0
    198
      ver_0.1/networks.py
  32. 0
    63
      ver_0.1/train_network.py
  33. 0
    35
      ver_0.1/visualize_raw_data.py
  34. 0
    198
      ver_0.2/networks.py
  35. 0
    35
      ver_0.2/train_network.py
  36. 0
    2
      ver_0.3/can.sh
  37. 0
    78
      ver_0.3/collect_raw_data.py
  38. 0
    2
      ver_0.3/data_size.txt
  39. 0
    65
      ver_0.3/eval_model.py
  40. 0
    43
      ver_0.3/get_cam.py
  41. 0
    14
      ver_0.3/get_can_bus.py
  42. 0
    1
      ver_0.3/mount.sh
  43. 0
    198
      ver_0.3/networks.py
  44. 0
    126
      ver_0.3/train_network.py
  45. 0
    37
      ver_0.3/visualize_raw_data.py
  46. 0
    91
      ver_0.4/DT_network.py
  47. BIN
      ver_0.4/__pycache__/model.cpython-35.pyc
  48. BIN
      ver_0.4/__pycache__/params.cpython-35.pyc
  49. 0
    2
      ver_0.4/can.sh
  50. 0
    175
      ver_0.4/cnn_network.py
  51. 0
    98
      ver_0.4/model.py
  52. 0
    1
      ver_0.4/mount.sh
  53. 0
    10
      ver_0.4/params.py
  54. 0
    140
      ver_0.4/train.py
  55. BIN
      ver_0.5.1/.DS_Store
  56. BIN
      ver_0.5.1/._.DS_Store
  57. BIN
      ver_0.5.1/__pycache__/get_train_data.cpython-35.pyc
  58. BIN
      ver_0.5.1/__pycache__/get_val_data.cpython-35.pyc
  59. BIN
      ver_0.5.1/__pycache__/model.cpython-35.pyc
  60. BIN
      ver_0.5.1/__pycache__/params.cpython-35.pyc
  61. 0
    2
      ver_0.5.1/can.sh
  62. 0
    55
      ver_0.5.1/get_val_data.py
  63. 0
    94
      ver_0.5.1/model.py
  64. 0
    1
      ver_0.5.1/mount.sh
  65. 0
    9
      ver_0.5.1/params.py
  66. 0
    5
      ver_0.5.1/result.txt
  67. 0
    76
      ver_0.5.1/train.py
  68. BIN
      ver_0.5/.DS_Store
  69. BIN
      ver_0.5/._.DS_Store
  70. BIN
      ver_0.5/__pycache__/get_train_data.cpython-35.pyc
  71. BIN
      ver_0.5/__pycache__/get_val_data.cpython-35.pyc
  72. BIN
      ver_0.5/__pycache__/model.cpython-35.pyc
  73. BIN
      ver_0.5/__pycache__/params.cpython-35.pyc
  74. 0
    2
      ver_0.5/can.sh
  75. 0
    33
      ver_0.5/find_bad_data.py
  76. 0
    46
      ver_0.5/get_train_data.py
  77. 0
    55
      ver_0.5/get_val_data.py
  78. 0
    95
      ver_0.5/model.py
  79. 0
    1
      ver_0.5/mount.sh
  80. 0
    9
      ver_0.5/params.py
  81. 0
    3
      ver_0.5/result.txt
  82. 0
    77
      ver_0.5/train.py
  83. BIN
      ver_0.6/.DS_Store
  84. BIN
      ver_0.6/._.DS_Store
  85. BIN
      ver_0.6/__pycache__/get_train_data.cpython-35.pyc
  86. BIN
      ver_0.6/__pycache__/get_val_data.cpython-35.pyc
  87. BIN
      ver_0.6/__pycache__/model.cpython-35.pyc
  88. BIN
      ver_0.6/__pycache__/params.cpython-35.pyc
  89. 0
    2
      ver_0.6/can.sh
  90. 0
    33
      ver_0.6/find_bad_data.py
  91. 0
    45
      ver_0.6/get_train_data.py
  92. 0
    54
      ver_0.6/get_val_data.py
  93. 0
    95
      ver_0.6/model.py
  94. 0
    1
      ver_0.6/mount.sh
  95. 0
    9
      ver_0.6/params.py
  96. 0
    6
      ver_0.6/result.txt
  97. 0
    77
      ver_0.6/train.py
  98. BIN
      ver_0.7.1/.DS_Store
  99. BIN
      ver_0.7.1/._.DS_Store
  100. 0
    0
      ver_0.7.1/__pycache__/get_train_data.cpython-35.pyc

+ 0
- 198
0.3_mnist/networks.py View File

@@ -1,198 +0,0 @@
1
-import tflearn
2
-from tflearn.layers.core import input_data, dropout, fully_connected
3
-from tflearn.layers.conv import conv_2d, max_pool_2d, avg_pool_2d
4
-from tflearn.layers.normalization import local_response_normalization, batch_normalization
5
-from tflearn.layers.merge_ops import merge
6
-from tflearn.layers.estimator import regression
7
-
8
-from tflearn.layers.core import input_data, dropout, fully_connected
9
-from tflearn.layers.conv import conv_2d, max_pool_2d
10
-from tflearn.layers.normalization import local_response_normalization
11
-from tflearn.layers.estimator import regression
12
-
13
-def AlexNet(height, width,channel, LR):
14
-	# Building 'AlexNet'
15
-	network = input_data(shape=[None, height, width, channel])
16
-
17
-	network = batch_normalization(network)
18
-
19
-	network = conv_2d(network, 96, 11, strides=4, activation='relu')
20
-	network = max_pool_2d(network, 3, strides=2)
21
-
22
-	network = local_response_normalization(network)
23
-
24
-	network = conv_2d(network, 256, 5, activation='relu')
25
-	network = max_pool_2d(network, 3, strides=2)
26
-
27
-	network = local_response_normalization(network)
28
-
29
-	network = conv_2d(network, 384, 3, activation='relu')
30
-	network = conv_2d(network, 384, 3, activation='relu')
31
-	network = conv_2d(network, 256, 3, activation='relu')
32
-	network = max_pool_2d(network, 3, strides=2)
33
-
34
-	network = local_response_normalization(network)
35
-
36
-	network = fully_connected(network, 4096, activation='relu')
37
-	network = dropout(network, 0.5)
38
-	network = fully_connected(network, 2048, activation='relu')
39
-	network = dropout(network, 0.5)
40
-	network = fully_connected(network, 1024, activation='relu')
41
-	network = dropout(network, 0.5)
42
-	network = fully_connected(network, 512, activation='relu')
43
-	network = dropout(network, 0.5)
44
-	network = fully_connected(network, 256, activation='relu')
45
-	network = dropout(network, 0.5)
46
-	network = fully_connected(network, 50, activation='relu')
47
-
48
-	network = fully_connected(network, 1, activation='linear')
49
-
50
-	network = regression(network, optimizer='adam',
51
-		             loss='hinge_loss',
52
-		             learning_rate=LR)
53
-
54
-	# Training
55
-	model = tflearn.DNN(network, checkpoint_path='model_alexnet',
56
-		            max_checkpoints=1, tensorboard_verbose=0)
57
-
58
-	return model
59
-
60
-def googLeNet(height, width, LR):
61
-
62
-	""" GoogLeNet.
63
-	References:
64
-	    - Szegedy, Christian, et al.
65
-	    Going deeper with convolutions.
66
-	Links:
67
-	    - [GoogLeNet Paper](http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Szegedy_Going_Deeper_With_2015_CVPR_paper.pdf)
68
-	"""
69
-	# image in the array form the height comes first and then the width
70
-	network = input_data(shape=[None, height, width, 1])
71
-	conv1_7_7 = conv_2d(network, 64, 7, strides=2, activation='relu', name = 'conv1_7_7_s2')
72
-	pool1_3_3 = max_pool_2d(conv1_7_7, 3,strides=2)
73
-	pool1_3_3 = local_response_normalization(pool1_3_3)
74
-	conv2_3_3_reduce = conv_2d(pool1_3_3, 64,1, activation='relu',name = 'conv2_3_3_reduce')
75
-	conv2_3_3 = conv_2d(conv2_3_3_reduce, 192,3, activation='relu', name='conv2_3_3')
76
-	conv2_3_3 = local_response_normalization(conv2_3_3)
77
-	pool2_3_3 = max_pool_2d(conv2_3_3, kernel_size=3, strides=2, name='pool2_3_3_s2')
78
-	inception_3a_1_1 = conv_2d(pool2_3_3, 64, 1, activation='relu', name='inception_3a_1_1')
79
-	inception_3a_3_3_reduce = conv_2d(pool2_3_3, 96,1, activation='relu', name='inception_3a_3_3_reduce')
80
-	inception_3a_3_3 = conv_2d(inception_3a_3_3_reduce, 128,filter_size=3,  activation='relu', name = 'inception_3a_3_3')
81
-	inception_3a_5_5_reduce = conv_2d(pool2_3_3,16, filter_size=1,activation='relu', name ='inception_3a_5_5_reduce' )
82
-	inception_3a_5_5 = conv_2d(inception_3a_5_5_reduce, 32, filter_size=5, activation='relu', name= 'inception_3a_5_5')
83
-	inception_3a_pool = max_pool_2d(pool2_3_3, kernel_size=3, strides=1, )
84
-	inception_3a_pool_1_1 = conv_2d(inception_3a_pool, 32, filter_size=1, activation='relu', name='inception_3a_pool_1_1')
85
-
86
-	# merge the inception_3a__
87
-	inception_3a_output = merge([inception_3a_1_1, inception_3a_3_3, inception_3a_5_5, inception_3a_pool_1_1], mode='concat', axis=3)
88
-
89
-	inception_3b_1_1 = conv_2d(inception_3a_output, 128,filter_size=1,activation='relu', name= 'inception_3b_1_1' )
90
-	inception_3b_3_3_reduce = conv_2d(inception_3a_output, 128, filter_size=1, activation='relu', name='inception_3b_3_3_reduce')
91
-	inception_3b_3_3 = conv_2d(inception_3b_3_3_reduce, 192, filter_size=3,  activation='relu',name='inception_3b_3_3')
92
-	inception_3b_5_5_reduce = conv_2d(inception_3a_output, 32, filter_size=1, activation='relu', name = 'inception_3b_5_5_reduce')
93
-	inception_3b_5_5 = conv_2d(inception_3b_5_5_reduce, 96, filter_size=5,  name = 'inception_3b_5_5')
94
-	inception_3b_pool = max_pool_2d(inception_3a_output, kernel_size=3, strides=1,  name='inception_3b_pool')
95
-	inception_3b_pool_1_1 = conv_2d(inception_3b_pool, 64, filter_size=1,activation='relu', name='inception_3b_pool_1_1')
96
-
97
-	#merge the inception_3b_*
98
-	inception_3b_output = merge([inception_3b_1_1, inception_3b_3_3, inception_3b_5_5, inception_3b_pool_1_1], mode='concat',axis=3,name='inception_3b_output')
99
-
100
-	pool3_3_3 = max_pool_2d(inception_3b_output, kernel_size=3, strides=2, name='pool3_3_3')
101
-	inception_4a_1_1 = conv_2d(pool3_3_3, 192, filter_size=1, activation='relu', name='inception_4a_1_1')
102
-	inception_4a_3_3_reduce = conv_2d(pool3_3_3, 96, filter_size=1, activation='relu', name='inception_4a_3_3_reduce')
103
-	inception_4a_3_3 = conv_2d(inception_4a_3_3_reduce, 208, filter_size=3,  activation='relu', name='inception_4a_3_3')
104
-	inception_4a_5_5_reduce = conv_2d(pool3_3_3, 16, filter_size=1, activation='relu', name='inception_4a_5_5_reduce')
105
-	inception_4a_5_5 = conv_2d(inception_4a_5_5_reduce, 48, filter_size=5,  activation='relu', name='inception_4a_5_5')
106
-	inception_4a_pool = max_pool_2d(pool3_3_3, kernel_size=3, strides=1,  name='inception_4a_pool')
107
-	inception_4a_pool_1_1 = conv_2d(inception_4a_pool, 64, filter_size=1, activation='relu', name='inception_4a_pool_1_1')
108
-
109
-	inception_4a_output = merge([inception_4a_1_1, inception_4a_3_3, inception_4a_5_5, inception_4a_pool_1_1], mode='concat', axis=3, name='inception_4a_output')
110
-
111
-
112
-	inception_4b_1_1 = conv_2d(inception_4a_output, 160, filter_size=1, activation='relu', name='inception_4a_1_1')
113
-	inception_4b_3_3_reduce = conv_2d(inception_4a_output, 112, filter_size=1, activation='relu', name='inception_4b_3_3_reduce')
114
-	inception_4b_3_3 = conv_2d(inception_4b_3_3_reduce, 224, filter_size=3, activation='relu', name='inception_4b_3_3')
115
-	inception_4b_5_5_reduce = conv_2d(inception_4a_output, 24, filter_size=1, activation='relu', name='inception_4b_5_5_reduce')
116
-	inception_4b_5_5 = conv_2d(inception_4b_5_5_reduce, 64, filter_size=5,  activation='relu', name='inception_4b_5_5')
117
-
118
-	inception_4b_pool = max_pool_2d(inception_4a_output, kernel_size=3, strides=1,  name='inception_4b_pool')
119
-	inception_4b_pool_1_1 = conv_2d(inception_4b_pool, 64, filter_size=1, activation='relu', name='inception_4b_pool_1_1')
120
-
121
-	inception_4b_output = merge([inception_4b_1_1, inception_4b_3_3, inception_4b_5_5, inception_4b_pool_1_1], mode='concat', axis=3, name='inception_4b_output')
122
-
123
-
124
-	inception_4c_1_1 = conv_2d(inception_4b_output, 128, filter_size=1, activation='relu',name='inception_4c_1_1')
125
-	inception_4c_3_3_reduce = conv_2d(inception_4b_output, 128, filter_size=1, activation='relu', name='inception_4c_3_3_reduce')
126
-	inception_4c_3_3 = conv_2d(inception_4c_3_3_reduce, 256,  filter_size=3, activation='relu', name='inception_4c_3_3')
127
-	inception_4c_5_5_reduce = conv_2d(inception_4b_output, 24, filter_size=1, activation='relu', name='inception_4c_5_5_reduce')
128
-	inception_4c_5_5 = conv_2d(inception_4c_5_5_reduce, 64,  filter_size=5, activation='relu', name='inception_4c_5_5')
129
-
130
-	inception_4c_pool = max_pool_2d(inception_4b_output, kernel_size=3, strides=1)
131
-	inception_4c_pool_1_1 = conv_2d(inception_4c_pool, 64, filter_size=1, activation='relu', name='inception_4c_pool_1_1')
132
-
133
-	inception_4c_output = merge([inception_4c_1_1, inception_4c_3_3, inception_4c_5_5, inception_4c_pool_1_1], mode='concat', axis=3,name='inception_4c_output')
134
-
135
-	inception_4d_1_1 = conv_2d(inception_4c_output, 112, filter_size=1, activation='relu', name='inception_4d_1_1')
136
-	inception_4d_3_3_reduce = conv_2d(inception_4c_output, 144, filter_size=1, activation='relu', name='inception_4d_3_3_reduce')
137
-	inception_4d_3_3 = conv_2d(inception_4d_3_3_reduce, 288, filter_size=3, activation='relu', name='inception_4d_3_3')
138
-	inception_4d_5_5_reduce = conv_2d(inception_4c_output, 32, filter_size=1, activation='relu', name='inception_4d_5_5_reduce')
139
-	inception_4d_5_5 = conv_2d(inception_4d_5_5_reduce, 64, filter_size=5,  activation='relu', name='inception_4d_5_5')
140
-	inception_4d_pool = max_pool_2d(inception_4c_output, kernel_size=3, strides=1,  name='inception_4d_pool')
141
-	inception_4d_pool_1_1 = conv_2d(inception_4d_pool, 64, filter_size=1, activation='relu', name='inception_4d_pool_1_1')
142
-
143
-	inception_4d_output = merge([inception_4d_1_1, inception_4d_3_3, inception_4d_5_5, inception_4d_pool_1_1], mode='concat', axis=3, name='inception_4d_output')
144
-
145
-	inception_4e_1_1 = conv_2d(inception_4d_output, 256, filter_size=1, activation='relu', name='inception_4e_1_1')
146
-	inception_4e_3_3_reduce = conv_2d(inception_4d_output, 160, filter_size=1, activation='relu', name='inception_4e_3_3_reduce')
147
-	inception_4e_3_3 = conv_2d(inception_4e_3_3_reduce, 320, filter_size=3, activation='relu', name='inception_4e_3_3')
148
-	inception_4e_5_5_reduce = conv_2d(inception_4d_output, 32, filter_size=1, activation='relu', name='inception_4e_5_5_reduce')
149
-	inception_4e_5_5 = conv_2d(inception_4e_5_5_reduce, 128,  filter_size=5, activation='relu', name='inception_4e_5_5')
150
-	inception_4e_pool = max_pool_2d(inception_4d_output, kernel_size=3, strides=1,  name='inception_4e_pool')
151
-	inception_4e_pool_1_1 = conv_2d(inception_4e_pool, 128, filter_size=1, activation='relu', name='inception_4e_pool_1_1')
152
-
153
-
154
-	inception_4e_output = merge([inception_4e_1_1, inception_4e_3_3, inception_4e_5_5,inception_4e_pool_1_1],axis=3, mode='concat')
155
-
156
-	pool4_3_3 = max_pool_2d(inception_4e_output, kernel_size=3, strides=2, name='pool_3_3')
157
-
158
-
159
-	inception_5a_1_1 = conv_2d(pool4_3_3, 256, filter_size=1, activation='relu', name='inception_5a_1_1')
160
-	inception_5a_3_3_reduce = conv_2d(pool4_3_3, 160, filter_size=1, activation='relu', name='inception_5a_3_3_reduce')
161
-	inception_5a_3_3 = conv_2d(inception_5a_3_3_reduce, 320, filter_size=3, activation='relu', name='inception_5a_3_3')
162
-	inception_5a_5_5_reduce = conv_2d(pool4_3_3, 32, filter_size=1, activation='relu', name='inception_5a_5_5_reduce')
163
-	inception_5a_5_5 = conv_2d(inception_5a_5_5_reduce, 128, filter_size=5,  activation='relu', name='inception_5a_5_5')
164
-	inception_5a_pool = max_pool_2d(pool4_3_3, kernel_size=3, strides=1,  name='inception_5a_pool')
165
-	inception_5a_pool_1_1 = conv_2d(inception_5a_pool, 128, filter_size=1,activation='relu', name='inception_5a_pool_1_1')
166
-
167
-	inception_5a_output = merge([inception_5a_1_1, inception_5a_3_3, inception_5a_5_5, inception_5a_pool_1_1], axis=3,mode='concat')
168
-
169
-
170
-	inception_5b_1_1 = conv_2d(inception_5a_output, 384, filter_size=1,activation='relu', name='inception_5b_1_1')
171
-	inception_5b_3_3_reduce = conv_2d(inception_5a_output, 192, filter_size=1, activation='relu', name='inception_5b_3_3_reduce')
172
-	inception_5b_3_3 = conv_2d(inception_5b_3_3_reduce, 384,  filter_size=3,activation='relu', name='inception_5b_3_3')
173
-	inception_5b_5_5_reduce = conv_2d(inception_5a_output, 48, filter_size=1, activation='relu', name='inception_5b_5_5_reduce')
174
-	inception_5b_5_5 = conv_2d(inception_5b_5_5_reduce,128, filter_size=5,  activation='relu', name='inception_5b_5_5' )
175
-	inception_5b_pool = max_pool_2d(inception_5a_output, kernel_size=3, strides=1,  name='inception_5b_pool')
176
-	inception_5b_pool_1_1 = conv_2d(inception_5b_pool, 128, filter_size=1, activation='relu', name='inception_5b_pool_1_1')
177
-	inception_5b_output = merge([inception_5b_1_1, inception_5b_3_3, inception_5b_5_5, inception_5b_pool_1_1], axis=3, mode='concat')
178
-
179
-	pool5_7_7 = avg_pool_2d(inception_5b_output, kernel_size=7, strides=1)
180
-	#pool5_7_7 = dropout(pool5_7_7, 0.4)
181
-
182
-	loss = fully_connected(pool5_7_7, 1, activation='linear')
183
-
184
-	network = regression(loss, optimizer='adam',
185
-		             loss='mean_square',
186
-		             learning_rate=LR)
187
-
188
-	model = tflearn.DNN(network, tensorboard_verbose=0)
189
-
190
-	return model
191
-	
192
-	'''
193
-	model.fit(X, Y, n_epoch=1000, validation_set=0.1, shuffle=True,
194
-		  show_metric=True, batch_size=64, snapshot_step=200,
195
-		  snapshot_epoch=False, run_id='googlenet_oxflowers17')
196
-	'''
197
-
198
-

+ 0
- 33
0.3_mnist/train_network.py View File

@@ -1,33 +0,0 @@
1
-import numpy as np
2
-import os
3
-import cv2
4
-import time
5
-
6
-# Load MNIST data set
7
-import tflearn.datasets.mnist as mnist
8
-X, Y, testX, testY = mnist.load_data(one_hot=False)
9
-X = X.reshape([-1, 28, 28, 1])
10
-Y = Y.reshape([-1,1])
11
-testX = testX.reshape([-1, 28, 28, 1])
12
-testY = testY.reshape([-1,1])
13
-
14
-#print(Y)
15
-
16
-WIDTH = 28
17
-HEIGHT = 28
18
-CHANNEL = 1
19
-
20
-from networks import googLeNet, AlexNet
21
-
22
-LR = 1e-2
23
-EPOCHS = 10
24
-MODEL_NAME = 'MNIST-{}-{}-{}-epochs.model'.format('AlexNet', LR , EPOCHS)
25
-
26
-model = AlexNet(HEIGHT,WIDTH,CHANNEL, LR)
27
-
28
-		# train the network
29
-model.fit(X, Y, n_epoch=EPOCHS, run_id=MODEL_NAME, show_metric=True, validation_set=(testX,testY))
30
-
31
-model.save(MODEL_NAME)
32
-
33
-

BIN
0.4_mnist/MNIST_data/t10k-images-idx3-ubyte.gz View File


BIN
0.4_mnist/MNIST_data/t10k-labels-idx1-ubyte.gz View File


BIN
0.4_mnist/MNIST_data/train-images-idx3-ubyte.gz View File


BIN
0.4_mnist/MNIST_data/train-labels-idx1-ubyte.gz View File


+ 0
- 99
0.4_mnist/model.py View File

@@ -1,99 +0,0 @@
1
-import tensorflow as tf
2
-import params
3
-
4
-def weight_variable(shape):
5
-    initial = tf.truncated_normal(shape, stddev=0.1)
6
-    return tf.Variable(initial)
7
-
8
-def bias_variable(shape):
9
-    initial = tf.constant(0.1, shape=shape)
10
-    return tf.Variable(initial)
11
-
12
-def conv2d(x, W, stride):
13
-    return tf.nn.conv2d(x, W, strides=[1, stride, stride, 1], padding='VALID')
14
-
15
-x = tf.placeholder(tf.float32, shape=[None, params.img_height, params.img_width, params.img_channels])
16
-# x = tf.placeholder(tf.float32, shape=[None, 66, 200, 3])
17
-y_ = tf.placeholder(tf.float32, shape=[None, 1])
18
-
19
-x_image = tf.reshape(x, [-1, params.img_height, params.img_width, params.img_channels])
20
-print(x_image)
21
-
22
-# first convolutional layer
23
-W_conv1 = weight_variable([5, 5, params.img_channels, 24])
24
-b_conv1 = bias_variable([24])
25
-
26
-h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1, 2) + b_conv1)
27
-print(h_conv1)
28
-
29
-# second convolutional layer
30
-W_conv2 = weight_variable([5, 5, 24, 36])
31
-b_conv2 = bias_variable([36])
32
-
33
-h_conv2 = tf.nn.relu(conv2d(h_conv1, W_conv2, 2) + b_conv2)
34
-print(h_conv2)
35
-
36
-# third convolutional layer
37
-W_conv3 = weight_variable([3, 3, 36, 48])
38
-b_conv3 = bias_variable([48])
39
-
40
-h_conv3 = tf.nn.relu(conv2d(h_conv2, W_conv3, 2) + b_conv3)
41
-print(h_conv3)
42
-
43
-# # fourth convolutional layer
44
-# W_conv4 = weight_variable([3, 3, 48, 64])
45
-# b_conv4 = bias_variable([64])
46
-
47
-# h_conv4 = tf.nn.relu(conv2d(h_conv3, W_conv4, 1) + b_conv4)
48
-# print(h_conv4)
49
-
50
-# # fifth convolutional layer
51
-# W_conv5 = weight_variable([3, 3, 64, 64])
52
-# b_conv5 = bias_variable([64])
53
-
54
-# h_conv5 = tf.nn.relu(conv2d(h_conv4, W_conv5, 1) + b_conv5)
55
-# print(h_conv5)
56
-
57
-# fully connected layer 1
58
-W_fc1 = weight_variable([48, 1164])
59
-b_fc1 = bias_variable([1164])
60
-
61
-h_conv5_flat = tf.reshape(h_conv3, [-1, 48])
62
-h_fc1 = tf.nn.relu(tf.matmul(h_conv5_flat, W_fc1) + b_fc1)
63
-
64
-keep_prob = tf.placeholder(tf.float32)
65
-h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
66
-print(h_fc1_drop)
67
-
68
-# fully connected layer 2
69
-W_fc2 = weight_variable([1164, 100])
70
-b_fc2 = bias_variable([100])
71
-
72
-h_fc2 = tf.nn.relu(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
73
-
74
-h_fc2_drop = tf.nn.dropout(h_fc2, keep_prob)
75
-print(h_fc2_drop)
76
-
77
-# fully connected layer 3
78
-W_fc3 = weight_variable([100, 50])
79
-b_fc3 = bias_variable([50])
80
-
81
-h_fc3 = tf.nn.relu(tf.matmul(h_fc2_drop, W_fc3) + b_fc3)
82
-
83
-h_fc3_drop = tf.nn.dropout(h_fc3, keep_prob)
84
-print(h_fc3_drop)
85
-
86
-# fully connected layer 4
87
-W_fc4 = weight_variable([50, 25])
88
-b_fc4 = bias_variable([25])
89
-
90
-h_fc4 = tf.nn.relu(tf.matmul(h_fc3_drop, W_fc4) + b_fc4)
91
-
92
-h_fc4_drop = tf.nn.dropout(h_fc4, keep_prob)
93
-print(h_fc4_drop)
94
-
95
-# output
96
-W_fc5 = weight_variable([25, 10])
97
-b_fc5 = bias_variable([10])
98
-
99
-y = tf.multiply(tf.atan(tf.matmul(h_fc4_drop, W_fc5) + b_fc5), 2) #scale the atan output

+ 0
- 5
0.4_mnist/params.py View File

@@ -1,5 +0,0 @@
1
-img_height = 28
2
-img_width = 28
3
-img_channels = 1
4
-batch = 64
5
-epoch = 30

+ 0
- 74
0.4_mnist/train.py View File

@@ -1,74 +0,0 @@
1
-#!/usr/bin/env python 
2
-from __future__ import division
3
-
4
-import os
5
-import tensorflow as tf
6
-import model
7
-import params
8
-import time
9
-import cv2
10
-import numpy as np
11
-
12
-# write_summary = params.write_summary
13
-
14
-sess = tf.InteractiveSession()
15
-
16
-loss = tf.reduce_mean(tf.square(tf.subtract(model.y_, model.y)))
17
-train_step = tf.train.AdamOptimizer(1e-4).minimize(loss)
18
-sess.run(tf.global_variables_initializer())
19
-
20
-# create a summary to monitor cost tensor
21
-# if write_summary:
22
-#     tf.summary.scalar("loss", loss)
23
-
24
-# merge all summaries into a single op
25
-# if write_summary:
26
-#     merged_summary_op = tf.summary.merge_all()
27
-
28
-# saver = tf.train.Saver()
29
-time_start = time.time()
30
-
31
-# op to write logs to Tensorboard
32
-# if write_summary:
33
-#     summary_writer = tf.summary.FileWriter(params.save_dir, graph=tf.get_default_graph())
34
-
35
-from tensorflow.examples.tutorials.mnist import input_data
36
-mnist = input_data.read_data_sets("MNIST_data/", one_hot=False)
37
-
38
-# print(mnist.train.images.shape)
39
-
40
-# train_X = tf.reshape(mnist.train.images, [-1,28,28,1])
41
-# train_Y = tf.reshape(mnist.train.labels, [-1,1])
42
-
43
-val_X = tf.reshape(mnist.test.images, [-1,28,28,1])
44
-val_Y = tf.reshape(mnist.test.labels, [-1,1])
45
-
46
-# print(train_X.shape, train_Y.shape,val_X.shape,val_Y.shape)
47
-
48
-for i in range(params.epoch):   
49
-    print ("start train step {} of {}".format(i, params.epoch))
50
-    batch_X, batch_Y = mnist.train.next_batch(100)
51
-    batch_X = batch_X.reshape([-1,28,28,1])
52
-    batch_Y = batch_Y.reshape([-1,1])
53
-
54
-    train_step.run(feed_dict={model.x: batch_X, model.y_: batch_Y, model.keep_prob: 0.8})
55
-
56
-    # write logs at every iteration
57
-    # if write_summary:
58
-    #     summary = merged_summary_op.eval(feed_dict={model.x: train_X, model.y_: train_Y, model.keep_prob: 1.0})
59
-    #     summary_writer.add_summary(summary, i)
60
-
61
-    t_loss = loss.eval(feed_dict={model.x: batch_X, model.y_: batch_Y, model.keep_prob: 1.0})
62
-    v_loss = loss.eval(feed_dict={model.x: val_X, model.y_: val_Y, model.keep_prob: 1.0})
63
-    print ("epoch {} of {}, train loss {}, val loss {}".format(i, params.epoch,t_loss, v_loss))
64
-
65
-    # if (i+1) % 100 == 0:
66
-    #     if not os.path.exists(params.save_dir):
67
-    #         os.makedirs(params.save_dir)
68
-    #     checkpoint_path = os.path.join(params.save_dir, "model.ckpt")
69
-    #     filename = saver.save(sess, checkpoint_path)
70
-
71
-    #     time_passed = cm.pretty_running_time(time_start)
72
-    #     time_left = cm.pretty_time_left(time_start, i, params.training_steps)
73
-    #     print 'Model saved. Time passed: {}. Time left: {}'.format(time_passed, time_left) 
74
-        

+ 0
- 5
can_data/can.txt View File

@@ -1,5 +0,0 @@
1
-width : 256
2
-height : 141
3
-
4
-
5
-test

+ 0
- 27
can_data/get_can_bus.py View File

@@ -1,27 +0,0 @@
1
-import can
2
-import numpy as np 
3
-import signal
4
-import sys
5
-
6
-bus = can.interface.Bus(channel='can0', bustype='socketcan_native') 
7
-
8
-data = []
9
-
10
-def signal_handler(signal, frame):
11
-	f.close()
12
-	file_name = "slow.npy"
13
-	np.save(file_name,data)
14
-	sys.exit(0)
15
-
16
-
17
-signal.signal(signal.SIGINT, signal_handler)
18
-
19
-f = open("slow.txt", "w")
20
-
21
-while(True):
22
-	msg = str(bus.recv())
23
-	if(msg.find("ID: 0025") > 0):
24
-		f.write(msg)
25
-		f.write('\n')
26
-		data.append(msg)
27
-		print(msg)

BIN
can_data/left_to_right.npy View File


+ 0
- 10191
can_data/left_to_right.txt
File diff suppressed because it is too large
View File


BIN
can_data/right_to_left.npy View File


+ 0
- 5847
can_data/right_to_left.txt
File diff suppressed because it is too large
View File


+ 0
- 20
can_data/show_saved_data.py View File

@@ -1,20 +0,0 @@
1
-import numpy as np 
2
-import time
3
-
4
-loaded_data = np.load("right_to_left.npy")
5
-
6
-for i in loaded_data:
7
-	msg = str(i)
8
-	print(msg)
9
-	hex_data = msg[-23:-21] + msg[-20:-18]
10
-	int_data = int(hex_data, 16)
11
-
12
-	if(int_data == 0):
13
-		pass
14
-	elif(int_data > 500):
15
-		int_data = int_data - 4096
16
-
17
-	print(int_data)
18
-	
19
-	time.sleep(0.5)
20
-

+ 5
- 0
data_size.txt View File

@@ -1,2 +1,7 @@
1 1
 width : 256
2 2
 height : 141
3
+
4
+after 
5
+
6
+width 256
7
+height 66

ver_0.5.1/find_bad_data.py → find_bad_data.py View File


ver_0.5.1/get_train_data.py → get_train_data.py View File


ver_a_0.5.1/get_val_data.py → get_val_data.py View File


ver_a_0.5.1/model.py → model.py View File

@@ -10,12 +10,8 @@ keep_prob = tf.placeholder(tf.float32)
10 10
 
11 11
 x_image = tf.reshape(x, [-1, params.network_height, params.img_width, params.img_channels])
12 12
 
13
-network = tf.layers.batch_normalization(x_image, name="norm_0")
14
-if print_layer:
15
-	print(network)
16
-
17 13
 # Conv Layer # 1
18
-network = tf.layers.conv2d(network, filters=96, kernel_size = (11,11), strides=(4,4), 
14
+network = tf.layers.conv2d(x_image, filters=96, kernel_size = (11,11), strides=(4,4), 
19 15
 	padding='same', activation=tf.nn.relu, use_bias=True,name="conv_1")
20 16
 if print_layer:
21 17
 	print(network)

ver_a_0.5.1/params.py → params.py View File


ver_a_0.1/train.py → train.py View File

@@ -19,9 +19,6 @@ sess.run(tf.global_variables_initializer())
19 19
 
20 20
 # get the val data
21 21
 val_X, val_Y = val_data()
22
-val_X = val_X[600:]
23
-val_Y = val_Y[600:]
24
-# print(np.array(val_Y).shape)
25 22
 # finish get val data
26 23
 
27 24
 file_list = os.listdir('/raw_data')
@@ -29,29 +26,22 @@ for i in range(params.epoch):
29 26
 	# prepare data for training
30 27
 	for file in file_list:
31 28
 		if file.endswith('.npy'):
29
+			print("Start process on file : " , file)
32 30
 			train_X, train_Y = train_data(file)
33 31
 		    	#finishing getting the training data
34
-			print("Start train on file : " , file)
32
+		
35 33
 			# start the train on the data
36
-			batch_iteration = int(train_X.shape[0] / params.batch)
37
-			# print(train_X.shape[0])
38
-			if train_X.shape[0] / params.batch > batch_iteration:
39
-				batch_iteration = batch_iteration + 1
40
-
34
+			batch_iteration = int(train_X.shape[0] / params.batch) + 1
41 35
 			for iteration in range(batch_iteration):
42
-				# print(iteration)
43 36
 				batch_X = train_X[iteration*params.batch:(iteration+1)*params.batch]
44 37
 				batch_Y = train_Y[iteration*params.batch:(iteration+1)*params.batch]
45
-				# print(np.array(batch_X).shape)
46
-				# print(np.array(batch_Y).shape)
47
-
48 38
 
49
-				train_step.run(feed_dict={model.x: batch_X, model.y_: batch_Y, model.keep_prob: 0.5})
50
-				# print("train done for batch")
39
+				train_step.run(feed_dict={model.x: batch_X, model.y_: batch_Y, model.keep_prob: 0.8})
51 40
 
52 41
 				t_loss = loss.eval(feed_dict={model.x: batch_X, model.y_: batch_Y, model.keep_prob: 1.0})
53 42
 				v_loss = loss.eval(feed_dict={model.x: val_X, model.y_: val_Y, model.keep_prob: 1.0})
54
-				print ("epoch {} of {}, batch {} of {}, batch loss {}, val loss {}".format(i, params.epoch,iteration,batch_iteration,t_loss, v_loss))
43
+				print ("epoch {} of {}, batch {} of {}, train loss {}, val loss {}".format(i, params.epoch,iteration,batch_iteration,t_loss, v_loss))
44
+
55 45
 
56 46
 
57 47
 			    

+ 0
- 64
ver_0.1/collect_raw_data.py View File

@@ -1,64 +0,0 @@
1
-import numpy as np
2
-import cv2
3
-import time
4
-import os
5
-import can
6
-import signal
7
-import sys
8
-
9
-bus = can.interface.Bus(channel='can0', bustype='socketcan_native')
10
-
11
-cap = cv2.VideoCapture(0)
12
-cap.set(3,300) # set height
13
-cap.set(4,200) # set width
14
-
15
-raw_data = []
16
-
17
-def signal_handler(signal, frame):
18
-	name = str(time.time())
19
-	file_name = "/raw_data/" + name + ".npy"
20
-	np.save(file_name,raw_data)
21
-	print("saved {} frame, name : {}".format(len(raw_data),name))
22
-	sys.exit(0)
23
- 
24
-signal.signal(signal.SIGINT, signal_handler)
25
-
26
-def get_frame():
27
-	# read the frame from webcam
28
-	_, frame = cap.read()
29
-	# change the color to gray
30
-	frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
31
-
32
-	# change the resolution (256*141)
33
-	frame = cv2.resize(frame,(0,0),fx=0.8, fy=0.8)
34
-	
35
-	return frame
36
-
37
-def get_angle():
38
-    while(True):
39
-	# get one can data
40
-        can_data = str(bus.recv())
41
-	# check it is steering angle, if yes then stop the loop
42
-        if(can_data.find("ID: 0025") > 0):
43
-            break
44
-
45
-    return can_data
46
-
47
-def main():
48
-	while True:
49
-		# discard first 40 frames to give time for webcam to get the proper exposure
50
-		for _ in range(40):
51
-			get_angle()
52
-			get_frame()
53
-
54
-		angle = get_angle()
55
-		frame = get_frame()
56
-		raw_data.append([frame, angle])
57
-
58
-		print(frame.shape[0], frame.shape[1], angle)
59
-
60
-
61
-main()
62
-
63
-cap.release()
64
-# cv2.destroyAllWindows()

+ 0
- 76
ver_0.1/data_collect.py View File

@@ -1,76 +0,0 @@
1
-import numpy as np
2
-import cv2
3
-import time
4
-import os
5
-import can
6
-import signal
7
-import sys
8
-
9
-bus = can.interface.Bus(channel='can0', bustype='socketcan_native')
10
-
11
-cap = cv2.VideoCapture(0)
12
-cap.set(3,200) # set height
13
-cap.set(4,250) # set width
14
-
15
-raw_data = []
16
-
17
-def signal_handler(signal, frame):
18
-    file_name = "raw_data/" + str(time.time()) + ".npy"
19
-    np.save(file_name,raw_data)
20
-    sys.exit(0)
21
-
22
-signal.signal(signal.SIGINT, signal_handler)
23
-
24
-def get_frame():
25
-    # read the frame from webcam
26
-    _, frame = cap.read()
27
-
28
-    # change the color to gray
29
-    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
30
-
31
-    # webcam is install in car upside down, so flip the image
32
-    frame = cv2.flip(frame,0)
33
-    frame = cv2.flip(frame,1)
34
-
35
-    # cut the top part of image because it is sky and bottom of image
36
-    # frame = frame[150:-15,::]
37
-
38
-    # resize the image by 80% to make it right size to feed into CNN
39
-    frame = cv2.resize(frame,(0,0),fx=0.8, fy=0.8)
40
-
41
-    # print(frame.shape)
42
-    # cv2.imshow('frame',frame)
43
-    # if cv2.waitKey(1) & 0xFF == ord('q'):
44
-    #     break
45
-
46
-    return frame
47
-
48
-def get_angle():
49
-    while(True):
50
-        notifier = str(bus.recv())
51
-
52
-        if(notifier.find("ID: 0025") > 0):
53
-            hex_data = notifier[-23:-21] + notifier[-20:-18]
54
-            int_data = int(hex_data, 16)
55
-
56
-            if(int_data > 550):
57
-                int_data = int_data - 4096
58
-
59
-            break
60
-
61
-    return int_data
62
-
63
-def main():
64
-    while True:
65
-        angle = get_angle()
66
-        frame = get_frame()
67
-
68
-        raw_data.append([frame, angle])
69
-
70
-        # if cv2.waitKey(1) & 0xFF == ord('q'):
71
-        #     break   
72
-
73
-main()
74
-
75
-cap.release()
76
-# cv2.destroyAllWindows()

+ 0
- 65
ver_0.1/eval_model.py View File

@@ -1,65 +0,0 @@
1
-import numpy as np
2
-import os
3
-
4
-from networks import googLeNet
5
-
6
-WIDTH = 66
7
-HEIGHT = 256
8
-LR = 1e-3
9
-EPOCHS = 10
10
-MODEL_NAME = 'Self-Steering-Car-{}-{}-{}-epochs.model'.format('googLeNet', LR , EPOCHS)
11
-
12
-model = googLeNet(WIDTH, HEIGHT, LR)
13
-
14
-
15
-# make evaluation data
16
-eval_x = []
17
-eval_y = []
18
-file_list = os.listdir('/raw_data/eval_data')
19
-for file in file_list:
20
-	if file.endswith('.npy'):
21
-		file_location = "/raw_data/eval_data/" + file
22
-		file = np.load(file_location)
23
-
24
-		temp_x = []
25
-	
26
-		for data in file:
27
-			frame = (data[0][70:-5,::]).reshape(66,256,1)
28
-			#cv2.imshow('frame', frame)
29
-			
30
-
31
-			if len(temp_x) == 0:
32
-				temp_x = frame
33
-				#print(temp_x.shape)
34
-			elif temp_x.shape[2] < 4:
35
-				temp_x = np.concatenate((temp_x, frame), axis=2)
36
-				#print(temp_x.shape)
37
-			else:
38
-				if temp_x.shape[2] == 4:
39
-					temp_x = np.concatenate((temp_x, frame), axis=2)
40
-					#print(temp_x.shape)
41
-					eval_x.append([temp_x])
42
-					eval_y.append([data[1]])
43
-				else:
44
-					temp_x = temp_x[::,::,-4:]
45
-					#print(temp_x.shape)
46
-					temp_x = np.concatenate((temp_x, frame), axis=2)
47
-					#print(temp_x.shape)
48
-					eval_x.append([temp_x])
49
-					eval_y.append([data[1]])
50
-
51
-eval_x = np.array(eval_x).reshape(-1,66,256,5)
52
-#print(eval_x.shape)
53
-eval_y = np.array(eval_y)
54
-#print(eval_y.shape)
55
-# finish makeing evaluation data
56
-
57
-model.load(MODEL_NAME)
58
-
59
-eval = model.evaluate(eval_x, eval_y)
60
-
61
-print(eval)
62
-
63
-
64
-
65
-

+ 0
- 30
ver_0.1/fix_raw_data_with_white_fixels.py View File

@@ -1,30 +0,0 @@
1
-import os
2
-import cv2
3
-import numpy as np
4
-import time
5
-
6
-'''
7
-original data
8
-width : 256
9
-height : 141
10
-'''
11
-
12
-file_list = os.listdir('/raw_data')
13
-#print(data_list)
14
-
15
-for file in file_list:
16
-	if file.endswith('.npy'):
17
-		print(file)
18
-		file_location = "/raw_data/" + file
19
-		loaded_file = np.load(file_location)
20
-
21
-		fixed_file = loaded_file[45:]
22
-		file_name ="/raw_data/" + "fixed_" + str(file)
23
-		np.save(file_name, fixed_file)
24
-'''
25
-data after resize
26
-width : 256
27
-height : 66
28
-'''
29
-
30
-

+ 0
- 43
ver_0.1/get_cam.py View File

@@ -1,43 +0,0 @@
1
-import numpy as np
2
-import cv2
3
-
4
-cap = cv2.VideoCapture(0)
5
-cap.set(3,350) # set height
6
-cap.set(4,200) # set width
7
-
8
-def get_frame():
9
-    # read the frame from webcam
10
-    _, frame = cap.read()
11
-
12
-    # change the color to gray
13
-    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
14
-
15
-    # webcam is install in car upside down, so flip the image
16
-    frame = cv2.flip(frame,0)
17
-    frame = cv2.flip(frame,1)
18
-
19
-    # cut the top part of image because it is sky and bottom of image
20
-    # frame = frame[150:-15,::]
21
-
22
-    # resize the image by 80% to make it right size to feed into CNN
23
-    frame = cv2.resize(frame,(0,0),fx=0.8, fy=0.8)
24
-
25
-    # print(frame.shape)
26
-    # cv2.imshow('frame',frame)
27
-    # if cv2.waitKey(1) & 0xFF == ord('q'):
28
-    #     break
29
-
30
-    return frame
31
-
32
-def main():
33
-    while True:
34
-        frame = get_frame()
35
-
36
-        print(frame.shape[0], frame.shape[1])
37
-        # if cv2.waitKey(1) & 0xFF == ord('q'):
38
-        #     break   
39
-
40
-main()
41
-
42
-cap.release()
43
-# cv2.destroyAllWindows()

+ 0
- 14
ver_0.1/get_can_bus.py View File

@@ -1,14 +0,0 @@
1
-import can 
2
-bus = can.interface.Bus(channel='can0', bustype='socketcan_native') 
3
-
4
-while(True):
5
-	notifier = str(bus.recv())
6
-	if(notifier.find("ID: 0025") > 0):
7
-		hex_data = notifier[-23:-21] + notifier[-20:-18]
8
-		int_data = int(hex_data, 16)
9
-		if(int_data == 0):
10
-			pass
11
-		elif(int_data > 500):
12
-			int_data = int_data - 4096
13
-
14
-		print(int_data)

+ 0
- 1
ver_0.1/mount.sh View File

@@ -1 +0,0 @@
1
-sudo mount /dev/mmcblk1p1 /raw_data

+ 0
- 198
ver_0.1/networks.py View File

@@ -1,198 +0,0 @@
1
-""" AlexNet.
2
-References:
3
-    - Alex Krizhevsky, Ilya Sutskever & Geoffrey E. Hinton. ImageNet
4
-    Classification with Deep Convolutional Neural Networks. NIPS, 2012.
5
-Links:
6
-    - [AlexNet Paper](http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf)
7
-"""
8
-
9
-def AlexNet(height, width, LR):
10
-
11
-	import tflearn
12
-	from tflearn.layers.core import input_data, dropout, fully_connected
13
-	from tflearn.layers.conv import conv_2d, max_pool_2d
14
-	from tflearn.layers.normalization import local_response_normalization
15
-	from tflearn.layers.estimator import regression
16
-
17
-	# Building 'AlexNet'
18
-	network = input_data(shape=[None, height, width, 5])
19
-	network = conv_2d(network, 96, 11, strides=4, activation='relu')
20
-	network = max_pool_2d(network, 3, strides=2)
21
-	network = local_response_normalization(network)
22
-	network = conv_2d(network, 256, 5, activation='relu')
23
-	network = max_pool_2d(network, 3, strides=2)
24
-	network = local_response_normalization(network)
25
-	network = conv_2d(network, 384, 3, activation='relu')
26
-	network = conv_2d(network, 384, 3, activation='relu')
27
-	network = conv_2d(network, 256, 3, activation='relu')
28
-	network = max_pool_2d(network, 3, strides=2)
29
-	network = local_response_normalization(network)
30
-	network = fully_connected(network, 4096, activation='tanh')
31
-	network = dropout(network, 0.5)
32
-	network = fully_connected(network, 4096, activation='tanh')
33
-	network = dropout(network, 0.5)
34
-	network = fully_connected(network, 1, activation='softmax')
35
-
36
-	network = regression(network, optimizer='momentum',
37
-		             loss='mean_square',
38
-		             learning_rate=LR)
39
-	# Model
40
-	model = tflearn.DNN(network, checkpoint_path='model_alexnet',
41
-		            max_checkpoints=1, tensorboard_verbose=0)
42
-
43
-	return model
44
-
45
-	"""
46
-	model.fit(X, Y, n_epoch=1000, validation_set=0.1, shuffle=True,
47
-		  show_metric=True, batch_size=64, snapshot_step=200,
48
-		  snapshot_epoch=False, run_id='alexnet_oxflowers17')
49
-	"""
50
-
51
-
52
-def googLeNet(height, width, LR):
53
-
54
-	""" GoogLeNet.
55
-	References:
56
-	    - Szegedy, Christian, et al.
57
-	    Going deeper with convolutions.
58
-	Links:
59
-	    - [GoogLeNet Paper](http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Szegedy_Going_Deeper_With_2015_CVPR_paper.pdf)
60
-	"""
61
-
62
-	import tflearn
63
-	from tflearn.layers.core import input_data, dropout, fully_connected
64
-	from tflearn.layers.conv import conv_2d, max_pool_2d, avg_pool_2d
65
-	from tflearn.layers.normalization import local_response_normalization
66
-	from tflearn.layers.merge_ops import merge
67
-	from tflearn.layers.estimator import regression
68
-
69
-	network = input_data(shape=[None,height, width, 5])
70
-	conv1_7_7 = conv_2d(network, 64, 7, strides=2, activation='relu', name = 'conv1_7_7_s2')
71
-	pool1_3_3 = max_pool_2d(conv1_7_7, 3,strides=2)
72
-	pool1_3_3 = local_response_normalization(pool1_3_3)
73
-	conv2_3_3_reduce = conv_2d(pool1_3_3, 64,1, activation='relu',name = 'conv2_3_3_reduce')
74
-	conv2_3_3 = conv_2d(conv2_3_3_reduce, 192,3, activation='relu', name='conv2_3_3')
75
-	conv2_3_3 = local_response_normalization(conv2_3_3)
76
-	pool2_3_3 = max_pool_2d(conv2_3_3, kernel_size=3, strides=2, name='pool2_3_3_s2')
77
-	inception_3a_1_1 = conv_2d(pool2_3_3, 64, 1, activation='relu', name='inception_3a_1_1')
78
-	inception_3a_3_3_reduce = conv_2d(pool2_3_3, 96,1, activation='relu', name='inception_3a_3_3_reduce')
79
-	inception_3a_3_3 = conv_2d(inception_3a_3_3_reduce, 128,filter_size=3,  activation='relu', name = 'inception_3a_3_3')
80
-	inception_3a_5_5_reduce = conv_2d(pool2_3_3,16, filter_size=1,activation='relu', name ='inception_3a_5_5_reduce' )
81
-	inception_3a_5_5 = conv_2d(inception_3a_5_5_reduce, 32, filter_size=5, activation='relu', name= 'inception_3a_5_5')
82
-	inception_3a_pool = max_pool_2d(pool2_3_3, kernel_size=3, strides=1, )
83
-	inception_3a_pool_1_1 = conv_2d(inception_3a_pool, 32, filter_size=1, activation='relu', name='inception_3a_pool_1_1')
84
-
85
-	# merge the inception_3a__
86
-	inception_3a_output = merge([inception_3a_1_1, inception_3a_3_3, inception_3a_5_5, inception_3a_pool_1_1], mode='concat', axis=3)
87
-
88
-	inception_3b_1_1 = conv_2d(inception_3a_output, 128,filter_size=1,activation='relu', name= 'inception_3b_1_1' )
89
-	inception_3b_3_3_reduce = conv_2d(inception_3a_output, 128, filter_size=1, activation='relu', name='inception_3b_3_3_reduce')
90
-	inception_3b_3_3 = conv_2d(inception_3b_3_3_reduce, 192, filter_size=3,  activation='relu',name='inception_3b_3_3')
91
-	inception_3b_5_5_reduce = conv_2d(inception_3a_output, 32, filter_size=1, activation='relu', name = 'inception_3b_5_5_reduce')
92
-	inception_3b_5_5 = conv_2d(inception_3b_5_5_reduce, 96, filter_size=5,  name = 'inception_3b_5_5')
93
-	inception_3b_pool = max_pool_2d(inception_3a_output, kernel_size=3, strides=1,  name='inception_3b_pool')
94
-	inception_3b_pool_1_1 = conv_2d(inception_3b_pool, 64, filter_size=1,activation='relu', name='inception_3b_pool_1_1')
95
-
96
-	#merge the inception_3b_*
97
-	inception_3b_output = merge([inception_3b_1_1, inception_3b_3_3, inception_3b_5_5, inception_3b_pool_1_1], mode='concat',axis=3,name='inception_3b_output')
98
-
99
-	pool3_3_3 = max_pool_2d(inception_3b_output, kernel_size=3, strides=2, name='pool3_3_3')
100
-	inception_4a_1_1 = conv_2d(pool3_3_3, 192, filter_size=1, activation='relu', name='inception_4a_1_1')
101
-	inception_4a_3_3_reduce = conv_2d(pool3_3_3, 96, filter_size=1, activation='relu', name='inception_4a_3_3_reduce')
102
-	inception_4a_3_3 = conv_2d(inception_4a_3_3_reduce, 208, filter_size=3,  activation='relu', name='inception_4a_3_3')
103
-	inception_4a_5_5_reduce = conv_2d(pool3_3_3, 16, filter_size=1, activation='relu', name='inception_4a_5_5_reduce')
104
-	inception_4a_5_5 = conv_2d(inception_4a_5_5_reduce, 48, filter_size=5,  activation='relu', name='inception_4a_5_5')
105
-	inception_4a_pool = max_pool_2d(pool3_3_3, kernel_size=3, strides=1,  name='inception_4a_pool')
106
-	inception_4a_pool_1_1 = conv_2d(inception_4a_pool, 64, filter_size=1, activation='relu', name='inception_4a_pool_1_1')
107
-
108
-	inception_4a_output = merge([inception_4a_1_1, inception_4a_3_3, inception_4a_5_5, inception_4a_pool_1_1], mode='concat', axis=3, name='inception_4a_output')
109
-
110
-
111
-	inception_4b_1_1 = conv_2d(inception_4a_output, 160, filter_size=1, activation='relu', name='inception_4a_1_1')
112
-	inception_4b_3_3_reduce = conv_2d(inception_4a_output, 112, filter_size=1, activation='relu', name='inception_4b_3_3_reduce')
113
-	inception_4b_3_3 = conv_2d(inception_4b_3_3_reduce, 224, filter_size=3, activation='relu', name='inception_4b_3_3')
114
-	inception_4b_5_5_reduce = conv_2d(inception_4a_output, 24, filter_size=1, activation='relu', name='inception_4b_5_5_reduce')
115
-	inception_4b_5_5 = conv_2d(inception_4b_5_5_reduce, 64, filter_size=5,  activation='relu', name='inception_4b_5_5')
116
-
117
-	inception_4b_pool = max_pool_2d(inception_4a_output, kernel_size=3, strides=1,  name='inception_4b_pool')
118
-	inception_4b_pool_1_1 = conv_2d(inception_4b_pool, 64, filter_size=1, activation='relu', name='inception_4b_pool_1_1')
119
-
120
-	inception_4b_output = merge([inception_4b_1_1, inception_4b_3_3, inception_4b_5_5, inception_4b_pool_1_1], mode='concat', axis=3, name='inception_4b_output')
121
-
122
-
123
-	inception_4c_1_1 = conv_2d(inception_4b_output, 128, filter_size=1, activation='relu',name='inception_4c_1_1')
124
-	inception_4c_3_3_reduce = conv_2d(inception_4b_output, 128, filter_size=1, activation='relu', name='inception_4c_3_3_reduce')
125
-	inception_4c_3_3 = conv_2d(inception_4c_3_3_reduce, 256,  filter_size=3, activation='relu', name='inception_4c_3_3')
126
-	inception_4c_5_5_reduce = conv_2d(inception_4b_output, 24, filter_size=1, activation='relu', name='inception_4c_5_5_reduce')
127
-	inception_4c_5_5 = conv_2d(inception_4c_5_5_reduce, 64,  filter_size=5, activation='relu', name='inception_4c_5_5')
128
-
129
-	inception_4c_pool = max_pool_2d(inception_4b_output, kernel_size=3, strides=1)
130
-	inception_4c_pool_1_1 = conv_2d(inception_4c_pool, 64, filter_size=1, activation='relu', name='inception_4c_pool_1_1')
131
-
132
-	inception_4c_output = merge([inception_4c_1_1, inception_4c_3_3, inception_4c_5_5, inception_4c_pool_1_1], mode='concat', axis=3,name='inception_4c_output')
133
-
134
-	inception_4d_1_1 = conv_2d(inception_4c_output, 112, filter_size=1, activation='relu', name='inception_4d_1_1')
135
-	inception_4d_3_3_reduce = conv_2d(inception_4c_output, 144, filter_size=1, activation='relu', name='inception_4d_3_3_reduce')
136
-	inception_4d_3_3 = conv_2d(inception_4d_3_3_reduce, 288, filter_size=3, activation='relu', name='inception_4d_3_3')
137
-	inception_4d_5_5_reduce = conv_2d(inception_4c_output, 32, filter_size=1, activation='relu', name='inception_4d_5_5_reduce')
138
-	inception_4d_5_5 = conv_2d(inception_4d_5_5_reduce, 64, filter_size=5,  activation='relu', name='inception_4d_5_5')
139
-	inception_4d_pool = max_pool_2d(inception_4c_output, kernel_size=3, strides=1,  name='inception_4d_pool')
140
-	inception_4d_pool_1_1 = conv_2d(inception_4d_pool, 64, filter_size=1, activation='relu', name='inception_4d_pool_1_1')
141
-
142
-	inception_4d_output = merge([inception_4d_1_1, inception_4d_3_3, inception_4d_5_5, inception_4d_pool_1_1], mode='concat', axis=3, name='inception_4d_output')
143
-
144
-	inception_4e_1_1 = conv_2d(inception_4d_output, 256, filter_size=1, activation='relu', name='inception_4e_1_1')
145
-	inception_4e_3_3_reduce = conv_2d(inception_4d_output, 160, filter_size=1, activation='relu', name='inception_4e_3_3_reduce')
146
-	inception_4e_3_3 = conv_2d(inception_4e_3_3_reduce, 320, filter_size=3, activation='relu', name='inception_4e_3_3')
147
-	inception_4e_5_5_reduce = conv_2d(inception_4d_output, 32, filter_size=1, activation='relu', name='inception_4e_5_5_reduce')
148
-	inception_4e_5_5 = conv_2d(inception_4e_5_5_reduce, 128,  filter_size=5, activation='relu', name='inception_4e_5_5')
149
-	inception_4e_pool = max_pool_2d(inception_4d_output, kernel_size=3, strides=1,  name='inception_4e_pool')
150
-	inception_4e_pool_1_1 = conv_2d(inception_4e_pool, 128, filter_size=1, activation='relu', name='inception_4e_pool_1_1')
151
-
152
-
153
-	inception_4e_output = merge([inception_4e_1_1, inception_4e_3_3, inception_4e_5_5,inception_4e_pool_1_1],axis=3, mode='concat')
154
-
155
-	pool4_3_3 = max_pool_2d(inception_4e_output, kernel_size=3, strides=2, name='pool_3_3')
156
-
157
-
158
-	inception_5a_1_1 = conv_2d(pool4_3_3, 256, filter_size=1, activation='relu', name='inception_5a_1_1')
159
-	inception_5a_3_3_reduce = conv_2d(pool4_3_3, 160, filter_size=1, activation='relu', name='inception_5a_3_3_reduce')
160
-	inception_5a_3_3 = conv_2d(inception_5a_3_3_reduce, 320, filter_size=3, activation='relu', name='inception_5a_3_3')
161
-	inception_5a_5_5_reduce = conv_2d(pool4_3_3, 32, filter_size=1, activation='relu', name='inception_5a_5_5_reduce')
162
-	inception_5a_5_5 = conv_2d(inception_5a_5_5_reduce, 128, filter_size=5,  activation='relu', name='inception_5a_5_5')
163
-	inception_5a_pool = max_pool_2d(pool4_3_3, kernel_size=3, strides=1,  name='inception_5a_pool')
164
-	inception_5a_pool_1_1 = conv_2d(inception_5a_pool, 128, filter_size=1,activation='relu', name='inception_5a_pool_1_1')
165
-
166
-	inception_5a_output = merge([inception_5a_1_1, inception_5a_3_3, inception_5a_5_5, inception_5a_pool_1_1], axis=3,mode='concat')
167
-
168
-
169
-	inception_5b_1_1 = conv_2d(inception_5a_output, 384, filter_size=1,activation='relu', name='inception_5b_1_1')
170
-	inception_5b_3_3_reduce = conv_2d(inception_5a_output, 192, filter_size=1, activation='relu', name='inception_5b_3_3_reduce')
171
-	inception_5b_3_3 = conv_2d(inception_5b_3_3_reduce, 384,  filter_size=3,activation='relu', name='inception_5b_3_3')
172
-	inception_5b_5_5_reduce = conv_2d(inception_5a_output, 48, filter_size=1, activation='relu', name='inception_5b_5_5_reduce')
173
-	inception_5b_5_5 = conv_2d(inception_5b_5_5_reduce,128, filter_size=5,  activation='relu', name='inception_5b_5_5' )
174
-	inception_5b_pool = max_pool_2d(inception_5a_output, kernel_size=3, strides=1,  name='inception_5b_pool')
175
-	inception_5b_pool_1_1 = conv_2d(inception_5b_pool, 128, filter_size=1, activation='relu', name='inception_5b_pool_1_1')
176
-	inception_5b_output = merge([inception_5b_1_1, inception_5b_3_3, inception_5b_5_5, inception_5b_pool_1_1], axis=3, mode='concat')
177
-
178
-	pool5_7_7 = avg_pool_2d(inception_5b_output, kernel_size=7, strides=1)
179
-	pool5_7_7 = dropout(pool5_7_7, 0.4)
180
-
181
-	loss = fully_connected(pool5_7_7, 1,activation='softmax')
182
-
183
-	network = regression(loss, optimizer='momentum',
184
-		             loss='mean_square',
185
-		             learning_rate=LR)
186
-
187
-	model = tflearn.DNN(network, checkpoint_path='model_googlenet',
188
-		            max_checkpoints=1, tensorboard_verbose=0)
189
-
190
-	return model
191
-	
192
-	'''
193
-	model.fit(X, Y, n_epoch=1000, validation_set=0.1, shuffle=True,
194
-		  show_metric=True, batch_size=64, snapshot_step=200,
195
-		  snapshot_epoch=False, run_id='googlenet_oxflowers17')
196
-	'''
197
-
198
-

+ 0
- 63
ver_0.1/train_network.py View File

@@ -1,63 +0,0 @@
1
-import numpy as np
2
-import os
3
-import cv2
4
-import time
5
-
6
-
7
-from networks import googLeNet
8
-
9
-WIDTH = 256
10
-HEIGHT = 66
11
-LR = 1e-3
12
-EPOCHS = 10
13
-MODEL_NAME = 'Self-Steering-Car-{}-{}-{}-epochs.model'.format('googLeNet', LR , EPOCHS)
14
-
15
-model = googLeNet(HEIGHT,WIDTH, LR)
16
-
17
-# start training
18
-file_list = os.listdir('/raw_data')
19
-for file in file_list:
20
-	if file.endswith('.npy'):
21
-		print("Start training on file : " + file + ".npy")
22
-		file_location = "/raw_data/" + file
23
-		loaded_data = np.load(file_location)
24
-
25
-		X = []
26
-		Y = []
27
-
28
-		temp_x = []
29
-
30
-		for data in loaded_data:
31
-			frame = (data[0][70:-5,::]).reshape(66,256,1)
32
-			
33
-			if len(temp_x) == 0:
34
-				temp_x = frame
35
-			elif temp_x.shape[2] < 4:
36
-				temp_x = np.concatenate((temp_x, frame), axis=2)
37
-			elif temp_x.shape[2] == 4:
38
-				temp_x = np.concatenate((temp_x, frame), axis=2)
39
-				X.append([temp_x])
40
-				Y.append([data[1]])
41
-			else:
42
-				temp_x = temp_x[::,::,-4:]
43
-				#print(temp_x.shape)
44
-				temp_x = np.concatenate((temp_x, frame), axis=2)
45
-				#print(temp_x.shape)
46
-				X.append([temp_x])
47
-				Y.append([data[1]])
48
-				#print(len(X))
49
-				#print(len(Y))
50
-
51
-
52
-			
53
-			if cv2.waitKey(1) & 0xFF == ord('q'):
54
-				break
55
-
56
-		X = np.array(X).reshape(-1,66,256,5)
57
-		#print(X.shape)
58
-		Y = np.array(Y).reshape(-1,1)
59
-		#print(Y.shape)
60
-		
61
-		model.fit(X,Y,run_id=MODEL_NAME, show_metric=True,shuffle=True,snapshot_step=500)
62
-
63
-		model.save(MODEL_NAME)

+ 0
- 35
ver_0.1/visualize_raw_data.py View File

@@ -1,35 +0,0 @@
1
-import os
2
-import cv2
3
-import numpy as np
4
-import time
5
-
6
-'''
7
-original data
8
-width : 256
9
-height : 141
10
-'''
11
-
12
-file_list = os.listdir('/raw_data')
13
-#print(data_list)
14
-
15
-for file in file_list:
16
-	if file.endswith('.npy'):
17
-		print(file)
18
-		file_location = "/raw_data/" +  file
19
-		loaded_data = np.load(file_location)
20
-
21
-		for data in loaded_data:
22
-			frame = data[0][70:-5,::]
23
-			cv2.imshow('frame', frame)
24
-			print(frame.shape, data[1])
25
-		
26
-			if cv2.waitKey(1) & 0xFF == ord('q'):
27
-				break
28
-
29
-'''
30
-data after resize
31
-width : 256
32
-height : 66
33
-'''
34
-
35
-

+ 0
- 198
ver_0.2/networks.py View File

@@ -1,198 +0,0 @@
1
-""" AlexNet.
2
-References:
3
-    - Alex Krizhevsky, Ilya Sutskever & Geoffrey E. Hinton. ImageNet
4
-    Classification with Deep Convolutional Neural Networks. NIPS, 2012.
5
-Links:
6
-    - [AlexNet Paper](http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf)
7
-"""
8
-
9
-def AlexNet(height, width, LR):
10
-
11
-	import tflearn
12
-	from tflearn.layers.core import input_data, dropout, fully_connected
13
-	from tflearn.layers.conv import conv_2d, max_pool_2d
14
-	from tflearn.layers.normalization import local_response_normalization
15
-	from tflearn.layers.estimator import regression
16
-
17
-	# Building 'AlexNet'
18
-	network = input_data(shape=[None, height, width, 1])
19
-	network = conv_2d(network, 96, 11, strides=4, activation='relu')
20
-	network = max_pool_2d(network, 3, strides=2)
21
-	network = local_response_normalization(network)
22
-	network = conv_2d(network, 256, 5, activation='relu')
23
-	network = max_pool_2d(network, 3, strides=2)
24
-	network = local_response_normalization(network)
25
-	network = conv_2d(network, 384, 3, activation='relu')
26
-	network = conv_2d(network, 384, 3, activation='relu')
27
-	network = conv_2d(network, 256, 3, activation='relu')
28
-	network = max_pool_2d(network, 3, strides=2)
29
-	network = local_response_normalization(network)
30
-	network = fully_connected(network, 4096, activation='tanh')
31
-	network = dropout(network, 0.5)
32
-	network = fully_connected(network, 4096, activation='tanh')
33
-	network = dropout(network, 0.5)
34
-	network = fully_connected(network, 1, activation='linear')
35
-
36
-	network = regression(network, optimizer='momentum',
37
-		             loss='mean_square',
38
-		             learning_rate=LR)
39
-	# Model
40
-	model = tflearn.DNN(network, checkpoint_path='model_alexnet',
41
-		            max_checkpoints=1, tensorboard_verbose=0)
42
-
43
-	return model
44
-
45
-	"""
46
-	model.fit(X, Y, n_epoch=1000, validation_set=0.1, shuffle=True,
47
-		  show_metric=True, batch_size=64, snapshot_step=200,
48
-		  snapshot_epoch=False, run_id='alexnet_oxflowers17')
49
-	"""
50
-
51
-
52
-def googLeNet(height, width, LR):
53
-
54
-	""" GoogLeNet.
55
-	References:
56
-	    - Szegedy, Christian, et al.
57
-	    Going deeper with convolutions.
58
-	Links:
59
-	    - [GoogLeNet Paper](http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Szegedy_Going_Deeper_With_2015_CVPR_paper.pdf)
60
-	"""
61
-
62
-	import tflearn
63
-	from tflearn.layers.core import input_data, dropout, fully_connected
64
-	from tflearn.layers.conv import conv_2d, max_pool_2d, avg_pool_2d
65
-	from tflearn.layers.normalization import local_response_normalization
66
-	from tflearn.layers.merge_ops import merge
67
-	from tflearn.layers.estimator import regression
68
-
69
-	network = input_data(shape=[None,height, width,1])
70
-	conv1_7_7 = conv_2d(network, 64, 7, strides=2, activation='relu', name = 'conv1_7_7_s2')
71
-	pool1_3_3 = max_pool_2d(conv1_7_7, 3,strides=2)
72
-	pool1_3_3 = local_response_normalization(pool1_3_3)
73
-	conv2_3_3_reduce = conv_2d(pool1_3_3, 64,1, activation='relu',name = 'conv2_3_3_reduce')
74
-	conv2_3_3 = conv_2d(conv2_3_3_reduce, 192,3, activation='relu', name='conv2_3_3')
75
-	conv2_3_3 = local_response_normalization(conv2_3_3)
76
-	pool2_3_3 = max_pool_2d(conv2_3_3, kernel_size=3, strides=2, name='pool2_3_3_s2')
77
-	inception_3a_1_1 = conv_2d(pool2_3_3, 64, 1, activation='relu', name='inception_3a_1_1')
78
-	inception_3a_3_3_reduce = conv_2d(pool2_3_3, 96,1, activation='relu', name='inception_3a_3_3_reduce')
79
-	inception_3a_3_3 = conv_2d(inception_3a_3_3_reduce, 128,filter_size=3,  activation='relu', name = 'inception_3a_3_3')
80
-	inception_3a_5_5_reduce = conv_2d(pool2_3_3,16, filter_size=1,activation='relu', name ='inception_3a_5_5_reduce' )
81
-	inception_3a_5_5 = conv_2d(inception_3a_5_5_reduce, 32, filter_size=5, activation='relu', name= 'inception_3a_5_5')
82
-	inception_3a_pool = max_pool_2d(pool2_3_3, kernel_size=3, strides=1, )
83
-	inception_3a_pool_1_1 = conv_2d(inception_3a_pool, 32, filter_size=1, activation='relu', name='inception_3a_pool_1_1')
84
-
85
-	# merge the inception_3a__
86
-	inception_3a_output = merge([inception_3a_1_1, inception_3a_3_3, inception_3a_5_5, inception_3a_pool_1_1], mode='concat', axis=3)
87
-
88
-	inception_3b_1_1 = conv_2d(inception_3a_output, 128,filter_size=1,activation='relu', name= 'inception_3b_1_1' )
89
-	inception_3b_3_3_reduce = conv_2d(inception_3a_output, 128, filter_size=1, activation='relu', name='inception_3b_3_3_reduce')
90
-	inception_3b_3_3 = conv_2d(inception_3b_3_3_reduce, 192, filter_size=3,  activation='relu',name='inception_3b_3_3')
91
-	inception_3b_5_5_reduce = conv_2d(inception_3a_output, 32, filter_size=1, activation='relu', name = 'inception_3b_5_5_reduce')
92
-	inception_3b_5_5 = conv_2d(inception_3b_5_5_reduce, 96, filter_size=5,  name = 'inception_3b_5_5')
93
-	inception_3b_pool = max_pool_2d(inception_3a_output, kernel_size=3, strides=1,  name='inception_3b_pool')
94
-	inception_3b_pool_1_1 = conv_2d(inception_3b_pool, 64, filter_size=1,activation='relu', name='inception_3b_pool_1_1')
95
-
96
-	#merge the inception_3b_*
97
-	inception_3b_output = merge([inception_3b_1_1, inception_3b_3_3, inception_3b_5_5, inception_3b_pool_1_1], mode='concat',axis=3,name='inception_3b_output')
98
-
99
-	pool3_3_3 = max_pool_2d(inception_3b_output, kernel_size=3, strides=2, name='pool3_3_3')
100
-	inception_4a_1_1 = conv_2d(pool3_3_3, 192, filter_size=1, activation='relu', name='inception_4a_1_1')
101
-	inception_4a_3_3_reduce = conv_2d(pool3_3_3, 96, filter_size=1, activation='relu', name='inception_4a_3_3_reduce')
102
-	inception_4a_3_3 = conv_2d(inception_4a_3_3_reduce, 208, filter_size=3,  activation='relu', name='inception_4a_3_3')
103
-	inception_4a_5_5_reduce = conv_2d(pool3_3_3, 16, filter_size=1, activation='relu', name='inception_4a_5_5_reduce')
104
-	inception_4a_5_5 = conv_2d(inception_4a_5_5_reduce, 48, filter_size=5,  activation='relu', name='inception_4a_5_5')
105
-	inception_4a_pool = max_pool_2d(pool3_3_3, kernel_size=3, strides=1,  name='inception_4a_pool')
106
-	inception_4a_pool_1_1 = conv_2d(inception_4a_pool, 64, filter_size=1, activation='relu', name='inception_4a_pool_1_1')
107
-
108
-	inception_4a_output = merge([inception_4a_1_1, inception_4a_3_3, inception_4a_5_5, inception_4a_pool_1_1], mode='concat', axis=3, name='inception_4a_output')
109
-
110
-
111
-	inception_4b_1_1 = conv_2d(inception_4a_output, 160, filter_size=1, activation='relu', name='inception_4a_1_1')
112
-	inception_4b_3_3_reduce = conv_2d(inception_4a_output, 112, filter_size=1, activation='relu', name='inception_4b_3_3_reduce')
113
-	inception_4b_3_3 = conv_2d(inception_4b_3_3_reduce, 224, filter_size=3, activation='relu', name='inception_4b_3_3')
114
-	inception_4b_5_5_reduce = conv_2d(inception_4a_output, 24, filter_size=1, activation='relu', name='inception_4b_5_5_reduce')
115
-	inception_4b_5_5 = conv_2d(inception_4b_5_5_reduce, 64, filter_size=5,  activation='relu', name='inception_4b_5_5')
116
-
117
-	inception_4b_pool = max_pool_2d(inception_4a_output, kernel_size=3, strides=1,  name='inception_4b_pool')
118
-	inception_4b_pool_1_1 = conv_2d(inception_4b_pool, 64, filter_size=1, activation='relu', name='inception_4b_pool_1_1')
119
-
120
-	inception_4b_output = merge([inception_4b_1_1, inception_4b_3_3, inception_4b_5_5, inception_4b_pool_1_1], mode='concat', axis=3, name='inception_4b_output')
121
-
122
-
123
-	inception_4c_1_1 = conv_2d(inception_4b_output, 128, filter_size=1, activation='relu',name='inception_4c_1_1')
124
-	inception_4c_3_3_reduce = conv_2d(inception_4b_output, 128, filter_size=1, activation='relu', name='inception_4c_3_3_reduce')
125
-	inception_4c_3_3 = conv_2d(inception_4c_3_3_reduce, 256,  filter_size=3, activation='relu', name='inception_4c_3_3')
126
-	inception_4c_5_5_reduce = conv_2d(inception_4b_output, 24, filter_size=1, activation='relu', name='inception_4c_5_5_reduce')
127
-	inception_4c_5_5 = conv_2d(inception_4c_5_5_reduce, 64,  filter_size=5, activation='relu', name='inception_4c_5_5')
128
-
129
-	inception_4c_pool = max_pool_2d(inception_4b_output, kernel_size=3, strides=1)
130
-	inception_4c_pool_1_1 = conv_2d(inception_4c_pool, 64, filter_size=1, activation='relu', name='inception_4c_pool_1_1')
131
-
132
-	inception_4c_output = merge([inception_4c_1_1, inception_4c_3_3, inception_4c_5_5, inception_4c_pool_1_1], mode='concat', axis=3,name='inception_4c_output')
133
-
134
-	inception_4d_1_1 = conv_2d(inception_4c_output, 112, filter_size=1, activation='relu', name='inception_4d_1_1')
135
-	inception_4d_3_3_reduce = conv_2d(inception_4c_output, 144, filter_size=1, activation='relu', name='inception_4d_3_3_reduce')
136
-	inception_4d_3_3 = conv_2d(inception_4d_3_3_reduce, 288, filter_size=3, activation='relu', name='inception_4d_3_3')
137
-	inception_4d_5_5_reduce = conv_2d(inception_4c_output, 32, filter_size=1, activation='relu', name='inception_4d_5_5_reduce')
138
-	inception_4d_5_5 = conv_2d(inception_4d_5_5_reduce, 64, filter_size=5,  activation='relu', name='inception_4d_5_5')
139
-	inception_4d_pool = max_pool_2d(inception_4c_output, kernel_size=3, strides=1,  name='inception_4d_pool')
140
-	inception_4d_pool_1_1 = conv_2d(inception_4d_pool, 64, filter_size=1, activation='relu', name='inception_4d_pool_1_1')
141
-
142
-	inception_4d_output = merge([inception_4d_1_1, inception_4d_3_3, inception_4d_5_5, inception_4d_pool_1_1], mode='concat', axis=3, name='inception_4d_output')
143
-
144
-	inception_4e_1_1 = conv_2d(inception_4d_output, 256, filter_size=1, activation='relu', name='inception_4e_1_1')
145
-	inception_4e_3_3_reduce = conv_2d(inception_4d_output, 160, filter_size=1, activation='relu', name='inception_4e_3_3_reduce')
146
-	inception_4e_3_3 = conv_2d(inception_4e_3_3_reduce, 320, filter_size=3, activation='relu', name='inception_4e_3_3')
147
-	inception_4e_5_5_reduce = conv_2d(inception_4d_output, 32, filter_size=1, activation='relu', name='inception_4e_5_5_reduce')
148
-	inception_4e_5_5 = conv_2d(inception_4e_5_5_reduce, 128,  filter_size=5, activation='relu', name='inception_4e_5_5')
149
-	inception_4e_pool = max_pool_2d(inception_4d_output, kernel_size=3, strides=1,  name='inception_4e_pool')
150
-	inception_4e_pool_1_1 = conv_2d(inception_4e_pool, 128, filter_size=1, activation='relu', name='inception_4e_pool_1_1')
151
-
152
-
153
-	inception_4e_output = merge([inception_4e_1_1, inception_4e_3_3, inception_4e_5_5,inception_4e_pool_1_1],axis=3, mode='concat')
154
-
155
-	pool4_3_3 = max_pool_2d(inception_4e_output, kernel_size=3, strides=2, name='pool_3_3')
156
-
157
-
158
-	inception_5a_1_1 = conv_2d(pool4_3_3, 256, filter_size=1, activation='relu', name='inception_5a_1_1')
159
-	inception_5a_3_3_reduce = conv_2d(pool4_3_3, 160, filter_size=1, activation='relu', name='inception_5a_3_3_reduce')
160
-	inception_5a_3_3 = conv_2d(inception_5a_3_3_reduce, 320, filter_size=3, activation='relu', name='inception_5a_3_3')
161
-	inception_5a_5_5_reduce = conv_2d(pool4_3_3, 32, filter_size=1, activation='relu', name='inception_5a_5_5_reduce')
162
-	inception_5a_5_5 = conv_2d(inception_5a_5_5_reduce, 128, filter_size=5,  activation='relu', name='inception_5a_5_5')
163
-	inception_5a_pool = max_pool_2d(pool4_3_3, kernel_size=3, strides=1,  name='inception_5a_pool')
164
-	inception_5a_pool_1_1 = conv_2d(inception_5a_pool, 128, filter_size=1,activation='relu', name='inception_5a_pool_1_1')
165
-
166
-	inception_5a_output = merge([inception_5a_1_1, inception_5a_3_3, inception_5a_5_5, inception_5a_pool_1_1], axis=3,mode='concat')
167
-
168
-
169
-	inception_5b_1_1 = conv_2d(inception_5a_output, 384, filter_size=1,activation='relu', name='inception_5b_1_1')
170
-	inception_5b_3_3_reduce = conv_2d(inception_5a_output, 192, filter_size=1, activation='relu', name='inception_5b_3_3_reduce')
171
-	inception_5b_3_3 = conv_2d(inception_5b_3_3_reduce, 384,  filter_size=3,activation='relu', name='inception_5b_3_3')
172
-	inception_5b_5_5_reduce = conv_2d(inception_5a_output, 48, filter_size=1, activation='relu', name='inception_5b_5_5_reduce')
173
-	inception_5b_5_5 = conv_2d(inception_5b_5_5_reduce,128, filter_size=5,  activation='relu', name='inception_5b_5_5' )
174
-	inception_5b_pool = max_pool_2d(inception_5a_output, kernel_size=3, strides=1,  name='inception_5b_pool')
175
-	inception_5b_pool_1_1 = conv_2d(inception_5b_pool, 128, filter_size=1, activation='relu', name='inception_5b_pool_1_1')
176
-	inception_5b_output = merge([inception_5b_1_1, inception_5b_3_3, inception_5b_5_5, inception_5b_pool_1_1], axis=3, mode='concat')
177
-
178
-	pool5_7_7 = avg_pool_2d(inception_5b_output, kernel_size=7, strides=1)
179
-	pool5_7_7 = dropout(pool5_7_7, 0.4)
180
-
181
-	loss = fully_connected(pool5_7_7, 1,activation='linear')
182
-
183
-	network = regression(loss, optimizer='momentum',
184
-		             loss='mean_square',
185
-		             learning_rate=LR)
186
-
187
-	model = tflearn.DNN(network, checkpoint_path='model_googlenet',
188
-		            max_checkpoints=1, tensorboard_verbose=0)
189
-
190
-	return model
191
-	
192
-	'''
193
-	model.fit(X, Y, n_epoch=1000, validation_set=0.1, shuffle=True,
194
-		  show_metric=True, batch_size=64, snapshot_step=200,
195
-		  snapshot_epoch=False, run_id='googlenet_oxflowers17')
196
-	'''
197
-
198
-

+ 0
- 35
ver_0.2/train_network.py View File

@@ -1,35 +0,0 @@
1
-import numpy as np
2
-import os
3
-import cv2
4
-import time
5
-from random import shuffle
6
-
7
-from networks import AlexNet
8
-
9
-WIDTH = 256
10
-HEIGHT = 66
11
-LR = 1e-3
12
-EPOCHS = 10
13
-MODEL_NAME = 'Self-Steering-Car-{}-{}-{}-epochs.model'.format('AlexNet', LR , EPOCHS)
14
-
15
-model = AlexNet(HEIGHT,WIDTH, LR)
16
-
17
-# start training
18
-file_list = os.listdir('/raw_data')
19
-for file in file_list:
20
-	if file.endswith('.npy'):
21
-		print("Start training on file : " + file)
22
-		file_location = "/raw_data/" + file
23
-		loaded_data = np.load(file_location)
24
-
25
-		train = loaded_data[:-100]
26
-		test = loaded_data[-100:]
27
-
28
-		X = np.array([i[0][70:-5,::] for i in train]).reshape(-1, HEIGHT,WIDTH,1)
29
-		Y = np.array([i[1] for i in train]).reshape(-1,1)
30
-
31
-		val_X = np.array([i[0][70:-5,::] for i in test]).reshape(-1, HEIGHT,WIDTH,1)
32
-		val_Y = np.array([i[1] for i in test]).reshape(-1,1)
33
-
34
-		model.fit(X, Y, n_epoch=EPOCHS, run_id=MODEL_NAME, show_metric=True, validation_set=(val_X,val_Y))
35
-		model.save(MODEL_NAME)

+ 0
- 2
ver_0.3/can.sh View File

@@ -1,2 +0,0 @@
1
-sudo ip link set can0 type can bitrate 500000
2
-sudo ip link set up can0

+ 0
- 78
ver_0.3/collect_raw_data.py View File

@@ -1,78 +0,0 @@
1
-import numpy as np
2
-import cv2
3
-import time
4
-import os
5
-import can
6
-import signal
7
-import sys
8
-
9
-bus = can.interface.Bus(channel='can0', bustype='socketcan_native')
10
-
11
-cap = cv2.VideoCapture(0)
12
-cap.set(3,300) # set height
13
-cap.set(4,200) # set width
14
-
15
-raw_data = []
16
-
17
-def signal_handler(signal, frame):
18
-	name = str(time.time())
19
-	file_name = "/raw_data/" + name + ".npy"
20
-	np.save(file_name,raw_data)
21
-	print("saved {} frame, name : {}".format(len(raw_data),name))
22
-	sys.exit(0)
23
- 
24
-signal.signal(signal.SIGINT, signal_handler)
25
-
26
-def get_frame():
27
-	# read the frame from webcam
28
-	_, frame = cap.read()
29
-
30
-	# change the color to gray
31
-	#frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
32
-
33
-	# change the resolution (256*141), later cut the sky
34
-	frame = cv2.resize(frame,(0,0),fx=0.8, fy=0.8)
35
-	
36
-	return frame
37
-
38
-def get_angle():
39
-    while(True):
40
-	# get one can data
41
-        can_data = str(bus.recv())
42
-	# check it is steering angle, if yes then stop the loop
43
-        if(can_data.find("ID: 0025") > 0):
44
-            break
45
-
46
-    return can_data
47
-
48
-def main():
49
-
50
-	# discard first 40 frames to give time for webcam to get the proper exposure
51
-	for i in range(40):
52
-			get_angle()
53
-			get_frame()
54
-			print(i, "discarded")
55
-
56
-	while True:
57
-		angle = get_angle()
58
-		frame = get_frame()
59
-		raw_data.append([frame, angle])
60
-
61
-		print(frame.shape[0], frame.shape[1], angle)
62
-		
63
-		if len(raw_data) > 5000:
64
-			pid = os.fork()
65
-			if pid == 0:
66
-				name = str(time.time())
67
-				file_name = "/raw_data/" + name + ".npy"
68
-				np.save(file_name,raw_data)
69
-				print("saved {} frame, name : {}".format(len(raw_data),name))
70
-				exit(0)
71
-			else:
72
-				raw_data = []
73
-			
74
-
75
-main()
76
-
77
-cap.release()
78
-# cv2.destroyAllWindows()

+ 0
- 2
ver_0.3/data_size.txt View File

@@ -1,2 +0,0 @@
1
-width : 256
2
-height : 141

+ 0
- 65
ver_0.3/eval_model.py View File

@@ -1,65 +0,0 @@
1
-import numpy as np
2
-import os
3
-
4
-from networks import googLeNet
5
-
6
-WIDTH = 66
7
-HEIGHT = 256
8
-LR = 1e-3
9
-EPOCHS = 10
10
-MODEL_NAME = 'Self-Steering-Car-{}-{}-{}-epochs.model'.format('googLeNet', LR , EPOCHS)
11
-
12
-model = googLeNet(WIDTH, HEIGHT, LR)
13
-
14
-
15
-# make evaluation data
16
-eval_x = []
17
-eval_y = []
18
-file_list = os.listdir('/raw_data/eval_data')
19
-for file in file_list:
20
-	if file.endswith('.npy'):
21
-		file_location = "/raw_data/eval_data/" + file
22
-		file = np.load(file_location)
23
-
24
-		temp_x = []
25
-	
26
-		for data in file:
27
-			frame = (data[0][70:-5,::]).reshape(66,256,1)
28
-			#cv2.imshow('frame', frame)
29
-			
30
-
31
-			if len(temp_x) == 0:
32
-				temp_x = frame
33
-				#print(temp_x.shape)
34
-			elif temp_x.shape[2] < 4:
35
-				temp_x = np.concatenate((temp_x, frame), axis=2)
36
-				#print(temp_x.shape)
37
-			else:
38
-				if temp_x.shape[2] == 4:
39
-					temp_x = np.concatenate((temp_x, frame), axis=2)
40
-					#print(temp_x.shape)
41
-					eval_x.append([temp_x])
42
-					eval_y.append([data[1]])
43
-				else:
44
-					temp_x = temp_x[::,::,-4:]
45
-					#print(temp_x.shape)
46
-					temp_x = np.concatenate((temp_x, frame), axis=2)
47
-					#print(temp_x.shape)
48
-					eval_x.append([temp_x])
49
-					eval_y.append([data[1]])
50
-
51
-eval_x = np.array(eval_x).reshape(-1,66,256,5)
52
-#print(eval_x.shape)
53
-eval_y = np.array(eval_y)
54
-#print(eval_y.shape)
55
-# finish makeing evaluation data
56
-
57
-model.load(MODEL_NAME)
58
-
59
-eval = model.evaluate(eval_x, eval_y)
60
-
61
-print(eval)
62
-
63
-
64
-
65
-

+ 0
- 43
ver_0.3/get_cam.py View File

@@ -1,43 +0,0 @@
1
-import numpy as np
2
-import cv2
3
-
4
-cap = cv2.VideoCapture(0)
5
-cap.set(3,350) # set height
6
-cap.set(4,200) # set width
7
-
8
-def get_frame():
9
-    # read the frame from webcam
10
-    _, frame = cap.read()
11
-
12
-    # change the color to gray
13
-    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
14
-
15
-    # webcam is install in car upside down, so flip the image
16
-    frame = cv2.flip(frame,0)
17
-    frame = cv2.flip(frame,1)
18
-
19
-    # cut the top part of image because it is sky and bottom of image
20
-    # frame = frame[150:-15,::]
21
-
22
-    # resize the image by 80% to make it right size to feed into CNN
23
-    frame = cv2.resize(frame,(0,0),fx=0.8, fy=0.8)
24
-
25
-    # print(frame.shape)
26
-    # cv2.imshow('frame',frame)
27
-    # if cv2.waitKey(1) & 0xFF == ord('q'):
28
-    #     break
29
-
30
-    return frame
31
-
32
-def main():
33
-    while True:
34
-        frame = get_frame()
35
-
36
-        print(frame.shape[0], frame.shape[1])
37
-        # if cv2.waitKey(1) & 0xFF == ord('q'):
38
-        #     break   
39
-
40
-main()
41
-
42
-cap.release()
43
-# cv2.destroyAllWindows()

+ 0
- 14
ver_0.3/get_can_bus.py View File

@@ -1,14 +0,0 @@
1
-import can 
2
-bus = can.interface.Bus(channel='can0', bustype='socketcan_native') 
3
-
4
-while(True):
5
-	notifier = str(bus.recv())
6
-	if(notifier.find("ID: 0025") > 0):
7
-		hex_data = notifier[-23:-21] + notifier[-20:-18]
8
-		int_data = int(hex_data, 16)
9
-		if(int_data == 0):
10
-			pass
11
-		elif(int_data > 500):
12
-			int_data = int_data - 4096
13
-
14
-		print(int_data)

+ 0
- 1
ver_0.3/mount.sh View File

@@ -1 +0,0 @@
1
-sudo mount /dev/mmcblk1p1 /raw_data

+ 0
- 198
ver_0.3/networks.py View File

@@ -1,198 +0,0 @@
1
-import tflearn
2
-from tflearn.layers.core import input_data, dropout, fully_connected
3
-from tflearn.layers.conv import conv_2d, max_pool_2d, avg_pool_2d
4
-from tflearn.layers.normalization import local_response_normalization, batch_normalization
5
-from tflearn.layers.merge_ops import merge
6
-from tflearn.layers.estimator import regression
7
-
8
-from tflearn.layers.core import input_data, dropout, fully_connected
9
-from tflearn.layers.conv import conv_2d, max_pool_2d
10
-from tflearn.layers.normalization import local_response_normalization
11
-from tflearn.layers.estimator import regression
12
-
13
-def AlexNet(height, width,channel, LR):
14
-	# Building 'AlexNet'
15
-	network = input_data(shape=[None, height, width, channel])
16
-
17
-	network = batch_normalization(network)
18
-
19
-	network = conv_2d(network, 96, 11, strides=4, activation='relu')
20
-	network = max_pool_2d(network, 3, strides=2)
21
-
22
-	network = local_response_normalization(network)
23
-
24
-	network = conv_2d(network, 256, 5, activation='relu')
25
-	network = max_pool_2d(network, 3, strides=2)
26
-
27
-	network = local_response_normalization(network)
28
-
29
-	network = conv_2d(network, 384, 3, activation='relu')
30
-	network = conv_2d(network, 384, 3, activation='relu')
31
-	network = conv_2d(network, 256, 3, activation='relu')
32
-	network = max_pool_2d(network, 3, strides=2)
33
-
34
-	network = local_response_normalization(network)
35
-
36
-	network = fully_connected(network, 4096, activation='relu')
37
-	network = dropout(network, 0.5)
38
-	network = fully_connected(network, 2048, activation='relu')
39
-	network = dropout(network, 0.5)
40
-	network = fully_connected(network, 1024, activation='relu')
41
-	network = dropout(network, 0.5)
42
-	network = fully_connected(network, 512, activation='relu')
43
-	network = dropout(network, 0.5)
44
-	network = fully_connected(network, 256, activation='relu')
45
-	network = dropout(network, 0.5)
46
-	network = fully_connected(network, 50, activation='relu')
47
-
48
-	network = fully_connected(network, 1, activation='linear')
49
-
50
-	network = regression(network, optimizer='momentum',
51
-		             loss='mean_square',
52
-		             learning_rate=LR)
53
-
54
-	# Training
55
-	model = tflearn.DNN(network, checkpoint_path='model_alexnet',
56
-		            max_checkpoints=1, tensorboard_verbose=0)
57
-
58
-	return model
59
-
60
-def googLeNet(height, width, LR):
61
-
62
-	""" GoogLeNet.
63
-	References:
64
-	    - Szegedy, Christian, et al.
65
-	    Going deeper with convolutions.
66
-	Links:
67
-	    - [GoogLeNet Paper](http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Szegedy_Going_Deeper_With_2015_CVPR_paper.pdf)
68
-	"""
69
-	# image in the array form the height comes first and then the width
70
-	network = input_data(shape=[None, height, width, 1])
71
-	conv1_7_7 = conv_2d(network, 64, 7, strides=2, activation='relu', name = 'conv1_7_7_s2')
72
-	pool1_3_3 = max_pool_2d(conv1_7_7, 3,strides=2)
73
-	pool1_3_3 = local_response_normalization(pool1_3_3)
74
-	conv2_3_3_reduce = conv_2d(pool1_3_3, 64,1, activation='relu',name = 'conv2_3_3_reduce')
75
-	conv2_3_3 = conv_2d(conv2_3_3_reduce, 192,3, activation='relu', name='conv2_3_3')
76
-	conv2_3_3 = local_response_normalization(conv2_3_3)
77
-	pool2_3_3 = max_pool_2d(conv2_3_3, kernel_size=3, strides=2, name='pool2_3_3_s2')
78
-	inception_3a_1_1 = conv_2d(pool2_3_3, 64, 1, activation='relu', name='inception_3a_1_1')
79
-	inception_3a_3_3_reduce = conv_2d(pool2_3_3, 96,1, activation='relu', name='inception_3a_3_3_reduce')
80
-	inception_3a_3_3 = conv_2d(inception_3a_3_3_reduce, 128,filter_size=3,  activation='relu', name = 'inception_3a_3_3')
81
-	inception_3a_5_5_reduce = conv_2d(pool2_3_3,16, filter_size=1,activation='relu', name ='inception_3a_5_5_reduce' )
82
-	inception_3a_5_5 = conv_2d(inception_3a_5_5_reduce, 32, filter_size=5, activation='relu', name= 'inception_3a_5_5')
83
-	inception_3a_pool = max_pool_2d(pool2_3_3, kernel_size=3, strides=1, )
84
-	inception_3a_pool_1_1 = conv_2d(inception_3a_pool, 32, filter_size=1, activation='relu', name='inception_3a_pool_1_1')
85
-
86
-	# merge the inception_3a__
87
-	inception_3a_output = merge([inception_3a_1_1, inception_3a_3_3, inception_3a_5_5, inception_3a_pool_1_1], mode='concat', axis=3)
88
-
89
-	inception_3b_1_1 = conv_2d(inception_3a_output, 128,filter_size=1,activation='relu', name= 'inception_3b_1_1' )
90
-	inception_3b_3_3_reduce = conv_2d(inception_3a_output, 128, filter_size=1, activation='relu', name='inception_3b_3_3_reduce')
91
-	inception_3b_3_3 = conv_2d(inception_3b_3_3_reduce, 192, filter_size=3,  activation='relu',name='inception_3b_3_3')
92
-	inception_3b_5_5_reduce = conv_2d(inception_3a_output, 32, filter_size=1, activation='relu', name = 'inception_3b_5_5_reduce')
93
-	inception_3b_5_5 = conv_2d(inception_3b_5_5_reduce, 96, filter_size=5,  name = 'inception_3b_5_5')
94
-	inception_3b_pool = max_pool_2d(inception_3a_output, kernel_size=3, strides=1,  name='inception_3b_pool')
95
-	inception_3b_pool_1_1 = conv_2d(inception_3b_pool, 64, filter_size=1,activation='relu', name='inception_3b_pool_1_1')
96
-
97
-	#merge the inception_3b_*
98
-	inception_3b_output = merge([inception_3b_1_1, inception_3b_3_3, inception_3b_5_5, inception_3b_pool_1_1], mode='concat',axis=3,name='inception_3b_output')
99
-
100
-	pool3_3_3 = max_pool_2d(inception_3b_output, kernel_size=3, strides=2, name='pool3_3_3')
101
-	inception_4a_1_1 = conv_2d(pool3_3_3, 192, filter_size=1, activation='relu', name='inception_4a_1_1')
102
-	inception_4a_3_3_reduce = conv_2d(pool3_3_3, 96, filter_size=1, activation='relu', name='inception_4a_3_3_reduce')
103
-	inception_4a_3_3 = conv_2d(inception_4a_3_3_reduce, 208, filter_size=3,  activation='relu', name='inception_4a_3_3')
104
-	inception_4a_5_5_reduce = conv_2d(pool3_3_3, 16, filter_size=1, activation='relu', name='inception_4a_5_5_reduce')
105
-	inception_4a_5_5 = conv_2d(inception_4a_5_5_reduce, 48, filter_size=5,  activation='relu', name='inception_4a_5_5')
106
-	inception_4a_pool = max_pool_2d(pool3_3_3, kernel_size=3, strides=1,  name='inception_4a_pool')
107
-	inception_4a_pool_1_1 = conv_2d(inception_4a_pool, 64, filter_size=1, activation='relu', name='inception_4a_pool_1_1')
108
-
109
-	inception_4a_output = merge([inception_4a_1_1, inception_4a_3_3, inception_4a_5_5, inception_4a_pool_1_1], mode='concat', axis=3, name='inception_4a_output')
110
-
111
-
112
-	inception_4b_1_1 = conv_2d(inception_4a_output, 160, filter_size=1, activation='relu', name='inception_4a_1_1')
113
-	inception_4b_3_3_reduce = conv_2d(inception_4a_output, 112, filter_size=1, activation='relu', name='inception_4b_3_3_reduce')
114
-	inception_4b_3_3 = conv_2d(inception_4b_3_3_reduce, 224, filter_size=3, activation='relu', name='inception_4b_3_3')
115
-	inception_4b_5_5_reduce = conv_2d(inception_4a_output, 24, filter_size=1, activation='relu', name='inception_4b_5_5_reduce')
116
-	inception_4b_5_5 = conv_2d(inception_4b_5_5_reduce, 64, filter_size=5,  activation='relu', name='inception_4b_5_5')
117
-
118
-	inception_4b_pool = max_pool_2d(inception_4a_output, kernel_size=3, strides=1,  name='inception_4b_pool')
119
-	inception_4b_pool_1_1 = conv_2d(inception_4b_pool, 64, filter_size=1, activation='relu', name='inception_4b_pool_1_1')
120
-
121
-	inception_4b_output = merge([inception_4b_1_1, inception_4b_3_3, inception_4b_5_5, inception_4b_pool_1_1], mode='concat', axis=3, name='inception_4b_output')
122
-
123
-
124
-	inception_4c_1_1 = conv_2d(inception_4b_output, 128, filter_size=1, activation='relu',name='inception_4c_1_1')
125
-	inception_4c_3_3_reduce = conv_2d(inception_4b_output, 128, filter_size=1, activation='relu', name='inception_4c_3_3_reduce')
126
-	inception_4c_3_3 = conv_2d(inception_4c_3_3_reduce, 256,  filter_size=3, activation='relu', name='inception_4c_3_3')
127
-	inception_4c_5_5_reduce = conv_2d(inception_4b_output, 24, filter_size=1, activation='relu', name='inception_4c_5_5_reduce')
128
-	inception_4c_5_5 = conv_2d(inception_4c_5_5_reduce, 64,  filter_size=5, activation='relu', name='inception_4c_5_5')
129
-
130
-	inception_4c_pool = max_pool_2d(inception_4b_output, kernel_size=3, strides=1)
131
-	inception_4c_pool_1_1 = conv_2d(inception_4c_pool, 64, filter_size=1, activation='relu', name='inception_4c_pool_1_1')
132
-
133
-	inception_4c_output = merge([inception_4c_1_1, inception_4c_3_3, inception_4c_5_5, inception_4c_pool_1_1], mode='concat', axis=3,name='inception_4c_output')
134
-
135
-	inception_4d_1_1 = conv_2d(inception_4c_output, 112, filter_size=1, activation='relu', name='inception_4d_1_1')
136
-	inception_4d_3_3_reduce = conv_2d(inception_4c_output, 144, filter_size=1, activation='relu', name='inception_4d_3_3_reduce')
137
-	inception_4d_3_3 = conv_2d(inception_4d_3_3_reduce, 288, filter_size=3, activation='relu', name='inception_4d_3_3')
138
-	inception_4d_5_5_reduce = conv_2d(inception_4c_output, 32, filter_size=1, activation='relu', name='inception_4d_5_5_reduce')
139
-	inception_4d_5_5 = conv_2d(inception_4d_5_5_reduce, 64, filter_size=5,  activation='relu', name='inception_4d_5_5')
140
-	inception_4d_pool = max_pool_2d(inception_4c_output, kernel_size=3, strides=1,  name='inception_4d_pool')
141
-	inception_4d_pool_1_1 = conv_2d(inception_4d_pool, 64, filter_size=1, activation='relu', name='inception_4d_pool_1_1')
142
-
143
-	inception_4d_output = merge([inception_4d_1_1, inception_4d_3_3, inception_4d_5_5, inception_4d_pool_1_1], mode='concat', axis=3, name='inception_4d_output')
144
-
145
-	inception_4e_1_1 = conv_2d(inception_4d_output, 256, filter_size=1, activation='relu', name='inception_4e_1_1')
146
-	inception_4e_3_3_reduce = conv_2d(inception_4d_output, 160, filter_size=1, activation='relu', name='inception_4e_3_3_reduce')
147
-	inception_4e_3_3 = conv_2d(inception_4e_3_3_reduce, 320, filter_size=3, activation='relu', name='inception_4e_3_3')
148
-	inception_4e_5_5_reduce = conv_2d(inception_4d_output, 32, filter_size=1, activation='relu', name='inception_4e_5_5_reduce')
149
-	inception_4e_5_5 = conv_2d(inception_4e_5_5_reduce, 128,  filter_size=5, activation='relu', name='inception_4e_5_5')
150
-	inception_4e_pool = max_pool_2d(inception_4d_output, kernel_size=3, strides=1,  name='inception_4e_pool')
151
-	inception_4e_pool_1_1 = conv_2d(inception_4e_pool, 128, filter_size=1, activation='relu', name='inception_4e_pool_1_1')
152
-
153
-
154
-	inception_4e_output = merge([inception_4e_1_1, inception_4e_3_3, inception_4e_5_5,inception_4e_pool_1_1],axis=3, mode='concat')
155
-
156
-	pool4_3_3 = max_pool_2d(inception_4e_output, kernel_size=3, strides=2, name='pool_3_3')
157
-
158
-
159
-	inception_5a_1_1 = conv_2d(pool4_3_3, 256, filter_size=1, activation='relu', name='inception_5a_1_1')
160
-	inception_5a_3_3_reduce = conv_2d(pool4_3_3, 160, filter_size=1, activation='relu', name='inception_5a_3_3_reduce')
161
-	inception_5a_3_3 = conv_2d(inception_5a_3_3_reduce, 320, filter_size=3, activation='relu', name='inception_5a_3_3')
162
-	inception_5a_5_5_reduce = conv_2d(pool4_3_3, 32, filter_size=1, activation='relu', name='inception_5a_5_5_reduce')
163
-	inception_5a_5_5 = conv_2d(inception_5a_5_5_reduce, 128, filter_size=5,  activation='relu', name='inception_5a_5_5')
164
-	inception_5a_pool = max_pool_2d(pool4_3_3, kernel_size=3, strides=1,  name='inception_5a_pool')
165
-	inception_5a_pool_1_1 = conv_2d(inception_5a_pool, 128, filter_size=1,activation='relu', name='inception_5a_pool_1_1')
166
-
167
-	inception_5a_output = merge([inception_5a_1_1, inception_5a_3_3, inception_5a_5_5, inception_5a_pool_1_1], axis=3,mode='concat')
168
-
169
-
170
-	inception_5b_1_1 = conv_2d(inception_5a_output, 384, filter_size=1,activation='relu', name='inception_5b_1_1')
171
-	inception_5b_3_3_reduce = conv_2d(inception_5a_output, 192, filter_size=1, activation='relu', name='inception_5b_3_3_reduce')
172
-	inception_5b_3_3 = conv_2d(inception_5b_3_3_reduce, 384,  filter_size=3,activation='relu', name='inception_5b_3_3')
173
-	inception_5b_5_5_reduce = conv_2d(inception_5a_output, 48, filter_size=1, activation='relu', name='inception_5b_5_5_reduce')
174
-	inception_5b_5_5 = conv_2d(inception_5b_5_5_reduce,128, filter_size=5,  activation='relu', name='inception_5b_5_5' )
175
-	inception_5b_pool = max_pool_2d(inception_5a_output, kernel_size=3, strides=1,  name='inception_5b_pool')
176
-	inception_5b_pool_1_1 = conv_2d(inception_5b_pool, 128, filter_size=1, activation='relu', name='inception_5b_pool_1_1')
177
-	inception_5b_output = merge([inception_5b_1_1, inception_5b_3_3, inception_5b_5_5, inception_5b_pool_1_1], axis=3, mode='concat')
178
-
179
-	pool5_7_7 = avg_pool_2d(inception_5b_output, kernel_size=7, strides=1)
180
-	#pool5_7_7 = dropout(pool5_7_7, 0.4)
181
-
182
-	loss = fully_connected(pool5_7_7, 1, activation='linear')
183
-
184
-	network = regression(loss, optimizer='adam',
185
-		             loss='mean_square',
186
-		             learning_rate=LR)
187
-
188
-	model = tflearn.DNN(network, tensorboard_verbose=0)
189
-
190
-	return model
191
-	
192
-	'''
193
-	model.fit(X, Y, n_epoch=1000, validation_set=0.1, shuffle=True,
194
-		  show_metric=True, batch_size=64, snapshot_step=200,
195
-		  snapshot_epoch=False, run_id='googlenet_oxflowers17')
196
-	'''
197
-
198
-

+ 0
- 126
ver_0.3/train_network.py View File

@@ -1,126 +0,0 @@
1
-import numpy as np
2
-import os
3
-import cv2
4
-import time
5
-
6
-WIDTH = 256
7
-HEIGHT = 66
8
-CHANNEL = 1
9
-
10
-from networks import googLeNet, AlexNet
11
-
12
-LR = 1e-2
13
-EPOCHS = 10
14
-MODEL_NAME = 'Self-Steering-Car-{}-{}-{}-epochs.model'.format('AlexNet', LR , EPOCHS)
15
-
16
-model = AlexNet(HEIGHT,WIDTH,CHANNEL, LR)
17
-
18
-# make the eval data
19
-file_list = os.listdir('/raw_data/eval_data')
20
-for file in file_list:
21
-	if file.endswith('.npy'):
22
-		file_location = "/raw_data/eval_data/" + file
23
-		loaded_data = np.load(file_location)
24
-
25
-		for data in loaded_data:
26
-			tmp = cv2.flip(data[0],0)
27
-			tmp = cv2.flip(tmp,1)
28
-			if CHANNEL == 1:
29
-				tmp = cv2.cvtColor(tmp, cv2.COLOR_BGR2GRAY)
30
-			data[0] = (tmp[70:-5,::]).reshape(HEIGHT,WIDTH,CHANNEL)
31
-
32
-			# change the can data (HEX) to numerical data
33
-			tmp = data[1]
34
-			hex_data = tmp[-23:-21] + tmp[-20:-18]
35
-			hex_decimal = tmp[-3:-1]
36
-			int_data = int(hex_data, 16)
37
-			int_decimal = int(hex_decimal, 16)
38
-			
39
-			# if the steering wheel angle in in right to the center
40
-			if(int_data > 550):
41
-				int_data = int_data - 4096
42
-				int_decimal = 256 - int_decimal 
43
-			
44
-			# put the int and the decimal together
45
-			num_in_string = str(int_data) + "." + str(int_decimal)
46
-			final_data = float(num_in_string)
47
-			data[1] = final_data
48
-		
49
-		loaded_data = loaded_data[30:]
50
-		val_X = np.array([i[0] for i in loaded_data]).reshape([-1, HEIGHT,WIDTH,CHANNEL])
51
-		val_Y = np.array([i[1] for i in loaded_data]).reshape([-1,1])
52
-
53
-# prepare data for training
54
-file_list = os.listdir('/raw_data')
55
-
56
-for file in file_list:
57
-	if file.endswith('.npy'):
58
-		print("Start training on file : " + file)
59
-		file_location = "/raw_data/" + file
60
-		loaded_data = np.load(file_location)
61
-
62
-		# change the saved data into the form that both human and NN can understand
63
-		for data in loaded_data:
64
-			# flip the frame because the webcam is mounted upside down on the front windsheild, and cut out the sky portion of the image the size became 256*66
65
-			tmp = cv2.flip(data[0],0)
66
-			tmp = cv2.flip(tmp,1)
67
-			if CHANNEL == 1:
68
-				tmp = cv2.cvtColor(tmp, cv2.COLOR_BGR2GRAY)
69
-			data[0] = (tmp[70:-5,::]).reshape(HEIGHT,WIDTH,CHANNEL)
70
-
71
-
72
-			'''
73
-			Example of interpreting the can steering data
74
-			1) left:
75
-				Timestamp: 1501251285.664896        ID: 0025    000    DLC: 8    
76
-				00 03 30 01 bf ce 00 ee
77
-				[-23:-21][-20:-18][-17:-15][-14:-12][-11:-9][-8:-7][-6:-4][-3:-1]
78
-				first two bytes are the int before decimal and last one byte is decimal
79
-			'''
80
-
81
-			# change the can data (HEX) to numerical data
82
-			tmp = data[1]
83
-			hex_data = tmp[-23:-21] + tmp[-20:-18]
84
-			hex_decimal = tmp[-3:-1]
85
-			int_data = int(hex_data, 16)
86
-			int_decimal = int(hex_decimal, 16)
87
-			
88
-			# if the steering wheel angle in in right to the center
89
-			if(int_data > 550):
90
-				int_data = int_data - 4096
91
-				int_decimal = 256 - int_decimal 
92
-			
93
-			# put the int and the decimal together
94
-			num_in_string = str(int_data) + "." + str(int_decimal)
95
-			final_data = float(num_in_string)
96
-			data[1] = final_data
97
-			#print(final_data)
98
-			'''
99
-			cv2.imshow('frame', data[0])
100
-			if cv2.waitKey(1) & 0xFF == ord('q'):
101
-				break
102
-			print(data[1])
103
-
104
-			time.sleep(0.1)
105
-			'''
106
-		#did cut out the first few frames because the webcam need time to adjust the exposure
107
-		# but seems like still the white out frames exist
108
-
109
-		loaded_data = loaded_data[30:]
110
-		train_X = np.array([i[0] for i in loaded_data]).reshape([-1, HEIGHT,WIDTH,CHANNEL])
111
-		train_Y = np.array([i[1] for i in loaded_data]).reshape([-1,1])
112
-		'''
113
-		for frame in train_X:
114
-			cv2.imshow('frame', frame)
115
-			if cv2.waitKey(1) & 0xFF == ord('q'):
116
-				break
117
-		'''
118
-#finishing making the training data
119
-
120
-
121
-		# train the network
122
-		model.fit(train_X, train_Y, n_epoch=EPOCHS, run_id=MODEL_NAME, show_metric=True, validation_set=(val_X,val_Y))
123
-
124
-		model.save(MODEL_NAME)
125
-
126
-

+ 0
- 37
ver_0.3/visualize_raw_data.py View File

@@ -1,37 +0,0 @@
1
-import os
2
-import cv2
3
-import numpy as np
4
-import time
5
-
6
-'''
7
-original data
8
-width : 256
9
-height : 141
10
-'''
11
-
12
-file_list = os.listdir('/raw_data')
13
-#print(data_list)
14
-
15
-for file in file_list:
16
-	if file.endswith('.npy'):
17
-		print(file)
18
-		file_location = "/raw_data/" + file
19
-		loaded_data = np.load(file_location)
20
-
21
-		for data in loaded_data:
22
-			tmp = cv2.flip(data[0],0)
23
-			tmp = cv2.flip(tmp,1)
24
-			frame = tmp[70:-5,::]
25
-			cv2.imshow('frame', frame)
26
-			print(frame.shape, data[1])
27
-		
28
-			if cv2.waitKey(1) & 0xFF == ord('q'):
29
-				break
30
-
31
-'''
32
-data after resize
33
-width : 256
34
-height : 66
35
-'''
36
-
37
-

+ 0
- 91
ver_0.4/DT_network.py View File

@@ -1,91 +0,0 @@
1
-#!/usr/bin/env python 
2
-from __future__ import division
3
-
4
-import tensorflow as tf
5
-import params
6
-
7
-def weight_variable(shape):
8
-    initial = tf.truncated_normal(shape, stddev=0.1)
9
-    return tf.Variable(initial)
10
-
11
-def bias_variable(shape):
12
-    initial = tf.constant(0.1, shape=shape)
13
-    return tf.Variable(initial)
14
-
15
-def conv2d(x, W, stride):
16
-    return tf.nn.conv2d(x, W, strides=[1, stride, stride, 1], padding='VALID')
17
-
18
-x = tf.placeholder(tf.float32, shape=[None, params.img_height, params.img_width, params.img_channels])
19
-y_ = tf.placeholder(tf.float32, shape=[None, 1])
20
-
21
-x_image = x
22
-
23
-# first convolutional layer
24
-W_conv1 = weight_variable([5, 5, 3, 24])
25
-b_conv1 = bias_variable([24])
26
-
27
-h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1, 2) + b_conv1)
28
-
29
-# second convolutional layer
30
-W_conv2 = weight_variable([5, 5, 24, 36])
31
-b_conv2 = bias_variable([36])
32
-
33
-h_conv2 = tf.nn.relu(conv2d(h_conv1, W_conv2, 2) + b_conv2)
34
-
35
-# third convolutional layer
36
-W_conv3 = weight_variable([5, 5, 36, 48])
37
-b_conv3 = bias_variable([48])
38
-
39
-h_conv3 = tf.nn.relu(conv2d(h_conv2, W_conv3, 2) + b_conv3)
40
-
41
-# fourth convolutional layer
42
-W_conv4 = weight_variable([3, 3, 48, 64])
43
-b_conv4 = bias_variable([64])
44
-
45
-h_conv4 = tf.nn.relu(conv2d(h_conv3, W_conv4, 1) + b_conv4)
46
-
47
-# fifth convolutional layer
48
-W_conv5 = weight_variable([3, 3, 64, 64])
49
-b_conv5 = bias_variable([64])
50
-
51
-h_conv5 = tf.nn.relu(conv2d(h_conv4, W_conv5, 1) + b_conv5)
52
-
53
-# fully connected layer 1
54
-W_fc1 = weight_variable([1152, 1164])
55
-b_fc1 = bias_variable([1164])
56
-
57
-h_conv5_flat = tf.reshape(h_conv5, [-1, 1152])
58
-h_fc1 = tf.nn.relu(tf.matmul(h_conv5_flat, W_fc1) + b_fc1)
59
-
60
-keep_prob = tf.placeholder(tf.float32)
61
-h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
62
-
63
-# fully connected layer 2
64
-W_fc2 = weight_variable([1164, 100])
65
-b_fc2 = bias_variable([100])
66
-
67
-h_fc2 = tf.nn.relu(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
68
-
69
-h_fc2_drop = tf.nn.dropout(h_fc2, keep_prob)
70
-
71
-# fully connected layer 3
72
-W_fc3 = weight_variable([100, 50])
73
-b_fc3 = bias_variable([50])
74
-
75
-h_fc3 = tf.nn.relu(tf.matmul(h_fc2_drop, W_fc3) + b_fc3)
76
-
77
-h_fc3_drop = tf.nn.dropout(h_fc3, keep_prob)
78
-
79
-# fully connected layer 4
80
-W_fc4 = weight_variable([50, 10])
81
-b_fc4 = bias_variable([10])
82
-
83
-h_fc4 = tf.nn.relu(tf.matmul(h_fc3_drop, W_fc4) + b_fc4)
84
-
85
-h_fc4_drop = tf.nn.dropout(h_fc4, keep_prob)
86
-
87
-# output
88
-W_fc5 = weight_variable([10, 1])
89
-b_fc5 = bias_variable([1])
90
-
91
-y = tf.mul(tf.atan(tf.matmul(h_fc4_drop, W_fc5) + b_fc5), 2) #scale the atan output

BIN
ver_0.4/__pycache__/model.cpython-35.pyc View File


BIN
ver_0.4/__pycache__/params.cpython-35.pyc View File


+ 0
- 2
ver_0.4/can.sh View File

@@ -1,2 +0,0 @@
1
-sudo ip link set can0 type can bitrate 500000
2
-sudo ip link set up can0

+ 0
- 175
ver_0.4/cnn_network.py View File

@@ -1,175 +0,0 @@
1
-import tensorflow as tf
2
-import random
3
-
4
-# hyper parameters
5
-learning_rate = 0.001
6
-training_epochs = 10
7
-batch_size = 64
8
-
9
-keep_prob = tf.placeholder(tf.float32)
10
-
11
-# input place holders
12
-X = tf.placeholder(tf.float32, [None, 16896])
13
-X_img = tf.reshape(X, [-1, 66, 256, 1])   # img 28x28x1 (black/white)
14
-Y = tf.placeholder(tf.float32, [None, 10])
15
-
16
-# L1 ImgIn shape=(?, 28, 28, 1)
17
-W1 = tf.Variable(tf.random_normal([3, 3, 1, 32], stddev=0.01))
18
-#    Conv     -> (?, 28, 28, 32)
19
-#    Pool     -> (?, 14, 14, 32)
20
-L1 = tf.nn.conv2d(X_img, W1, strides=[1, 1, 1, 1], padding='SAME')
21
-L1 = tf.nn.relu(L1)
22
-L1 = tf.nn.max_pool(L1, ksize=[1, 2, 2, 1],
23
-                    strides=[1, 2, 2, 1], padding='SAME')
24
-L1 = tf.nn.dropout(L1, keep_prob=keep_prob)
25
-'''
26
-Tensor("Conv2D:0", shape=(?, 28, 28, 32), dtype=float32)
27
-Tensor("Relu:0", shape=(?, 28, 28, 32), dtype=float32)
28
-Tensor("MaxPool:0", shape=(?, 14, 14, 32), dtype=float32)
29
-Tensor("dropout/mul:0", shape=(?, 14, 14, 32), dtype=float32)
30
-'''
31
-
32
-# L2 ImgIn shape=(?, 14, 14, 32)
33
-W2 = tf.Variable(tf.random_normal([3, 3, 32, 64], stddev=0.01))
34
-#    Conv      ->(?, 14, 14, 64)
35
-#    Pool      ->(?, 7, 7, 64)
36
-L2 = tf.nn.conv2d(L1, W2, strides=[1, 1, 1, 1], padding='SAME')
37
-L2 = tf.nn.relu(L2)
38
-L2 = tf.nn.max_pool(L2, ksize=[1, 2, 2, 1],
39
-                    strides=[1, 2, 2, 1], padding='SAME')
40
-L2 = tf.nn.dropout(L2, keep_prob=keep_prob)
41
-'''
42
-Tensor("Conv2D_1:0", shape=(?, 14, 14, 64), dtype=float32)
43
-Tensor("Relu_1:0", shape=(?, 14, 14, 64), dtype=float32)
44
-Tensor("MaxPool_1:0", shape=(?, 7, 7, 64), dtype=float32)
45
-Tensor("dropout_1/mul:0", shape=(?, 7, 7, 64), dtype=float32)
46
-'''
47
-
48
-# L3 ImgIn shape=(?, 7, 7, 64)
49
-W3 = tf.Variable(tf.random_normal([3, 3, 64, 128], stddev=0.01))
50
-#    Conv      ->(?, 7, 7, 128)
51
-#    Pool      ->(?, 4, 4, 128)
52
-#    Reshape   ->(?, 4 * 4 * 128) # Flatten them for FC
53
-L3 = tf.nn.conv2d(L2, W3, strides=[1, 1, 1, 1], padding='SAME')
54
-L3 = tf.nn.relu(L3)
55
-L3 = tf.nn.max_pool(L3, ksize=[1, 2, 2, 1], strides=[
56
-                    1, 2, 2, 1], padding='SAME')
57
-L3 = tf.nn.dropout(L3, keep_prob=keep_prob)
58
-L3 = tf.reshape(L3, [-1, 128 * 4 * 4])
59
-'''
60
-Tensor("Conv2D_2:0", shape=(?, 7, 7, 128), dtype=float32)
61
-Tensor("Relu_2:0", shape=(?, 7, 7, 128), dtype=float32)
62
-Tensor("MaxPool_2:0", shape=(?, 4, 4, 128), dtype=float32)
63
-Tensor("dropout_2/mul:0", shape=(?, 4, 4, 128), dtype=float32)
64
-Tensor("Reshape_1:0", shape=(?, 2048), dtype=float32)
65
-'''
66
-
67
-# L4 FC 4x4x128 inputs -> 625 outputs
68
-W4 = tf.get_variable("W4", shape=[128 * 4 * 4, 625],
69
-                     initializer=tf.contrib.layers.xavier_initializer())
70
-b4 = tf.Variable(tf.random_normal([625]))
71
-L4 = tf.nn.relu(tf.matmul(L3, W4) + b4)
72
-L4 = tf.nn.dropout(L4, keep_prob=keep_prob)
73
-'''
74
-Tensor("Relu_3:0", shape=(?, 625), dtype=float32)
75
-Tensor("dropout_3/mul:0", shape=(?, 625), dtype=float32)
76
-'''
77
-
78
-# L5 Final FC 625 inputs -> 10 outputs
79
-W5 = tf.get_variable("W5", shape=[625, 10],
80
-                     initializer=tf.contrib.layers.xavier_initializer())
81
-b5 = tf.Variable(tf.random_normal([10]))
82
-hypothesis = tf.matmul(L4, W5) + b5
83
-'''
84
-Tensor("add_1:0", shape=(?, 10), dtype=float32)
85
-'''
86
-
87
-# define cost/loss & optimizer
88
-cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(
89
-    logits=hypothesis, labels=Y))
90
-optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
91
-
92
-# initialize
93
-sess = tf.Session()
94
-sess.run(tf.global_variables_initializer())
95
-
96
-# train my model
97
-print('Learning stared. It takes sometime.')
98
-for epoch in range(training_epochs):
99
-    avg_cost = 0
100
-    total_batch = int(mnist.train.num_examples / batch_size)
101
-
102
-    for i in range(total_batch):
103
-        batch_xs, batch_ys = mnist.train.next_batch(batch_size)
104
-        feed_dict = {X: batch_xs, Y: batch_ys, keep_prob: 0.7}
105
-        c, _, = sess.run([cost, optimizer], feed_dict=feed_dict)
106
-        avg_cost += c / total_batch
107
-
108
-    print('Epoch:', '%04d' % (epoch + 1), 'cost =', '{:.9f}'.format(avg_cost))
109
-
110
-print('Learning Finished!')
111
-
112
-# Test model and check accuracy
113
-correct_prediction = tf.equal(tf.argmax(hypothesis, 1), tf.argmax(Y, 1))
114
-accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
115
-
116
-
117
-def evaluate(X_sample, y_sample, batch_size=512):
118
-    """Run a minibatch accuracy op"""
119
-
120
-    N = X_sample.shape[0]
121
-    correct_sample = 0
122
-
123
-    for i in range(0, N, batch_size):
124
-        X_batch = X_sample[i: i + batch_size]
125
-        y_batch = y_sample[i: i + batch_size]
126
-        N_batch = X_batch.shape[0]
127
-
128
-        feed = {
129
-            X: X_batch,
130
-            Y: y_batch,
131
-            keep_prob: 1
132
-        }
133
-
134
-        correct_sample += sess.run(accuracy, feed_dict=feed) * N_batch
135
-
136
-    return correct_sample / N
137
-
138
-print("\nAccuracy Evaluates")
139
-print("-------------------------------")
140
-print('Train Accuracy:', evaluate(mnist.train.images, mnist.train.labels))
141
-print('Test Accuracy:', evaluate(mnist.test.images, mnist.test.labels))
142
-
143
-
144
-# Get one and predict
145
-print("\nGet one and predict")
146
-print("-------------------------------")
147
-r = random.randint(0, mnist.test.num_examples - 1)
148
-print("Label: ", sess.run(tf.argmax(mnist.test.labels[r:r + 1], 1)))
149
-print("Prediction: ", sess.run(
150
-    tf.argmax(hypothesis, 1), {X: mnist.test.images[r:r + 1], keep_prob: 1}))
151
-
152
-# plt.imshow(mnist.test.images[r:r + 1].
153
-#           reshape(28, 28), cmap='Greys', interpolation='nearest')
154
-# plt.show()
155
-
156
-'''
157
-Learning stared. It takes sometime.
158
-Epoch: 0001 cost = 0.385748474
159
-Epoch: 0002 cost = 0.092017397
160
-Epoch: 0003 cost = 0.065854684
161
-Epoch: 0004 cost = 0.055604566
162
-Epoch: 0005 cost = 0.045996377
163
-Epoch: 0006 cost = 0.040913645
164
-Epoch: 0007 cost = 0.036924479
165
-Epoch: 0008 cost = 0.032808939
166
-Epoch: 0009 cost = 0.031791007
167
-Epoch: 0010 cost = 0.030224456
168
-Epoch: 0011 cost = 0.026849916
169
-Epoch: 0012 cost = 0.026826763
170
-Epoch: 0013 cost = 0.027188021
171
-Epoch: 0014 cost = 0.023604777
172
-Epoch: 0015 cost = 0.024607201
173
-Learning Finished!
174
-Accuracy: 0.9938
175
-'''

+ 0
- 98
ver_0.4/model.py View File

@@ -1,98 +0,0 @@
1
-import tensorflow as tf
2
-import params
3
-
4
-def weight_variable(shape):
5
-    initial = tf.truncated_normal(shape, stddev=0.1)
6
-    return tf.Variable(initial)
7
-
8
-def bias_variable(shape):
9
-    initial = tf.constant(0.1, shape=shape)
10
-    return tf.Variable(initial)
11
-
12
-def conv2d(x, W, stride):
13
-    return tf.nn.conv2d(x, W, strides=[1, stride, stride, 1], padding='VALID')
14
-
15
-x = tf.placeholder(tf.float32, shape=[None, params.img_height, params.img_width, params.img_channels])
16
-# x = tf.placeholder(tf.float32, shape=[None, 66, 200, 3])
17
-y_ = tf.placeholder(tf.float32, shape=[None, 1])
18
-
19
-x_image = tf.reshape(x, [-1, params.img_height, params.img_width, params.img_channels])
20
-# print(x_image)
21
-
22
-batch_norm = tf.layers.batch_normalization(x_image)
23
-print("batch_norm : ", batch_norm)
24
-
25
-# first convolutional layer
26
-W_conv1 = weight_variable([5, 5, params.img_channels, 24])
27
-b_conv1 = bias_variable([24])
28
-
29
-h_conv1 = tf.nn.relu(conv2d(batch_norm, W_conv1, 2) + b_conv1)
30
-print(h_conv1)
31
-
32
-# second convolutional layer
33
-W_conv2 = weight_variable([5, 5, 24, 36])
34
-b_conv2 = bias_variable([36])
35
-
36
-h_conv2 = tf.nn.relu(conv2d(h_conv1, W_conv2, 2) + b_conv2)
37
-print(h_conv2)
38
-
39
-# third convolutional layer
40
-W_conv3 = weight_variable([5, 5, 36, 48])
41
-b_conv3 = bias_variable([48])
42
-
43
-h_conv3 = tf.nn.relu(conv2d(h_conv2, W_conv3, 2) + b_conv3)
44
-print(h_conv3)
45
-
46
-# fourth convolutional layer
47
-W_conv4 = weight_variable([3, 3, 48, 64])
48
-b_conv4 = bias_variable([64])
49
-
50
-h_conv4 = tf.nn.relu(conv2d(h_conv3, W_conv4, 1) + b_conv4)
51
-print(h_conv4)
52
-
53
-# fifth convolutional layer
54
-W_conv5 = weight_variable([3, 3, 64, 64])
55
-b_conv5 = bias_variable([64])
56
-
57
-h_conv5 = tf.nn.relu(conv2d(h_conv4, W_conv5, 1) + b_conv5)
58
-print(h_conv5)
59
-
60
-# fully connected layer 1
61
-W_fc1 = weight_variable([1600, 1164])
62
-b_fc1 = bias_variable([1164])
63
-
64
-h_conv5_flat = tf.reshape(h_conv5, [-1, 1600])
65
-h_fc1 = tf.nn.relu(tf.matmul(h_conv5_flat, W_fc1) + b_fc1)
66
-
67
-keep_prob = tf.placeholder(tf.float32)
68
-h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
69
-
70
-# fully connected layer 2
71
-W_fc2 = weight_variable([1164, 100])
72
-b_fc2 = bias_variable([100])
73
-
74
-h_fc2 = tf.nn.relu(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
75
-
76
-h_fc2_drop = tf.nn.dropout(h_fc2, keep_prob)
77
-
78
-# fully connected layer 3
79
-W_fc3 = weight_variable([100, 50])
80
-b_fc3 = bias_variable([50])
81
-
82
-h_fc3 = tf.nn.relu(tf.matmul(h_fc2_drop, W_fc3) + b_fc3)
83
-
84
-h_fc3_drop = tf.nn.dropout(h_fc3, keep_prob)
85
-
86
-# fully connected layer 4
87
-W_fc4 = weight_variable([50, 10])
88
-b_fc4 = bias_variable([10])
89
-
90
-h_fc4 = tf.nn.relu(tf.matmul(h_fc3_drop, W_fc4) + b_fc4)
91
-
92
-h_fc4_drop = tf.nn.dropout(h_fc4, keep_prob)
93
-
94
-# output
95
-W_fc5 = weight_variable([10, 1])
96
-b_fc5 = bias_variable([1])
97
-
98
-y = tf.multiply(tf.atan(tf.matmul(h_fc4_drop, W_fc5) + b_fc5), 2) #scale the atan output

+ 0
- 1
ver_0.4/mount.sh View File

@@ -1 +0,0 @@
1
-sudo mount /dev/mmcblk1p1 /raw_data

+ 0
- 10
ver_0.4/params.py View File

@@ -1,10 +0,0 @@
1
-import os
2
-
3
-img_height = 66
4
-img_width = 256
5
-img_channels = 1
6
-batch = 64
7
-epoch = 2000
8
-write_summary = True
9
-save_dir = os.path.abspath('models')
10
-print(save_dir)

+ 0
- 140
ver_0.4/train.py View File