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

nvidia.dali.plugin.tf makes my label incorrect #80

Closed
wangguangyuan opened this issue Jul 28, 2018 · 1 comment
Closed

nvidia.dali.plugin.tf makes my label incorrect #80

wangguangyuan opened this issue Jul 28, 2018 · 1 comment

Comments

@wangguangyuan
Copy link

wangguangyuan commented Jul 28, 2018

When I use pipe.build() and pipe.run() to enter the result, the label output is correct, but when I use nvidia.dali.plugin.tf and then use sess.run() to output the result, label is all zero.
my test file format: (image_path, label)
/n01704323/n01704323_1569.JPEG 0
/n01704323/n01704323_5833.JPEG 0
/n01704323/n01704323_2956.JPEG 0
/n01704323/n01704323_4976.JPEG 0
/n01704323/n01704323_8911.JPEG 0
/n01704323/n01704323_9292.JPEG 0
/n01704323/n01704323_1379.JPEG 0
/n01704323/n01704323_8648.JPEG 0
/n01704323/n01704323_8497.JPEG 0
/n01704323/n01704323_2732.JPEG 0
/n02017213/n02017213_3476.JPEG 1
/n02017213/n02017213_6601.JPEG 1
/n02017213/n02017213_3582.JPEG 1
/n02017213/n02017213_765.JPEG 1
/n02017213/n02017213_3461.JPEG 1
/n02017213/n02017213_3894.JPEG 1
/n02017213/n02017213_513.JPEG 1
/n02017213/n02017213_6029.JPEG 1
/n02017213/n02017213_43.JPEG 1
/n02017213/n02017213_5432.JPEG 1
/n02017213/n02017213_7325.JPEG 1
/n02017213/n02017213_7622.JPEG 1
/n02017213/n02017213_7330.JPEG 1

my test code:
`
#First test procedure:
pipe = FileReadPipeline(batch_size=32, num_threads=1, device_id=0, random_shuffle=True,
file_list=save_file_path, initial_fill=4096)
pipe.build()
for _ in range(1):
pipe_out = pipe.run()
images, labels = pipe_out
labels_tensor = labels.asCPU().as_tensor()
images = images.asCPU()
print(np.array(labels_tensor))
# print(images.at(9))

output:
[[1]
[0]
[1]
[0]
[1]
[1]
[1]
[0]
[1]
[1]
[0]
[1]
[1]
[0]
[0]
[0]
[1]
[0]
[0]
[0]
[1]
[1]
[0]
[0]
[0]
[1]
[0]
[1]
[0]
[1]
[0]
[0]]
#--------------------------------------#
#Second test procedure:
device_id = 0
pipe = FileReadPipeline(batch_size=32, num_threads=1, device_id=0, random_shuffle=True,
file_list=save_file_path, initial_fill=4096)
seri_pipe = pipe.serialize()
daliop = dali_tf.DALIIterator()
with tf.device('/gpu:%i' % device_id):
image, label = daliop(serialized_pipeline=seri_pipe,
batch_size=32,
height=224,
width=224,
device_id=device_id)
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.5)
config = tf.ConfigProto(gpu_options=gpu_options)
with tf.Session(config=config) as sess:
ims, labels = sess.run([image, label])
print(labels)
`
output:
[[ 0.00000000e+00]
[ 0.00000000e+00]
[ 1.40129846e-45]
[ 1.40129846e-45]
[ 1.40129846e-45]
[ 1.40129846e-45]
[ 0.00000000e+00]
[ 0.00000000e+00]
[ 1.40129846e-45]
[ 0.00000000e+00]
[ 0.00000000e+00]
[ 1.40129846e-45]
[ 0.00000000e+00]
[ 0.00000000e+00]
[ 1.40129846e-45]
[ 1.40129846e-45]
[ 1.40129846e-45]
[ 1.40129846e-45]
[ 0.00000000e+00]
[ 0.00000000e+00]
[ 1.40129846e-45]
[ 1.40129846e-45]
[ 1.40129846e-45]
[ 0.00000000e+00]
[ 0.00000000e+00]
[ 1.40129846e-45]
[ 0.00000000e+00]
[ 1.40129846e-45]
[ 0.00000000e+00]
[ 0.00000000e+00]
[ 0.00000000e+00]
[ 0.00000000e+00]]

`
class CommonPipeline(Pipeline):
def init(self, batch_size, num_threads, device_id, size=(224, 224), crop_size=(224, 224),
mean=IMAGE_MEAN,
std=IMAGE_STD,
channel_format=types.NHWC,
probability=0.5,
device='gpu',
decode_method='in_gpu'):
super(CommonPipeline, self).init(batch_size, num_threads, device_id)
assert device == 'gpu' and decode_method == 'in_gpu'
if decode_method == 'in_gpu':
self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB)
else:
self.decode = ops.HostDecoder(output_type=types.RGB)

    self.rrc = ops.RandomResizedCrop(device=device, size=size)
    self.cmnp = ops.CropMirrorNormalize(device=device,
                                        output_dtype=types.FLOAT,
                                        output_layout=channel_format,
                                        image_type=types.RGB,
                                        crop=crop_size,
                                        mean=mean,
                                        std=std)
    self.coin = ops.CoinFlip(probability=probability)
    # self.cast = ops.Cast(device=device, dtype=types.FLOAT16)

def base_define_graph(self, inputs, labels):
    rng = self.coin()
    images = self.decode(inputs)
    images = self.rrc(images)
    images = self.cmnp(images, mirror=rng)
    # images = self.cast(images)
    return images, labels.gpu()

class FileReadPipeline(CommonPipeline):
def init(self,
batch_size,
num_threads,
device_id,
random_shuffle,
file_root='',
file_list='',
size=(224, 224),
crop_size=(224, 224),
mean=IMAGE_MEAN,
std=IMAGE_STD,
channel_format=types.NHWC,
probability=0.5,
device='gpu',
decode_method='in_gpu',
initial_fill=4096):
super(FileReadPipeline, self).init(batch_size=batch_size,
num_threads=num_threads,
device_id=device_id,
size=size,
crop_size=crop_size,
mean=mean,
std=std,
channel_format=channel_format,
probability=probability,
device=device,
decode_method=decode_method)
self.input = ops.FileReader(file_root=file_root, file_list=file_list,
random_shuffle=random_shuffle, initial_fill=initial_fill)

def define_graph(self):
    images, labels = self.input()
    return self.base_define_graph(images, labels)`
@wangguangyuan
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant