def _preprocess_features(features):
"""Function that returns preprocessed images"""
def _parse_single_example_from_tfrecord(value):
features = (
tf.parse_single_example(value,
features={'image_raw': tf.FixedLenFeature([], tf.string),
'label': tf.FixedLenFeature([model_config.LABEL_SIZE], tf.int64)
})
)
return features
def _read_and_decode_tfrecords(filename_queue):
reader = tf.TFRecordReader()
# Point it at the filename_queue
_, value = reader.read(filename_queue)
features = _parse_single_example_from_tfrecord(value)
# decode the binary string image data
image, label = _preprocess_features(features)
return image, label
def test_tfread(filelist):
train_filename_queue = (
tf.train.string_input_producer(filelist,
num_epochs=None,
shuffle=True))
image, label = (
_read_and_decode_tfrecords(train_filename_queue))
return image
images= test_tfread(["gs://test-bucket/t.tfrecords"])
sess = tf.Session(config=tf.ConfigProto(
allow_soft_placement=True,
log_device_placement=True))
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
try:
for step in range(model_config.MAX_STEPS):
_ = sess.run([images])
finally:
# When done, ask the threads to stop.
coord.request_stop()
# Finally, wait for them to join (i.e. cleanly shut down)
coord.join(threads)
subprocess.check_call(["gcloud", "auth", "application-default', "login"])
) - rhaertel80