Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Noted call("clear") in train.py #18

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,31 @@ def conv2d(x, W, stride):
keep_prob = tf.placeholder(tf.float32)
h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)

#FCL12
W_fc12 = weight_variable([1164, 800])
b_fc12 = bias_variable([800])

h_fc12 = tf.nn.relu(tf.matmul(h_fc1_drop, W_fc12) + b_fc12)

h_fc12_drop = tf.nn.dropout(h_fc12, keep_prob)

#FCL 2
W_fc2 = weight_variable([1164, 100])
W_fc2 = weight_variable([800, 100])
b_fc2 = bias_variable([100])

h_fc2 = tf.nn.relu(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
h_fc2 = tf.nn.relu(tf.matmul(h_fc12_drop, W_fc2) + b_fc2)

h_fc2_drop = tf.nn.dropout(h_fc2, keep_prob)


#FCL 2
#W_fc2 = weight_variable([1164, 100])
#b_fc2 = bias_variable([100])

#h_fc2 = tf.nn.relu(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)

#h_fc2_drop = tf.nn.dropout(h_fc2, keep_prob)

#FCL 3
W_fc3 = weight_variable([100, 50])
b_fc3 = bias_variable([50])
Expand All @@ -85,4 +102,4 @@ def conv2d(x, W, stride):
W_fc5 = weight_variable([10, 1])
b_fc5 = bias_variable([1])

y = tf.mul(tf.atan(tf.matmul(h_fc4_drop, W_fc5) + b_fc5), 2) #scale the atan output
y = tf.multiply(tf.atan(tf.matmul(h_fc4_drop, W_fc5) + b_fc5), 2) #scale the atan output
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ret, frame = cap.read()
image = scipy.misc.imresize(frame, [66, 200]) / 255.0
degrees = model.y.eval(feed_dict={model.x: [image], model.keep_prob: 1.0})[0][0] * 180 / scipy.pi
call("clear")
#call("clear")
print("Predicted steering angle: " + str(degrees) + " degrees")
cv2.imshow('frame', frame)
#make smooth angle transitions by turning the steering wheel based on the difference of the current angle
Expand Down
3 changes: 2 additions & 1 deletion run_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
saver.restore(sess, "save/model.ckpt")

img = cv2.imread('steering_wheel_image.jpg',0)
#img = cv2.imread('me0.jpg',0)
rows,cols = img.shape

smoothed_angle = 0
Expand All @@ -18,7 +19,7 @@
full_image = scipy.misc.imread("driving_dataset/" + str(i) + ".jpg", mode="RGB")
image = scipy.misc.imresize(full_image[-150:], [66, 200]) / 255.0
degrees = model.y.eval(feed_dict={model.x: [image], model.keep_prob: 1.0})[0][0] * 180.0 / scipy.pi
call("clear")
#call("clr")
print("Predicted steering angle: " + str(degrees) + " degrees")
cv2.imshow("frame", cv2.cvtColor(full_image, cv2.COLOR_RGB2BGR))
#make smooth angle transitions by turning the steering wheel based on the difference of the current angle
Expand Down
Binary file modified save/model.ckpt.meta
Binary file not shown.
17 changes: 10 additions & 7 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@

train_vars = tf.trainable_variables()

loss = tf.reduce_mean(tf.square(tf.sub(model.y_, model.y))) + tf.add_n([tf.nn.l2_loss(v) for v in train_vars]) * L2NormConst
loss = tf.reduce_mean(tf.square(tf.subtract(model.y_, model.y))) + tf.add_n([tf.nn.l2_loss(v) for v in train_vars]) * L2NormConst
train_step = tf.train.AdamOptimizer(1e-4).minimize(loss)
sess.run(tf.initialize_all_variables())
#sess.run(tf.initialize_all_variables())
sess.run(tf.global_variables_initializer())

# create a summary to monitor cost tensor
tf.scalar_summary("loss", loss)
tf.summary.scalar("loss", loss)
# merge all summaries into a single op
merged_summary_op = tf.merge_all_summaries()
#merged_summary_op = tf.merge_all_summaries()
merged_summary_op = tf.summary.merge_all()

saver = tf.train.Saver()

# op to write logs to Tensorboard
logs_path = './logs'
summary_writer = tf.train.SummaryWriter(logs_path, graph=tf.get_default_graph())
#summary_writer = tf.train.SummaryWriter(logs_path, graph=tf.get_default_graph())
summary_writer = tf.summary.FileWriter(logs_path, graph=tf.get_default_graph())

epochs = 30
batch_size = 100
epochs = 3
batch_size = 10

# train over the dataset about 30 times
for epoch in range(epochs):
Expand Down