forked from guildai/_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose lr decay rate and support for samples
- Loading branch information
Garrett Smith
committed
Dec 2, 2016
1 parent
35f37a9
commit 6a99a73
Showing
5 changed files
with
95 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
CIFAR10_data | ||
samples |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import argparse | ||
import json | ||
|
||
import tensorflow as tf | ||
|
||
from tensorflow.core.framework import summary_pb2 | ||
|
||
import support | ||
|
||
FLAGS = None | ||
|
||
def prepare_samples(images_op, labels_op): | ||
# Use summary op to generate a PNG from TF native image | ||
inputs = tf.placeholder(tf.float32, [None, support.CROPPED_IMAGE_HEIGHT, | ||
support.CROPPED_IMAGE_WIDTH, | ||
support.IMAGE_DEPTH]) | ||
summary = tf.image_summary('input', inputs, 1) | ||
|
||
# Init session | ||
sess = tf.Session() | ||
|
||
# Initialize queue runners | ||
coord = tf.train.Coordinator() | ||
threads = tf.train.start_queue_runners(sess=sess, coord=coord) | ||
|
||
# Save images and labels | ||
images, labels = sess.run([images_op, labels_op]) | ||
i = 1 | ||
for image, label in zip(images, labels): | ||
summary_bin = sess.run(summary, feed_dict={inputs: [image]}) | ||
image_summary = summary_pb2.Summary() | ||
image_summary.ParseFromString(summary_bin) | ||
basename = FLAGS.sample_dir + "/" + ("%05i" % i) | ||
image_path = basename + ".png" | ||
print "Writing %s" % image_path | ||
with open(image_path, "w") as f: | ||
f.write(image_summary.value[0].image.encoded_image_string) | ||
with open(basename + ".json", "w") as f: | ||
f.write(json.dumps({ | ||
"image": image.tolist(), | ||
"label": int(label) | ||
})) | ||
i += 1 | ||
|
||
# Stop queue runners | ||
coord.request_stop() | ||
coord.join(threads) | ||
|
||
def main(_): | ||
images, labels = support.data_inputs( | ||
FLAGS.datadir, support.VALIDATION_DATA, FLAGS.sample_count, 1) | ||
tf.gfile.MakeDirs(FLAGS.sample_dir) | ||
prepare_samples(images, labels) | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--datadir", default="/tmp/CIFAR10_data",) | ||
parser.add_argument("--sample_dir", default="/tmp/CIFAR10_samples") | ||
parser.add_argument("--sample_count", type=int, default=100) | ||
FLAGS, _ = parser.parse_known_args() | ||
tf.app.run() |
This file contains 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
This file contains 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