Skip to content

Commit

Permalink
Added validation loss output
Browse files Browse the repository at this point in the history
  • Loading branch information
Sully Chen authored and Sully Chen committed Oct 3, 2016
1 parent 7742f84 commit cc518e6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
32 changes: 26 additions & 6 deletions driving_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
ys = []

#points to the end of the last batch
batch_pointer = 0
train_batch_pointer = 0
val_batch_pointer = 0

#read data.txt
with open("driving_dataset/data.txt") as f:
Expand All @@ -24,12 +25,31 @@
random.shuffle(c)
xs, ys = zip(*c)

def LoadBatch(batch_size):
global batch_pointer
train_xs = xs[:int(len(xs) * 0.8)]
train_ys = ys[:int(len(xs) * 0.8)]

val_xs = xs[-int(len(xs) * 0.2):]
val_ys = ys[-int(len(xs) * 0.2):]

num_train_images = len(train_xs)
num_val_images = len(val_xs)

def LoadTrainBatch(batch_size):
global train_batch_pointer
x_out = []
y_out = []
for i in range(0, batch_size):
x_out.append(scipy.misc.imresize(scipy.misc.imread(train_xs[(train_batch_pointer + i) % num_train_images])[-150:], [66, 200]) / 255.0)
y_out.append([train_ys[(train_batch_pointer + i) % num_train_images]])
train_batch_pointer += batch_size
return x_out, y_out

def LoadValBatch(batch_size):
global val_batch_pointer
x_out = []
y_out = []
for i in range(0, batch_size):
x_out.append(scipy.misc.imresize(scipy.misc.imread(xs[(batch_pointer + i) % num_images])[-150:], [66, 200]) / 255.0)
y_out.append([ys[(batch_pointer + i) % num_images]])
batch_pointer += batch_size
x_out.append(scipy.misc.imresize(scipy.misc.imread(val_xs[(val_batch_pointer + i) % num_val_images])[-150:], [66, 200]) / 255.0)
y_out.append([val_ys[(val_batch_pointer + i) % num_val_images]])
val_batch_pointer += batch_size
return x_out, y_out
5 changes: 3 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

#train over the dataset about 30 times
for i in range(int(driving_data.num_images * 0.3)):
xs, ys = driving_data.LoadBatch(100)
xs, ys = driving_data.LoadTrainBatch(100)
train_step.run(feed_dict={model.x: xs, model.y_: ys, model.keep_prob: 0.8})
if i % 10 == 0:
print("step %d, train loss %g"%(i, loss.eval(feed_dict={
xs, ys = driving_data.LoadValBatch(100)
print("step %d, val loss %g"%(i, loss.eval(feed_dict={
model.x:xs, model.y_: ys, model.keep_prob: 1.0})))
if i % 100 == 0:
if not os.path.exists(LOGDIR):
Expand Down

0 comments on commit cc518e6

Please sign in to comment.