DALI
DALI copied to clipboard
Squeeze does not convert tensor from [1,480, 600, 3] to [480, 600, 3]
My understanding of TensorGPU.squeeze(int) is that given a tensor of shape [1,480, 600,3], if I did TensorGPU.squeeze(0), the tensor would be replaced in place by a tensor of shape [480, 600,3].
However, that is not what I am seeing running the code below. Though a call to squeze(0) returns true, the shape of the tensor does not change. Could you please point out my error or explain the right usage of squeeze.
import os
import numpy as np
from nvidia.dali import pipeline_def
import nvidia.dali.fn as fn
batch_size=1
sequence_length=1
video_files=["/home/<locationOfFile>/EarthaKittEmotionalinterviewPart 2_480p.mp4"]
@pipeline_def
def video_pipe(filenames):
videos = fn.readers.video(device="gpu", filenames=filenames, sequence_length=sequence_length,
shard_id=0, num_shards=1)
return videos
pipe = video_pipe(batch_size=batch_size,
num_threads=1, device_id=0,
filenames=video_files, seed=123456)
pipe.build()
i = 0
while(True):
#pipe_out[0] returns the TensorList.
print(i)
i += 1
pipe_out = pipe.run()
print(pipe_out[0][0].shape()) # should print [1, 480, 600, 3]
result = pipe_out[0][0].squeeze(0)
print(result) #should print True, indicating that squeeze succeeded
print(pipe_out[0][0].shape()) # I expected it to print [480, 600, 3], but rather got [1, 480, 600, 3]
Hi @nikhiljgeorge,
Every time you call pipe_out[0][0] you extract tensor from the output TensorList. However, the squeeze doesn't affect the TensorList itself, but only the Tensor that was extracted.
To do what you want to please:
output = pipe_out[0][0]
result = output.squeeze(0)
print(result) #should print True, indicating that squeeze succeeded
print(output.shape()) # I expected it to print [480, 600, 3], but rather got [1, 480, 600, 3]