Skip to content

Instantly share code, notes, and snippets.

@ispamm
Created November 27, 2018 11:41
Show Gist options
  • Save ispamm/6bb70371d665ca0185c3b765afe23cdc to your computer and use it in GitHub Desktop.
Save ispamm/6bb70371d665ca0185c3b765afe23cdc to your computer and use it in GitHub Desktop.
# This snippet is adapted from here: https://www.tensorflow.org/guide/datasets
def input_fn(dataframe, is_eval=False):
# Load the list of files
filenames = tf.constant(dataframe.iloc[:, 0].tolist())
# Load the labels
labels = tf.constant(dataframe.iloc[:, 1:].values.astype(np.float32))
# Build the dataset with image processing on top of it
dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
dataset = dataset.map(_parse_function)
# Add shuffling and repeatition if training
if is_eval:
dataset = dataset.batch(64)
else:
dataset = dataset.repeat().shuffle(1000).batch(64)
return dataset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment