Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Fix the Cifar10ImagePreprocessor class to use newer dataset APIs #320

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions scripts/tf_cnn_benchmarks/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,24 +858,29 @@ def minibatch(self,
subset,
params,
shift_ratio=-1):
# TODO(jsimsa): Implement datasets code path
del shift_ratio, params
with tf.name_scope('batch_processing'):
all_images, all_labels = dataset.read_data_files(subset)
all_images = tf.constant(all_images)
all_labels = tf.constant(all_labels)
input_image, input_label = tf.train.slice_input_producer(
[all_images, all_labels])
input_image = tf.cast(input_image, self.dtype)
input_label = tf.cast(input_label, tf.int32)
# Ensure that the random shuffling has good mixing properties.
input_image = tf.cast(all_images, self.dtype)
input_label = tf.cast(all_labels, tf.int32)
dataset_train = tf.data.Dataset.from_tensor_slices(
(input_image, input_label))

min_fraction_of_examples_in_queue = 0.4
min_queue_examples = int(dataset.num_examples_per_epoch(subset) *
min_fraction_of_examples_in_queue)
raw_images, raw_labels = tf.train.shuffle_batch(
[input_image, input_label], batch_size=self.batch_size,
capacity=min_queue_examples + 3 * self.batch_size,
min_after_dequeue=min_queue_examples)

dataset_train = dataset_train.shuffle(min_queue_examples).batch(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should call .repeat() in between shuffle and batch

self.batch_size, drop_remainder=True)

if tf.VERSION > "1.12":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can safely assume TensorFlow is at least version 1.12. There are branches such as cnn_tf_v1.11_compatible that work with older versions.

raw_images, raw_labels = tf.compat.v1.data.make_one_shot_iterator(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for compat.v1 since we have import tensorflow.compat.v1 as tf at the top. Simply tf.data.make_one_shot_iterator is fine.

dataset_train).get_next()
else:
raw_images, raw_labels = dataset_train.make_one_shot_iterator(
).get_next()

images = [[] for i in range(self.num_splits)]
labels = [[] for i in range(self.num_splits)]
Expand Down