Created
December 22, 2016 15:53
-
-
Save samehmohamed88/13e81462cc736c5772277f26249e61f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Image Tensor | |
images_placeholder = tf.placeholder(tf.float32, shape=[None, 32, 32, 3], name='x') | |
gray = tf.image.rgb_to_grayscale(images_placeholder, name='gray') | |
gray /= 255. | |
# Label Tensor | |
labels_placeholder = tf.placeholder(tf.float32, shape=(None, 43), name='y') | |
# dropout Tensor | |
keep_prob = tf.placeholder(tf.float32, name='drop') | |
# construct model | |
logits = inference(gray, keep_prob) | |
# calculate loss | |
loss_value = loss(logits, labels_placeholder) | |
# training | |
train_op = training(loss_value, 0.001) | |
# accuracy | |
acc = accuracy(logits, labels_placeholder) | |
sess = tf.Session() | |
sess.run(tf.initialize_all_variables()) | |
# for TensorBoard | |
summary_op = tf.merge_all_summaries() | |
summary_writer = tf.train.SummaryWriter("/home/ubuntu", sess.graph) | |
with tf.Session() as sess: | |
sess.run(tf.initialize_all_variables()) | |
num_examples = len(X_train) | |
print("Training...") | |
print() | |
for i in range(EPOCHS): | |
for j in range(steps): | |
# train for batch_size | |
batch_x, batch_y = next_batch(X_train, Y_train, BATCH_SIZE) | |
sess.run(train_op, feed_dict={ | |
images_placeholder: batch_x, | |
labels_placeholder: batch_y, | |
keep_prob: 0.5}) | |
val_accuracy, val_loss = evaluate(X_val, Y_val) | |
if i % 10 == 0: | |
print("EPOCH {} ...".format(i+1)) | |
print("Validation Loss = {:.3f} and Validation Accuracy = {:.3f}".format(val_loss, val_accuracy*100)) | |
print() | |
if val_accuracy > .93: | |
break | |
try: | |
saver | |
except NameError: | |
saver = tf.train.Saver() | |
saver.save(sess, 'gtsd') | |
print("Model saved") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment