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

Allow reshaping blobs to size 0. #4101

Merged
merged 1 commit into from
May 6, 2016
Merged

Conversation

erictzeng
Copy link
Contributor

The current implementation of Blob::Reshape has a check to ensure that Blob sizes do not exceed INT_MAX that goes awry whenever the size of the Blob is 0. (More precisely, the check causes a floating point exception if a 0 appears in the shape anywhere except for the last element.) This PR disables that check if count_ == 0.

While this seems a little silly upon first glance, I think there is a very real use case for supporting this behavior. I'm training a detection network that uses ground truth boxes, which are typically represented by 5 values, but some images have no ground truth boxes at all. In this case, having a ground truth blob of shape (0, 5) seems perfectly sensible to me.

This PR also includes a simple test that reshapes a Blob to shape (0, 5), which would have failed prior to the fix.

Also add a test that reshapes a blob to shape (0, 5).
@jeffdonahue
Copy link
Contributor

Thanks @erictzeng, LGTM (can merge once Travis passes). The current behavior (allowing empty blobs only in the case that 0 is the last (and only the last) dimension, and otherwise failing with a floating point exception) is clearly wrong. An alternative to this which would also at least make behavior consistent would be to die on all empty blobs, but I don't see a compelling reason to go that way.

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

Successfully merging this pull request may close these issues.

2 participants