Skip to content

Instantly share code, notes, and snippets.

View jihaonew's full-sized avatar
🎯
Focusing

Jihao Liu jihaonew

🎯
Focusing
View GitHub Profile
@jihaonew
jihaonew / reader_tfrecode.py
Created April 10, 2018 12:07
Read image from tfrecord using TensorFlow.
import tensorflow as tf
import utils
class Reader():
def __init__(self, tfrecords_file, image_size=256,
min_queue_examples=1000, batch_size=1, num_threads=8, name=''):
"""
Args:
tfrecords_file: string, tfrecords file path
min_queue_examples: integer, minimum number of samples to retain in the queue that provides of batches of examples
@jihaonew
jihaonew / reader.py
Created April 10, 2018 12:04
A general TensorFlow image reader.
from os import listdir
from os.path import isfile, join
import tensorflow as tf
def get_image(path, height, width, preprocess_fn):
png = path.lower().endswith('png')
img_bytes = tf.read_file(path)
image = tf.image.decode_png(img_bytes, channels=3) if png else tf.image.decode_jpeg(img_bytes, channels=3)
return preprocess_fn(image, height, width)