Repository navigation
evaluation or metrics module - #4025
Conversation
|
Hello @rbavery! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2019-07-20 21:09:31 UTC |
|
I'm not sure what the python 3.7 build is failing due to this error: I'll look into this later today. The Python 3.5 build fails are because of a typo, I need to set the minimum version to |
|
Is the build fixed now? Sometimes mirrors fail. There was a |
There was a problem hiding this comment.
Thank you for the contribution! This is a good cleanup of the namespace in measure, and I like the API for the new variation_of_information. I really only have a few minor comments/tweaks, some which relate to the original code and not your changes, with one additional question:
Is there a reason compare_ssim didn't make the move also? It is very much in this class of functions, and seems like skimage.evaluate would be the proper home for it as well.
| ] | ||
|
|
||
|
|
||
| def _assert_compatible(im1, im2): |
There was a problem hiding this comment.
Is this the ideal place for this function? Would it make more sense for this to live in _shared?
Some duplicated effort where we ask for masks in other functions could be simplified with this. I wouldn't mind removing the leading underscore in that case.
There was a problem hiding this comment.
Agreed, moved to _shared and renamed assert_equal_shape
Yep @hmaarrfk , looks like all builds pass. I think the python 3.7 build that failed last time was a fluke, it's working now. |
Hey @JDWarner thanks for the review! I missed |
|
I don't object to the new submodule, although I wonder if Sorry to nitpick on such a bike-sheddable item, but since we don't often introduce top-level models I think it is worth getting the name right in this case. |
|
@stefanv I hear you, I was thinking of the term But I'm not totally opposed to |
|
Metrics would feel more familiar to me. What do others think? |
|
Metrics feels familiar and the colloquial definition fits. However, while I don't want to get too far into the weeds with this, note that metric has a specific mathematical definition and not all of these functions are metrics. For example, two routines I'll be contributing as soon as this refactor happens are the Dice coefficient and Jaccard index for comparison of binary images/segmented objects against a ground truth. The Dice is not a metric, while the Jaccard is (see the Jaccard Wikipedia article for further details). |
|
I'm leaning towards |
sciunto
left a comment
There was a problem hiding this comment.
I haven't made a careful review, but I noticed two things while scrolling the code.
sciunto
left a comment
There was a problem hiding this comment.
Great PR.
I made additional comments after a more careful reading of the code. My main concern is about the new assert_shape_equal function. Also, the rendering of the gallery example is not good on my laptop. Do you have the same?
The rest is more on details.
|
|
||
| def assert_shape_equal(im1, im2): | ||
| """Raise an error if the shape and dtype do not match.""" | ||
| if not im1.shape == im2.shape: |
There was a problem hiding this comment.
Why not just assert im1.shape == im2.shape? Do we really need this function? The gain looks low to me.
There was a problem hiding this comment.
We had assert im1.shape == im2.shape previously, @JDWarner thought it might be useful to have a function in _shared
See #4025 (comment)
If we made this function use an assert statement would that be an improvement? I'm impartial either way.
In [7]: def assert_shape_equal(a, b):
...: message = "%r does not have equal shape with %r" % (a.shape, b.shape)
...: assert a.shape == b.shape, message
In [8]: assert_shape_equal(x,y)
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-8-8237c8a1005b> in <module>
----> 1 assert_shape_equal(x,y)
<ipython-input-7-2933226b4e44> in assert_shape_equal(a, b)
1 def assert_shape_equal(a, b):
2 message = "%r does not have equal shape with %r" % (a.shape, b.shape)
----> 3 assert a.shape == b.shape, message
4
5
AssertionError: (3, 3) does not have equal shape with (4, 4)
There was a problem hiding this comment.
We should not use assert if the check must be done in any situation (including with optimize flags). I would say no.
My opinion on this is to put this function in _shared/utils.py, below assert_nD, and rename these functions to do not use the word "assert". Like check_nD, check_shape_equality.
This can be addressed in another PR. These functions are not in the public API, it won't be painful to change this later.
| for connectomics. Front. Neuroanat. 9:142. | ||
| :DOI:`10.3389/fnana.2015.00142` | ||
| """ | ||
| assert_shape_equal(im_true, im_test) |
There was a problem hiding this comment.
This comment follows another inline comment I made where this function is defined.
I don't like calling this function assert_something, because it does not call assert. And this is important. Assert statements are removed if python is called with an optimization flag.
So, assert_shape_equal is not written in the right file. I'm not sure where it can fit the best and I'm not certain that we want this sort of functions in scikit-image. @scikit-image/core Thoughts?
| (im_true.ravel(), im_test.ravel())), | ||
| dtype=float).tocsr() | ||
| table2 = contingency_table(im_true, im_test, normalize=True) | ||
| (table1 != table2).nnz == 0 |
There was a problem hiding this comment.
| (table1 != table2).nnz == 0 | |
| assert (table1 != table2).nnz == 0 |
?
There was a problem hiding this comment.
This tests if the contingency_table function is working, forgot the assert. I changed the test to be more legible
def test_contingency_table():
im_true = np.array([1, 2, 3, 4])
im_test = np.array([1, 1, 8, 8])
table1 = np.array([[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0.25, 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0.25, 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.25],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.25]])
sparse_table2 = contingency_table(im_true, im_test, normalize=True)
table2 = sparse_table2.toarray()
assert_array_equal(table1, table2)
| ax[5].set_title('Morphological GAC') | ||
| ax[5].set_axis_off() | ||
|
|
||
| plt.show() |
There was a problem hiding this comment.
Ah yikes, I changed the figure size and it looks good on my end.
Co-Authored-By: François Boulogne <[email protected]>
Co-Authored-By: François Boulogne <[email protected]>
Co-Authored-By: François Boulogne <[email protected]>
Co-Authored-By: François Boulogne <[email protected]>
Co-Authored-By: François Boulogne <[email protected]>
|
Hi everyone, apologies that I don't have time for a thorough review right now, but I just wanted to chime in on the module name. imho "metrics" is too precise. Even semi-metrics don't cut it — in some cases, we are measuring similarity, not distance. imho, we should go with something along the lines of "evaluation", "evaluate", "performance", ... For me, a non-mathematician, "metrics" just sounds too vague. I wouldn't know to look there. |
|
I'll also note, I don't necessarily want this debate to hold the merge up — I think this is going to be a prolonged debate and we should not clutter the discussion here. |
|
Thanks for the feedback all! |

Description
This pull request supersedes #3354 and addresses #2345. It refactors @seanbudd's original PR into a new
skimage.evaluatemodule, moving simple metrics (mse, nrmse, psnr) and segmentation metrics (adapted rand error, variation of information) intoevaluate.Citations for segmentation metrics:
Checklist
./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py.doc/release/release_dev.rst.@meeseeksdev backport to v0.14.x