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

Improve show methods #511

Merged
merged 25 commits into from
Nov 18, 2024
Merged

Improve show methods #511

merged 25 commits into from
Nov 18, 2024

Conversation

rwood-97
Copy link
Collaborator

@rwood-97 rwood-97 commented Oct 10, 2024

Summary

Currently we have some very basic "show" methods for veiwing results. This is good for a quick look but would be better if we had some more advanced tools for visualising our results as part of the MapReader library.

Fixes #341
Address #478 - removed the utils.py file from annotate

Describe your changes

  • Updates the show methods in images.py, runner_base.py and rec_runner_base.py and adds explore_xx methods in each of these classes. Explore uses geopandas explore to create an interactive visualisation of results.
  • Also adds a check_georeferencing method ot the runners as this is needed to ensure we can convert to geo coords and therefore use the explore methods.
  • Adds infer_coords_from_patches method in images.py which uses patches to infer parent coords. This is for e.g. if you have loaded patches via the load_patches method and only added patch metadata (e.g. predictions).
  • Updates the way in which metrics are stored in classifier.py - now instead of train_loss_epoch and train_fscore_epoch as the key for a dict, we have nested dict with keys of train, val, etc and then within that keys of loss, fscore etc.
  • This enables simplification of the plot_metrics method, users now pass a list of metrics to plot (e.g. "loss", "fscore_micro", etc) and it will plot by default all phases. Can tell it just to plot for one phase by passing the phases argument.
  • I moved initialise model to the top of the file because it made sense to be grouped with the initialise_optimiser, initialise_scheduler etc methods.

Using the show_patches method:

image

Using the explore_patches method:

image image

Using explore_predictions method (i.e. the equivalent to explore_patches but for text spotting):

image

Checklist before assigning a reviewer (update as needed)

  • Self-review code
  • Ensure submission passes current tests
  • Add tests
  • Update relevant docs
  • Update changelog

Reviewer checklist

