Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds constant memory backprop #2

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
20 changes: 20 additions & 0 deletions invtf/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import tensorflow as tf
import os

def load_image_dataset(folder, epochs=1,new_image_size=(64, 64),batch_size=32,shuffle=True,):
def _parse_function(filename):
image_string = tf.io.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_string)
image_resized = tf.image.resize(image_decoded, new_size)
return image_resized

files = ['{}/{}'.format(folder,f) for f in os.listdir(
folder) if os.path.isfile(os.path.join(folder, f))]
dataset = tf.data.Dataset.from_tensor_slices(tf.constant(files))
if shuffle == True:
dataset = dataset.shuffle(buffer_size=100)
dataset = dataset.repeat(count=epochs)
dataset = dataset.map(map_func=_parse_function,num_parallel_calls=4)
dataset = dataset.prefetch(buffer_size=batch_size)
dataset = dataset.batch(batch_size=batch_size)
return iter(dataset),(len(files)//batch_size)
Loading