Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

feat: Add Detection Task #56

Merged
merged 36 commits into from
Feb 10, 2021
Merged

Conversation

kaushikb11
Copy link
Contributor

@kaushikb11 kaushikb11 commented Feb 2, 2021

What does this PR do?

Add support for detection

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests? [not needed for typos/docs]
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@codecov
Copy link

codecov bot commented Feb 2, 2021

Codecov Report

Merging #56 (13f5106) into master (7acd8b5) will decrease coverage by 0.09%.
The diff coverage is 84.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #56      +/-   ##
==========================================
- Coverage   86.66%   86.56%   -0.10%     
==========================================
  Files          45       47       +2     
  Lines        1372     1526     +154     
==========================================
+ Hits         1189     1321     +132     
- Misses        183      205      +22     
Flag Coverage Δ
unittests 86.56% <84.75%> (-0.10%) ⬇️

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

Impacted Files Coverage Δ
flash/core/finetuning.py 88.46% <ø> (ø)
flash/vision/detection/model.py 67.27% <50.00%> (-32.73%) ⬇️
flash/vision/detection/data.py 94.06% <94.06%> (ø)
flash/vision/__init__.py 100.00% <100.00%> (ø)
flash/vision/detection/__init__.py 100.00% <100.00%> (ø)
flash/vision/detection/finetuning.py 100.00% <100.00%> (ø)
flash/vision/classification/data.py 77.77% <0.00%> (-0.35%) ⬇️
flash/core/data/datapipeline.py 100.00% <0.00%> (+3.44%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7acd8b5...3330387. Read the comment docs.

@kaushikb11 kaushikb11 changed the title Add DataModules for detection Add support for detection Feb 2, 2021
@kaushikb11 kaushikb11 added the task flash Task label Feb 2, 2021
@teddykoker
Copy link
Contributor

Great work! do you know if there are any small datasets we could use to test?

@kaushikb11
Copy link
Contributor Author

Great work! do you know if there are any small datasets we could use to test?

I found a toy COCO format dataset link. The author uses it in this repo.

@zhiqwang
Copy link

zhiqwang commented Feb 3, 2021

Great work! do you know if there are any small datasets we could use to test?

I found a toy COCO format dataset link. The author uses it in this repo.

Hi, ultralytics provided a small coco datasets named coco128 here (It is a subset of COCO Datasets), they are using DarkNet like format, but I've converted it to COCO format, if you are interested on this, I can upload the converted COCO file.

EDIT: I've uploaded the COCO label here. (Check the file instead in https://github.com/zhiqwang/yolov5-rt-stack/releases/download/v0.3.0/coco128.zip)

@kaushikb11
Copy link
Contributor Author

@zhiqwang Thank you, will look into it!

@zhiqwang
Copy link

zhiqwang commented Feb 3, 2021

Hi @kaushikb11, I upload the whole folder containing images here for easy of use. The COCO format file are also in this folder.

@kaushikb11
Copy link
Contributor Author

kaushikb11 commented Feb 3, 2021

Hi @kaushikb11, I upload the whole folder containing images here for easy of use. The COCO format file are also in this folder.

@zhiqwang Could you update file_name in images section from path(images/train2017/000000000612.jpg) to filename(000000000612.jpg)?

@zhiqwang
Copy link

zhiqwang commented Feb 4, 2021

Hi @kaushikb11 okay, I'll reupload the label file soon.

EDIT: Done, you can redownload the https://github.com/zhiqwang/yolov5-rt-stack/releases/download/v0.3.0/coco128.zip.

@kaushikb11
Copy link
Contributor Author

@zhiqwang: The annotations don't seem to be right. The categories are out of bounds. FOr eg., you could check id 12 in the annotation section which has category_id 86.

@zhiqwang
Copy link

zhiqwang commented Feb 4, 2021

Hi @kaushikb11, Sorry, and I'll double check it!

@zhiqwang
Copy link

zhiqwang commented Feb 4, 2021

Hi @kaushikb11

Indeed, COCO only has 80 classes, but they are not contiguous in their class indices. Indeed, as you can see from the colab notebook (which contains the class names), there are many N/A classes

CLASSES = [
    'N/A', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
    'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'N/A',
    'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse',
    'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'N/A', 'backpack',
    'umbrella', 'N/A', 'N/A', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis',
    'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove',
    'skateboard', 'surfboard', 'tennis racket', 'bottle', 'N/A', 'wine glass',
    'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich',
    'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake',
    'chair', 'couch', 'potted plant', 'bed', 'N/A', 'dining table', 'N/A',
    'N/A', 'toilet', 'N/A', 'tv', 'laptop', 'mouse', 'remote', 'keyboard',
    'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'N/A',
    'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier',
    'toothbrush'
]

So the total number of classes is 91 here.

REF: facebookresearch/detr#23 (comment)

@zhiqwang
Copy link

zhiqwang commented Feb 4, 2021

Hi @kaushikb11

One option here to solve the category inconsistent problem is through the category mapping like:

json_category_id_to_contiguous_id = {
    v: i for i, v in enumerate(example_coco.getCatIds())
}

Thoughts?

@kaushikb11
Copy link
Contributor Author

@zhiqwang I have handled the case, we wouldn’t want to change the category mapping. Thanks!

@kaushikb11 kaushikb11 marked this pull request as ready for review February 4, 2021 13:40
Copy link
Contributor

@teddykoker teddykoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one question. Do you think we could add some tests here? Would be great to get code coverage > 90%

flash/vision/detection/finetuning.py Show resolved Hide resolved
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work there ! You aced it !

flash/vision/detection/data.py Outdated Show resolved Hide resolved
flash/vision/detection/model.py Show resolved Hide resolved
flash/vision/detection/model.py Show resolved Hide resolved
flash/vision/detection/model.py Outdated Show resolved Hide resolved
flash_examples/finetuning/image_detection.py Show resolved Hide resolved
flash_examples/finetuning/image_detection.py Show resolved Hide resolved
tests/vision/detection/test_data.py Outdated Show resolved Hide resolved
flash/vision/detection/data.py Outdated Show resolved Hide resolved
flash/vision/detection/data.py Outdated Show resolved Hide resolved
flash/vision/detection/data.py Outdated Show resolved Hide resolved
flash/vision/detection/dataset.py Outdated Show resolved Hide resolved
flash/vision/detection/finetuning.py Show resolved Hide resolved
requirements.txt Show resolved Hide resolved
Copy link
Member

@justusschock justusschock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaushikb11 looking good already. just pointing out some things hat should be adressed. The collate thing is the only blocker from my side :)

flash/vision/detection/data.py Show resolved Hide resolved
flash/vision/detection/data.py Show resolved Hide resolved
flash/vision/detection/data.py Outdated Show resolved Hide resolved
flash/vision/detection/data.py Show resolved Hide resolved
@kaushikb11 kaushikb11 changed the title Add support for detection feat: Add Detection Task Feb 9, 2021
@kaushikb11 kaushikb11 enabled auto-merge (squash) February 10, 2021 14:19
def collate(self, samples: Any) -> Any:
if not isinstance(samples, Tensor):
elem = samples[0]
if isinstance(elem, container_abcs.Sequence):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoudn't you use typing.Sequence?

@edenlightning
Copy link
Contributor

Nice work! Can you please add docs here too?

@kaushikb11
Copy link
Contributor Author

Nice work! Can you please add docs here too?

Where should we add it? Also will do a follow up PR for docs. Better for review.

@Borda Borda disabled auto-merge February 10, 2021 20:28
@Borda Borda merged commit c60fef8 into Lightning-Universe:master Feb 10, 2021
@williamFalcon
Copy link
Contributor

@kaushikb11 @Borda @edenlightning can we add docs for this?

@kaushikb11
Copy link
Contributor Author

@williamFalcon On it!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
task flash Task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants