-
Notifications
You must be signed in to change notification settings - Fork 618
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
Add PeekShape operator to learn the decoded image shape #2205
Conversation
!build |
CI MESSAGE: [1536126]: BUILD STARTED |
CI MESSAGE: [1536126]: BUILD FAILED |
!build |
CI MESSAGE: [1536191]: BUILD STARTED |
CI MESSAGE: [1536191]: BUILD FAILED |
- adds an operator that utilizes peek shape functionality from Image class that can parse image header without decoding to learn decoded image shape Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
!build |
CI MESSAGE: [1536371]: BUILD STARTED |
CI MESSAGE: [1536371]: BUILD FAILED |
CI MESSAGE: [1536371]: BUILD PASSED |
|
||
namespace dali { | ||
|
||
DALI_SCHEMA(PeekShape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is image specific, so I think the name should reflect it. Something like ImagePeekShape
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
|
||
template <typename type> | ||
void ConvertShape(Tensor<CPUBackend> &out, const TensorShape<3> &shape) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void ConvertShape(Tensor<CPUBackend> &out, const TensorShape<3> &shape) { | |
void WriteShape(Tensor<CPUBackend> &out, const TensorShape<3> &shape) { |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pipe = Pipeline(batch_size=batch_size, num_threads=4, device_id=0) | ||
input, _ = fn.file_reader(file_root=data_path, shard_id=0, num_shards=1, name="reader") | ||
decoded = fn.image_decoder(input, device=device, output_type=types.RGB) | ||
if device == "cpu" : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shape_device = 'cpu' if device == 'cpu' else 'gpu'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
out = pipe.run() | ||
(image, decoded_shape, raw_shape) = [v.as_cpu() if isinstance(v, dali.backend_impl.TensorListGPU) else v for v in out] | ||
for i in range(batch_size): | ||
# as we are asking for a particular color space it may differ from the source image, so don't comapre it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# as we are asking for a particular color space it may differ from the source image, so don't comapre it | |
# as we are asking for a particular color space it may differ from the source image, so don't compare it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
test_types = [types.INT32, types.UINT32, types.INT64, types.UINT64, types.FLOAT, types.FLOAT64] | ||
|
||
def test_image_decoder(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_image_decoder(): | |
def test_operator_peek_shape(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test_types = [types.INT32, types.UINT32, types.INT64, types.UINT64, types.FLOAT, types.FLOAT64] | ||
|
||
def test_image_decoder(): | ||
for device in {'cpu', 'mixed'}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for device in {'cpu', 'mixed'}: | |
for device in {'cpu', 'gpu'}: |
I'd rather set the device of the PeekShape operator here and calculate the device for decoder inside the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peek shape is available only for the CPU, so it doesn't make much sense. Maybe I should just test for the CPU, after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
# as we are asking for a particular color space it may differ from the source image, so don't comapre it | ||
for d in range(len(image.at(i).shape) - 1): | ||
shape_type = dali_to_numpy[out_type] | ||
assert image.at(i).shape[d] == decoded_shape.at(i)[d], "{} vs {}".format(image.at(i).shape[d], decoded_shape.at(i)[d]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract image.at(i)
outside of the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
for i in range(batch_size): | ||
# as we are asking for a particular color space it may differ from the source image, so don't comapre it | ||
for d in range(len(image.at(i).shape) - 1): | ||
shape_type = dali_to_numpy[out_type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can go out of the loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
path = 'db/single' | ||
file_types = {'jpeg', 'mixed', 'png', 'tiff', 'pnm', 'bmp'} | ||
|
||
dali_to_numpy = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could go to utils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
!build |
CI MESSAGE: [1538872]: BUILD STARTED |
namespace dali { | ||
|
||
DALI_SCHEMA(PeekImageShape) | ||
.DocStr(R"code(Obtain the shape of the encoded image.)code") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.DocStr(R"code(Obtain the shape of the encoded image.)code") | |
.DocStr(R"code(Obtains the shape of the encoded image.)code") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
!build |
CI MESSAGE: [1538921]: BUILD STARTED |
CI MESSAGE: [1538872]: BUILD FAILED |
CI MESSAGE: [1538872]: BUILD PASSED |
CI MESSAGE: [1538921]: BUILD FAILED |
CI MESSAGE: [1538921]: BUILD PASSED |
Signed-off-by: Janusz Lisiecki jlisiecki@nvidia.com
Why we need this PR?
Pick one, remove the rest
What happened in this PR?
Fill relevant points, put NA otherwise. Replace anything inside []
PeekShape operator to learn the decoded image shape
new operator
NA
test case is added
NA
JIRA TASK: [DALI-1564]