Skip to content

hog block normalization fix - #1345

Closed
PuppySaturation wants to merge 2 commits into
scikit-image:masterfrom
PuppySaturation:master
Closed

PuppySaturation wants to merge 2 commits into
scikit-image:masterfrom
PuppySaturation:master

Conversation

@PuppySaturation

Copy link
Copy Markdown

Was reviewing and comparing with my own HoG implementation, noticed that the normalization was done wrong. I fixed it assuming an L-2 normalization.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling 6bc40d7 on PuppySaturation:master into cd70059 on scikit-image:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 92.57% when pulling 57ec35c on PuppySaturation:master into b6a1bcd on scikit-image:master.

@stefanv

stefanv commented Jan 29, 2015

Copy link
Copy Markdown
Member

@scikit-image/core Can anyone who uses HoG's verify this fix?

@emmanuelle

Copy link
Copy Markdown
Member

@stefanv it seems indeed right to use the L2 norm of block for normalization, and it would be consistent with the formula of http://en.wikipedia.org/wiki/Histogram_of_oriented_gradients (paragraph block normalization). +1 for merging.

@stefanv

stefanv commented Feb 24, 2015

Copy link
Copy Markdown
Member

@PuppySaturation Thanks very much for this fix; could you please add a test, then I will merge.

@PuppySaturation

Copy link
Copy Markdown
Author

Gave the test some though, didn't come up with anything that would be useful.

@PuppySaturation

Copy link
Copy Markdown
Author

Gave the test some though, didn't come up with anything that would be useful. The current test for HoG don't seem to cover general value accuracy, so I'm not sure quite how to go about this.
Should I hardcode come known values into the test and check the results? If I check the norm of the result by recalculating it, I don't see that as being very useful.

Given that is it such a small fix, if there was no test before, how does it warrant one now?

@JDWarner

JDWarner commented Mar 2, 2015

Copy link
Copy Markdown
Contributor

@PuppySaturation - Generally speaking, if the tests are bad at actually evaluating the function feel completely free to improve them. Trivial tests are easy to write, but aren't good long-term.

In this case, HoG wasn't well tested. Sometimes it's appropriate to test if a function works given proper inputs, or doesn't work in specific ways. However, the fact that this change - which meaningfully changed the quantitative results - didn't make the test suite throw a fit is a bug, just not one a typical user sees.

As for why an improvement is needed, we have to make sure this change will not regress in future versions. You found a real bug (thanks!) but that change also exposed an insufficiency in the testsuite, which we need to shore up.

I'm completely fine with hardcoded values, if there is a known valid example available or if one can hand-calculate the expected results. This type of test is very powerful, even if seemingly rather simple. Note that for this type of test, np.testing.assert_allclose is better than checking exact equality as future alternative implementations may well have slightly different, but effectively equal floating point results.

@PuppySaturation

Copy link
Copy Markdown
Author

Yet for a complex operation such as HoG the only practical way of obtaining the values of a non-trivial transformation is to run the algorithm. That would mean they are in affect testing whether the implementation fits itself. This might be useful to some extent, but It would also mean that the tests themselves would have to be subject to bug fixes of the algorithm. Which would make future corrections complicated.

If my change were from:
normalised_blocks[y,x,:] = normalize(block,'L1')
to:
normalised_blocks[y,x,:] = normalize(block,'L2')

and the function normalize was properly tested, would HoG still needed a new test?

@soupault

soupault commented Apr 7, 2016

Copy link
Copy Markdown
Member

@JDWarner would you be "satisfied enough" to merge this PR if the function will be tested against random input matrix with fixed seed?

@JDWarner

JDWarner commented Apr 7, 2016

Copy link
Copy Markdown
Contributor

Yes, that would work. Ideally we would have an independently verified result to compare against, though.

@soupault

soupault commented Apr 7, 2016

Copy link
Copy Markdown
Member

I suppose, that's not the easiest thing to get for a HoG descriptor.

UPD: Ah, sorry. We could verify against MATLAB.

@soupault

soupault commented Apr 7, 2016

Copy link
Copy Markdown
Member

@JDWarner Ok, well, a comparison had been added in c095daa#diff-f7fbb052903c8ca5aab7b798019b73b3R23 .

@stefanv

stefanv commented Apr 7, 2016

Copy link
Copy Markdown
Member

Perhaps @sdsingh has some thoughts, since he was looking at comparing with the Matlab results.

@PuppySaturation

Copy link
Copy Markdown
Author

Thank you @soupault for picking this up. I completely forgot about it.

@sdsingh

sdsingh commented Apr 13, 2016

Copy link
Copy Markdown

I tried comparing to Matlab results--the comparison is in #2011, and is not particularly encouraging. However, perhaps it will be fixed after this bug fix. Feel free to use tests from #2011 if they are useful.

@soupault

Copy link
Copy Markdown
Member

Superseded by #2040.

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.

7 participants