MapReader
MapReader copied to clipboard
Update context model code
Summary
The current version of MapReader contains unused/untested code for using the patch context when training the model. From the 2021 paper:
"Context-aware patchwork method.
A limitation of the patchwork method is that it ignores neighboring patches when training or performing model inference. To capture the strong, spatial dependencies between neighboring patches (which will be common in maps for many types of labels [16]), MapReader supports building model ensembles as shown in Fig. 8. Model-1 and Model-2 are two CV models with neural network architectures defined by the user. These models can have different or similar architectures. For exam- ple, in one of our experiments, Model-2 was a pre-trained model on our patch dataset while Model-1 was a pre-trained model from PyTorch Image Models [40] with a different architecture. As shown in Fig. 8, a patch and its context image are fed into Model-2 and Model-1, respectively. In practice, the user only specifies the size of the context image, and MapReader extracts and preprocesses the context image from the dataset. Model-1 and Model-2 generate vector representations for the input images, V1 and V2. The size of these vectors are defined by the user and a combination of the two (e.g., by concatenation) is then fed into Model-3 for prediction. Such model ensembles can be an efficient approach to achieving high- performing CV models [37]."
This PR updates this code to be more simple/user-friendly.
Fixes #287 Addresses #17
Describe your changes
- Both
PatchDataset
andPatchContextDataset
return image(s) as tuples. These datasets now return(img,)
and(img, context_img)
respectively. - Classifier handles "inputs" as tuples (so now can handle both context and normal inputs)
- Add
context_dataset
arg when creating datasets to enable creating of 'PatchContextDataset' type datasets from the annotations loader. - Update
twoParrellelModels
class to clarify patch/context branches of the model - Update
generate_layerwise_lrs
method for context datasets
Checklist before assigning a reviewer (update as needed)
- [x] Self-review code
- [x] Ensure submission passes current tests
- [ ] Add tests
- [x] Update relevant docs
Reviewer checklist
Please add anything you want reviewers to specifically focus/comment on.
- [ ] Everything looks ok?
@all-contributors add @rwood-97 for code
Things still to do:
- [x] Check annotator works for edge patches
- [x] Think about how to annotate context patches
- [x] Geotiff saving!!!
Codecov Report
Attention: 31 lines
in your changes are missing coverage. Please review.
Comparison is base (
566e602
) 59.58% compared to head (11afa54
) 61.60%. Report is 2 commits behind head on main.
:exclamation: Current head 11afa54 differs from pull request most recent head a5e36ca. Consider uploading reports for the commit a5e36ca to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## main #296 +/- ##
==========================================
+ Coverage 59.58% 61.60% +2.01%
==========================================
Files 35 34 -1
Lines 6164 5949 -215
==========================================
- Hits 3673 3665 -8
+ Misses 2491 2284 -207
Flag | Coverage Δ | |
---|---|---|
unittests | 61.60% <65.55%> (+2.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Current workflow is:
- patchify as normal - there is no longer the
square_cuts
arg so now patches are always square but will be padded if at an edge - annotate at patch level by calling
annotate()
or context level by callingannotate_context()
. Annotations are saved as eitherfilename.csv
orfilename_context.csv
for patch or patch+context annotations respectively. You can only assign context labels to patches which you've annotated. - load context annotations (contains patch and context labels) and create patch context dataset.
__get_item__()
returns tuples of patch/context images and patch/context labels. - train context classifier (TODO)