-
Notifications
You must be signed in to change notification settings - Fork 609
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
Deprecate squeeze_labels option from MXNet iterator and enhance .squeeze function to match numpy style interface #2450
Conversation
b99befe
to
456775f
Compare
456775f
to
ab2b497
Compare
Whether the iterator should squeeze the labels before | ||
copying them to the ndarray. | ||
This argument is deprecated and will be removed from future releases | ||
without further notice. |
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.
without further notice. |
(-2, (3, 1, 6)), | ||
(None, (1, 1, 6)), | ||
(1, (1, 1, 6)), | ||
#(None, (1, 1, 1)), # Numpy produces a scalar in this case (probably we should too) |
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.
Should we address this now?
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.
@mzient ?
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.
We should.
ab2b497
to
e96da5e
Compare
Signed-off-by: Joaquin Anton <janton@nvidia.com>
e96da5e
to
11020ca
Compare
dali/pipeline/data/tensor.h
Outdated
*/ | ||
inline void Squeeze() { | ||
std::vector<Index> shape(shape_.begin(), shape_.end()); | ||
SmallVector<int64_t, 6> shape(shape_.begin(), shape_.end()); |
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.
SmallVector<int64_t, 6> shape(shape_.begin(), shape_.end()); | |
auto &shape = shape_.shape; |
dali/pipeline/data/tensor.h
Outdated
shape.erase(std::remove(shape.begin(), shape.end(), 1), shape.end()); | ||
if (shape.empty()) { | ||
shape.push_back(1); | ||
shape_ = 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.
This line is not necessary when you follow the suggestion above.
dali/pipeline/data/tensor.h
Outdated
DALI_ENFORCE(dim >= -ndim && dim <= (ndim - 1), | ||
make_string("axis ", dim, " is out of bound for a tensor with ", shape_.size(), | ||
" dimensions.")); | ||
if (dim < 0) |
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.
I think we should remove corresponding dimension from the layout, if present.
Signed-off-by: Joaquin Anton <janton@nvidia.com>
6a7b240
to
3245d58
Compare
dali/pipeline/data/tensor.h
Outdated
shape.erase(std::remove(shape.begin(), shape.end(), 1), shape.end()); | ||
if (shape.empty()) { | ||
shape.push_back(1); | ||
SmallVector<int64_t, 6> out_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.
SmallVector<int64_t, 6> out_shape; | |
DynamicTensorShapeContainer out_shape; |
dali/pipeline/data/tensor.h
Outdated
if (!in_layout.empty()) | ||
out_layout += in_layout[d]; | ||
} | ||
shape_ = out_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.
shape_ = out_shape; | |
shape_ = std::move(out_shape); |
dali/pipeline/data/tensor.h
Outdated
* equal to 1. | ||
* @param dim Dimension to be squeezed. Negative indexing is also suppo9rted | ||
*/ | ||
inline void Squeeze(int dim) { |
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.
Following that definition (the function does or does not squeeze), maybe return a bool?
inline void Squeeze(int dim) { | |
inline bool Squeeze(int dim) { |
auto layout = GetLayout(); | ||
if (!layout.empty()) { | ||
SetLayout(layout.first(dim) + layout.sub(dim + 1)); | ||
} |
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.
} | |
} | |
return true; |
} | ||
shape_ = 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.
} | |
return false; | |
} |
include/dali/core/tensor_layout.h
Outdated
@@ -302,10 +312,29 @@ class TensorLayout { | |||
|
|||
DALI_HOST_DEV | |||
friend constexpr TensorLayout operator+(const TensorLayout &a, const TensorLayout &b); | |||
DALI_HOST_DEV | |||
friend constexpr TensorLayout operator+(const TensorLayout &a, const char &b); |
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.
Don't pass primitive types by reference
friend constexpr TensorLayout operator+(const TensorLayout &a, const char &b); | |
friend constexpr TensorLayout operator+(const TensorLayout &a, char b); |
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.
Yeah, it is a leftover (I was trying to figure out a compile error, that turned out to be the lack of operator+=). I'll revert to pass by value
include/dali/core/tensor_layout.h
Outdated
}; | ||
|
||
static_assert(sizeof(TensorLayout) == 16, "Tensor layout size should be exactly 16B"); | ||
|
||
/** @brief Appends a single element to the layout string */ | ||
DALI_HOST_DEV | ||
constexpr TensorLayout operator+(const TensorLayout &a, const char &b) { |
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.
constexpr TensorLayout operator+(const TensorLayout &a, const char &b) { | |
constexpr TensorLayout operator+(const TensorLayout &a, char b) { |
b0232e5
to
3a8e056
Compare
Signed-off-by: Joaquin Anton <janton@nvidia.com>
c1753e6
to
92f5940
Compare
!build |
CI MESSAGE: [1806157]: BUILD STARTED |
CI MESSAGE: [1806157]: BUILD PASSED |
Signed-off-by: Joaquin Anton janton@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 []
The option squeeze_labels=True caused the batch dimension to disappear when batch_size=1
MXNet generic iterator
All
Existing tests
N/A
JIRA TASK: [Use DALI-XXXX or NA]