Please add anything you want reviewers to specifically focus/comment on.

  • Everything looks ok?

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 71.94093% with 133 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mapreader/classify/classifier.py 63.19% 60 Missing ⚠️
mapreader/spot_text/runner_base.py 34.88% 28 Missing ⚠️
mapreader/load/images.py 81.25% 24 Missing ⚠️
mapreader/spot_text/rec_runner_base.py 35.71% 18 Missing ⚠️
mapreader/classify/load_annotations.py 0.00% 3 Missing ⚠️
Flag Coverage Δ
unittests 77.66% <71.94%> (+3.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
mapreader/download/sheet_downloader.py 83.38% <100.00%> (+0.04%) ⬆️
mapreader/spot_text/deepsolo_runner.py 82.14% <ø> (ø)
mapreader/spot_text/dptext_detr_runner.py 89.55% <ø> (ø)
mapreader/spot_text/maptext_runner.py 82.75% <ø> (ø)
setup.py 0.00% <ø> (ø)
tests/test_classify/test_classifier.py 100.00% <100.00%> (ø)
tests/test_load/test_images.py 100.00% <100.00%> (ø)
mapreader/classify/load_annotations.py 59.29% <0.00%> (-0.64%) ⬇️
mapreader/spot_text/rec_runner_base.py 73.68% <35.71%> (-2.79%) ⬇️
mapreader/load/images.py 88.53% <81.25%> (+9.95%) ⬆️
... and 2 more

@kallewesterling
Copy link
Contributor

I really like this PR, @rwood-97. Haven't had time/been able to test run it yet. Do you need me to do that?

@rwood-97
Copy link
Collaborator Author

rwood-97 commented Nov 1, 2024

@kallewesterling I've updated the docs and two of the worked examples.
Could you potentially run the worked examples to check it all works

Maybe if you have time an ideal thing would be to use the docs to write an example of show_xx and explore_xxx methods (even if just getting up to that point in the worked examples I've updated and then writing your own cells instead of running the ones I've written if that makes sense.

Let me know what you have time for and I could potentially get @thobson88 or @kmcdono2 to check it.

@kallewesterling
Copy link
Contributor

@kallewesterling I've updated the docs and two of the worked examples. Could you potentially run the worked examples to check it all works

Maybe if you have time an ideal thing would be to use the docs to write an example of show_xx and explore_xxx methods (even if just getting up to that point in the worked examples I've updated and then writing your own cells instead of running the ones I've written if that makes sense.

Let me know what you have time for and I could potentially get @thobson88 or @kmcdono2 to check it.

Sorry for the late response! I'll check it out and will test run things.

I'll also use the docs to write an example of the show_xx and explore_xxx methods!

@kallewesterling
Copy link
Contributor

A few things:

  1. Weirdly, the annotator stopped working. I am running Python 3.9.20
    image

  2. ./models_tutorial/checkpoint_10.pkl cannot be found (my last checkpoint is 9):

    my_classifier = ClassifierContainer(
        model=None,
        labels_map=None,
        load_path="./models_tutorial/checkpoint_10.pkl",
    )
    
    ---------------------------------------------------------------------------
    FileNotFoundError                         Traceback (most recent call last)
    Cell In[77], [line 1](vscode-notebook-cell:?execution_count=77&line=1)
    ----> [1](vscode-notebook-cell:?execution_count=77&line=1) my_classifier = ClassifierContainer(
          [2](vscode-notebook-cell:?execution_count=77&line=2)     model=None,
          [3](vscode-notebook-cell:?execution_count=77&line=3)     labels_map=None,
          [4](vscode-notebook-cell:?execution_count=77&line=4)     load_path="./models_tutorial/checkpoint_10.pkl",
          [5](vscode-notebook-cell:?execution_count=77&line=5) )
    
    File ~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:130, in ClassifierContainer.__init__(self, model, labels_map, dataloaders, device, input_size, is_inception, load_path, force_device, **kwargs)
        [125](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:125)     print(
        [126](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:126)         "[WARNING] Ignoring ``labels_map`` as ``load_path`` is specified."
        [127](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:127)     )
        [129](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:129) # load object
    --> [130](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:130) self.load(load_path=load_path, force_device=force_device)
        [132](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:132) # add any extra dataloaders
        [133](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:133) if dataloaders:
    
    File ~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:1730, in ClassifierContainer.load(self, load_path, force_device)
       [1727](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:1727) mydevice = self.device
       [1729](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:1729) if not os.path.isfile(load_path):
    -> [1730](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:1730)     raise FileNotFoundError(f'[ERROR] "{load_path}" cannot be found.')
       [1732](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:1732) print(f'[INFO] Loading "{load_path}".')
       [1734](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:1734) with open(load_path, "rb") as myfile:
       [1735](https://file+.vscode-resource.vscode-cdn.net/Users/kwesterling/Desktop/temp/november-2024-mapreader/MapReader/worked_examples/geospatial/classification_one_inch_maps/~/Desktop/temp/november-2024-mapreader/MapReader/mapreader/classify/classifier.py:1735)     # objPickle = pickle.load(myfile)
    
    FileNotFoundError: [ERROR] "------------/models_tutorial/checkpoint_10.pkl" cannot be found.

@kallewesterling
Copy link
Contributor

Otherwise, looking good!

@kallewesterling
Copy link
Contributor

@rwood-97 Where in the docs do you think we should add the parts about these methods? As a new section under the post-processing step?

@rwood-97
Copy link
Collaborator Author

Re. docs, I've added them in the load docs as an extension of the old show methods.

I think the two issues in the worked examples are actually okay, I'm just working on moving these over to the worked-examples repo (dev branch) and have fixed them I thinkl

@kallewesterling
Copy link
Contributor

Oh, I see now that you've already added the methods to the documentation. Can you let me know what you need me to do with the docs, then, @rwood-97 ?

@rwood-97
Copy link
Collaborator Author

I think just have a quick look and check it makes sense would be ideal, otherwise I think this is good to merge

@rwood-97 rwood-97 merged commit 0999cf3 into main Nov 18, 2024
8 of 9 checks passed
@rwood-97 rwood-97 deleted the improve_show branch November 18, 2024 11:54
@kallewesterling
Copy link
Contributor

Wiho!! MERGED!!

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.

Update show() method to enable plotting of discrete data (e.g. labels) using legend rather than colormap
2 participants