Skip to content

Commit

Permalink
Partial cherry-pic of #305 (#307)
Browse files Browse the repository at this point in the history
* Fix validation for accuracy in TF example

Signed-off-by: Serge Panev <spanev@nvidia.com>
Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
  • Loading branch information
JanuszL committed Nov 16, 2018
1 parent 5676fca commit 235ae80
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions docs/examples/tensorflow/demo/nvutils/image_processing.py
Expand Up @@ -36,7 +36,8 @@ def __init__(self,
device_id,
num_gpus,
deterministic=False,
dali_cpu=True):
dali_cpu=True,
training=True):

kwargs = dict()
if deterministic:
Expand All @@ -60,24 +61,24 @@ def __init__(self,
'image/object/bbox/ymax':dali.tfrecord.VarLenFeature(dali.tfrecord.float32, 0.0)})
if dali_cpu:
self.decode = dali.ops.HostDecoder(device="cpu", output_type=dali.types.RGB)
self.resize = dali.ops.RandomResizedCrop(
device="cpu",
size=[height, width],
interp_type=dali.types.INTERP_LINEAR,
random_aspect_ratio=[0.8, 1.25],
random_area=[0.1, 1.0],
num_attempts=100)
resize_device = "cpu"
else:
self.decode = dali.ops.nvJPEGDecoder(
device="mixed",
output_type=dali.types.RGB)
resize_device = "gpu"

if training:
self.resize = dali.ops.RandomResizedCrop(
device="gpu",
device=resize_device,
size=[height, width],
interp_type=dali.types.INTERP_LINEAR,
random_aspect_ratio=[0.8, 1.25],
random_area=[0.1, 1.0],
num_attempts=100)
else:
# Make sure that every image > 224 for CropMirrorNormalize
self.resize = dali.ops.Resize (device=resize_device, resize_shorter=256)

self.normalize = dali.ops.CropMirrorNormalize(
device="gpu",
Expand Down Expand Up @@ -117,7 +118,8 @@ def __init__(self,
num_threads,
dtype=tf.uint8,
dali_cpu=True,
deterministic=False):
deterministic=False,
training=False):
pipe = HybridPipe(
tfrec_filenames=filenames,
tfrec_idx_filenames=idx_filenames,
Expand All @@ -128,7 +130,8 @@ def __init__(self,
device_id=hvd.rank(),
num_gpus=hvd.size(),
deterministic=deterministic,
dali_cpu=dali_cpu)
dali_cpu=dali_cpu,
training=training)
serialized_pipe = pipe.serialize()
del pipe

Expand Down Expand Up @@ -158,6 +161,7 @@ def image_set(filenames, batch_size, height, width, training=False,
batch_size,
num_threads,
dali_cpu=dali_cpu,
deterministic=deterministic)
deterministic=deterministic,
training=training)
images, labels = preprocessor.get_device_minibatches()
return (images, labels)
2 changes: 1 addition & 1 deletion docs/examples/tensorflow/demo/nvutils/runner.py
Expand Up @@ -364,7 +364,7 @@ def validate(infer_func, params):
deterministic=deterministic,
dali_cpu=dali_cpu, idx_filenames=eval_idx_filenames,
num_threads=num_preproc_threads),
steps=num_eval_samples)
steps=(num_eval_samples/batch_size))
print('Top-1 accuracy:', eval_result['top1_accuracy']*100, '%')
print('Top-5 accuracy:', eval_result['top5_accuracy']*100, '%')
except KeyboardInterrupt:
Expand Down

0 comments on commit 235ae80

Please sign in to comment.