icevision icon indicating copy to clipboard operation
icevision copied to clipboard

Introduce mosaic augmentation

Open potipot opened this issue 3 years ago • 11 comments

Fixes #587

  • [x] figure out how to attach mosaic as batch_tfms
  • [x] implement bbox unaware mosaic
  • [x] implement bbox safe crop mosaic with scaling
  • [ ] implement bbox safe crop without scaling (requires new Albumentation transform)
  • [ ] add tests (especially for negative samples - what happens if there is no bbox to "safely crop"?)

potipot avatar Dec 21 '21 10:12 potipot

some early results for bbox unaware mosaic image

potipot avatar Dec 21 '21 10:12 potipot

Codecov Report

Merging #1007 (e4b74db) into master (4050e0e) will decrease coverage by 0.28%. The diff coverage is 54.00%.

:exclamation: Current head e4b74db differs from pull request most recent head b7e64f1. Consider uploading reports for the commit b7e64f1 to get more accurate results

@@            Coverage Diff             @@
##           master    #1007      +/-   ##
==========================================
- Coverage   85.88%   85.59%   -0.29%     
==========================================
  Files         255      256       +1     
  Lines        5631     5679      +48     
==========================================
+ Hits         4836     4861      +25     
- Misses        795      818      +23     
Flag Coverage Δ
unittests 85.59% <54.00%> (-0.29%) :arrow_down:

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

Impacted Files Coverage Δ
icevision/tfms/batch/mosaic.py 48.88% <48.88%> (ø)
icevision/data/record_collection.py 100.00% <100.00%> (ø)
...sion/tfms/albumentations/albumentations_adapter.py 96.25% <100.00%> (ø)
icevision/tfms/batch/__init__.py 100.00% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Dec 21 '21 10:12 codecov[bot]

bbox aware mosaic with enforced scaling image

potipot avatar Dec 21 '21 12:12 potipot

what I want to achieve with non-scaling mosaic is keeping the original size of objects. The current scaled mosaic tries to encircle all of the bboxes in an image and make such crop, that will include all of the objects.

Another, smarter approach is to select exclusive areas in an image that can be cropped out and used as "pieces" in the mosaic.

potipot avatar Dec 21 '21 12:12 potipot

Can this be merged? It looks fantastic, and I've been struggling trying to implement one myself.

dav-ell avatar Mar 14 '22 18:03 dav-ell

@dav-ell Oh wow! I completely forgot about this one. Yeah I'll sync master changes and try to merge it as is. (the non-scaling mosaic aug is still TBD but if you find it useful as is then I'd say let's merge!)

potipot avatar Mar 15 '22 08:03 potipot

Thanks @potipot!

What a shame that I just finished my own custom implementation that I referenced here: https://github.com/albumentations-team/albumentations/issues/677#issuecomment-1068088671

The good news is that this one has more features than mine, so I'll almost definitely be switching over once it's in.

dav-ell avatar Mar 15 '22 15:03 dav-ell

This looks great. I am also looking for a similar functionality for object detection. I hope it can be merged soon =)

Modius22 avatar May 23 '22 14:05 Modius22

Any update on this?

mikel-brostrom avatar Jan 16 '23 14:01 mikel-brostrom

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Hi @mikel-brostrom, it's been a while since I worked on this. I just checked and it should be working. Do you mind giving it a try? you can install this PR in your venv by

pip install git+https://github.com/potipot/icevision@add_mosaic#egg=icevision[all]

here is the notebook showcasing how to use the mosaic tfm: https://github.com/potipot/icevision/blob/add_mosaic/notebooks/mosaic.ipynb

if it works for you I could put some more time into it and try to merge it.

potipot avatar Jan 17 '23 06:01 potipot