internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: airctic/icevision

Issue:
Hub Detr fine tuning
Following the first relase of Detr on hub, it would be a very good idea to support fine tuning.

[this](https://github.com/facebookresearch/detr/issues/9) thread should be helpful, and [this](https://gist.github.com/mlk1337/651297e28199b4bb7907fc413c49f58f) gist has the high level overview on how to implement it.


Discussion:
For those coming from the linked issue, I'm sorry, I accidentally linked it lol

Well, keep an eye open, this will soon be ready and I hope this will make it very easy to pretrain detr =)

Resolving patch:
diff --git a/examples/detr_wheat.py b/examples/detr_wheat.py
--- a/examples/detr_wheat.py
+++ b/examples/detr_wheat.py
@@ -30,17 +30,17 @@ def height(self, o) -> int:
     def width(self, o) -> int:
         return o.width
 
-    def label(self, o) -> int:
-        return 1
+    def label(self, o) -> List[int]:
+        return [1]
 
-    def bbox(self, o) -> BBox:
-        return self.bbox
+    def bbox(self, o) -> List[BBox]:
+        return [self.bbox]
 
-    def area(self, o) -> float:
-        return self.bbox.area
+    def area(self, o) -> List[float]:
+        return [self.bbox.area]
 
-    def iscrowd(self, o) -> bool:
-        return 0
+    def iscrowd(self, o) -> List[bool]:
+        return [0]
 
 
 def get_datasets(args):
@@ -62,7 +62,12 @@ def get_datasets(args):
     # adds new arguments to original args_parser
     args_parser = get_args_parser()
     args_parser.add_argument("--data_path", type=str)
+    args_parser.add_argument("--num_classes", type=int, default=None)
+    args_parser.add_argument("--fine_tune", action="store_true")
     args = args_parser.parse_args()
 
+    if args.fine_tune:
+        args.resume = detr_pretrained_checkpoint_base()
+
     train_dataset, valid_dataset = get_datasets(args)
     run_detr(args=args, dataset_train=train_dataset, dataset_val=valid_dataset)


Test patch:
Repository: airctic/icevision

Issue:
helper function for COCO parser
## 🚀 Feature
**Is your feature request related to a problem? Please describe.**
As described in #79, it's currently very verbose to create a COCO parser, the steps should be ideally be reduced to a single function call.

**Dream API**
```python
    parser = datasets.coco.parser(
        annotations_file="path_to_annotations.json",
        img_dir="path_to_images_dir",
    )
```



Discussion:

Resolving patch:
diff --git a/mantisshrimp/datasets/coco/parsers.py b/mantisshrimp/datasets/coco/parsers.py
--- a/mantisshrimp/datasets/coco/parsers.py
+++ b/mantisshrimp/datasets/coco/parsers.py
@@ -1,9 +1,23 @@
-__all__ = ["COCOImageInfoParser", "COCOAnnotationParser"]
+__all__ = ["parser", "COCOImageInfoParser", "COCOAnnotationParser"]
 
 from mantisshrimp.imports import *
 from mantisshrimp.core import *
-from mantisshrimp.parsers.defaults import *
-from mantisshrimp.parsers.mixins import *
+from mantisshrimp.parsers import *
+
+
+def parser(
+    annotations_file: Union[str, Path], img_dir: Union[str, Path]
+) -> ParserInterface:
+    annotations_dict = json.loads(Path(annotations_file).read())
+
+    image_info_parser = COCOImageInfoParser(
+        infos=annotations_dict["images"], img_dir=img_dir
+    )
+    annotations_parser = COCOAnnotationParser(
+        annotations=annotations_dict["annotations"]
+    )
+
+    return CombinedParser(image_info_parser, annotations_parser)
 
 
 class COCOImageInfoParser(DefaultImageInfoParser):


Test patch:
diff --git a/mantisshrimp/test_utils/samples.py b/mantisshrimp/test_utils/samples.py
--- a/mantisshrimp/test_utils/samples.py
+++ b/mantisshrimp/test_utils/samples.py
@@ -20,12 +20,14 @@
 
 def sample_image_info_parser():
     return datasets.coco.COCOImageInfoParser(
-        annotations_dict["images"], source / "images"
+        infos=annotations_dict["images"], img_dir=source / "images"
     )
 
 
 def sample_annotation_parser():
-    return datasets.coco.COCOAnnotationParser(annotations_dict["annotations"])
+    return datasets.coco.COCOAnnotationParser(
+        annotations=annotations_dict["annotations"]
+    )
 
 
 def sample_combined_parser():
diff --git a/tests/datasets/coco/__init__.py b/tests/datasets/coco/__init__.py
new file mode 100644
diff --git a/tests/datasets/coco/test_parser.py b/tests/datasets/coco/test_parser.py
new file mode 100644
--- /dev/null
+++ b/tests/datasets/coco/test_parser.py
@@ -0,0 +1,21 @@
+import pytest
+from mantisshrimp import *
+
+
+def test_coco_parser(samples_source):
+    parser = datasets.coco.parser(
+        annotations_file=samples_source / "annotations.json",
+        img_dir=samples_source / "images",
+    )
+
+    records = parser.parse()[0]
+    assert len(records) == 5
+
+    record = records[0]
+    assert record["imageid"] == 0
+    assert record["filepath"] == samples_source / "images/000000128372.jpg"
+    assert record["height"] == 427
+    assert record["width"] == 640
+
+    assert record["labels"] == [6, 1, 1, 1, 1, 1, 1, 1, 31, 31, 1, 3, 31, 1, 31, 31]
+    assert pytest.approx(record["bboxes"][0].xywh) == [0, 73.89, 416.44, 305.13]
Repository: airctic/icevision

Issue:
icedata is missing in the example code snippets
## 🐛 Bug
**Describe the bug**
The examples code snippets are not using icedata package

**Solution**
- Add `import icedata`
- Replace `load()` by `load_data`


Discussion:
Ow yeah... I totally forgot about those

Resolving patch:
diff --git a/docs/autogen.py b/docs/autogen.py
--- a/docs/autogen.py
+++ b/docs/autogen.py
@@ -64,7 +64,9 @@
         "icevision.models.rcnn.mask_rcnn.dataloaders.build_valid_batch",
         "icevision.models.rcnn.mask_rcnn.dataloaders.build_infer_batch",
     ],
-    "mask_rcnn_fastai.md": ["icevision.models.rcnn.mask_rcnn.fastai.learner.learner",],
+    "mask_rcnn_fastai.md": [
+        "icevision.models.rcnn.mask_rcnn.fastai.learner.learner",
+    ],
     "mask_rcnn_lightning.md": [
         "icevision.models.rcnn.mask_rcnn.lightning.model_adapter.ModelAdapter",
     ],
@@ -77,7 +79,9 @@
         "icevision.models.efficientdet.dataloaders.build_valid_batch",
         "icevision.models.efficientdet.dataloaders.build_infer_batch",
     ],
-    "efficientdet_fastai.md": ["icevision.models.efficientdet.fastai.learner.learner",],
+    "efficientdet_fastai.md": [
+        "icevision.models.efficientdet.fastai.learner.learner",
+    ],
     "efficientdet_lightning.md": [
         "icevision.models.efficientdet.lightning.model_adapter.ModelAdapter",
     ],
@@ -258,7 +262,7 @@ def generate(dest_dir: Path):
 
     # Copy CNAME file
     shutil.copyfile(icevision_dir / "CNAME", dest_dir / "CNAME")
-    
+
     # Copy web manifest
     shutil.copyfile("manifest.webmanifest", dest_dir / "manifest.webmanifest")
 
@@ -284,7 +288,8 @@ def generate(dest_dir: Path):
     # Copy static .md files from the docs folder
     shutil.copyfile(icevision_dir / "docs/INSTALL.md", dest_dir / "install.md")
     shutil.copyfile(
-        icevision_dir / "docs/HOW-TO.md", dest_dir / "how-to.md",
+        icevision_dir / "docs/HOW-TO.md",
+        dest_dir / "how-to.md",
     )
     shutil.copyfile(icevision_dir / "docs/ABOUT.md", dest_dir / "about.md")
 
@@ -299,7 +304,8 @@ def generate(dest_dir: Path):
 
     # Copy static .md files from the other folders
     shutil.copyfile(
-        icevision_dir / "icevision/models/README.md", dest_dir / "model_comparison.md",
+        icevision_dir / "icevision/models/README.md",
+        dest_dir / "model_comparison.md",
     )
 
     shutil.copyfile(
@@ -323,7 +329,8 @@ def generate(dest_dir: Path):
     )
 
     shutil.copyfile(
-        icevision_dir / "icevision/tfms/README.md", dest_dir / "albumentations.md",
+        icevision_dir / "icevision/tfms/README.md",
+        dest_dir / "albumentations.md",
     )
 
     # Copy .md examples files to destination examples folder


Test patch:
Repository: airctic/icevision

Issue:
Add icedata to icevision.all
## 🚀 Feature
Currently to train a dataset available with icedata the following two lines are necessary:
```python
import icedata
from icevision.all import *
```

Because icedata already depends on icevision, icevision cannot depend on icedata. **But** I guess we can add icedata as a soft dependency to `.all`, we just have to be sure not to use `icedata` internally in icevision.


Discussion:

Resolving patch:
diff --git a/icevision/all.py b/icevision/all.py
--- a/icevision/all.py
+++ b/icevision/all.py
@@ -1,2 +1,9 @@
 from icevision.imports import *
 from icevision import *
+
+# soft import icedata
+try:
+    import icedata
+except ModuleNotFoundError as e:
+    if str(e) != f"No module named 'icedata'":
+        raise e


Test patch:
Repository: airctic/icevision

Issue:
Add tutorial with hard negative samples
## 📓 Documentation Update
"how to use an image as background annotation" is a common question. We can provide a tutorial showing how to do that

### Racoon and dogs
If you train a model on the racoon dataset and show the model a picture of a dog it will classify it as a racoon. We can add images of dogs to the dataset (without any annotations) and show how the difference of model performance in both scenarios.


Discussion:

Resolving patch:
diff --git a/icevision/models/base_show_results.py b/icevision/models/base_show_results.py
--- a/icevision/models/base_show_results.py
+++ b/icevision/models/base_show_results.py
@@ -18,7 +18,7 @@ def base_show_results(
     denormalize_fn: Optional[callable] = denormalize_imagenet,
     show: bool = True,
 ) -> None:
-    samples = [dataset[i] for i in range(num_samples)]
+    samples = random.choices(dataset, k=num_samples)
     batch, samples = build_infer_batch_fn(samples)
     preds = predict_fn(model, batch)
 


Test patch:
Repository: airctic/icevision

Issue:
EfficientDet images_size has to be divisible by 128
## 📓 Documentation Update
**What part of documentation was unclear or wrong?**
It has to be clear that the image size for the efficientdet model has to be divisible by 128

**Describe the solution you'd like**
Add this information to the `efficientdet/model.py` docstring and also make it explicit in the tutorials that use efficientdet.





Discussion:

Resolving patch:
diff --git a/icevision/models/efficientdet/model.py b/icevision/models/efficientdet/model.py
--- a/icevision/models/efficientdet/model.py
+++ b/icevision/models/efficientdet/model.py
@@ -20,7 +20,7 @@ def model(
             [this](https://github.com/rwightman/efficientdet-pytorch#models) table.
         num_classes: Number of classes of your dataset (including background).
         img_size: Image size that will be fed to the model. Must be squared and
-            divisible by 64.
+            divisible by 128.
         pretrained: If True, use a pretrained backbone (on COCO).
 
     # Returns


Test patch:
Repository: airctic/icevision

Issue:
Add support for MMDetection CorneNet and CentriPetalNet
## 🚀 Feature
**Is your feature request related to a problem? Please describe.**
Add support for MMDetection CorneNet and CentriPetalNet


Discussion:

Resolving patch:
diff --git a/icevision/models/mmdet/models/__init__.py b/icevision/models/mmdet/models/__init__.py
--- a/icevision/models/mmdet/models/__init__.py
+++ b/icevision/models/mmdet/models/__init__.py
@@ -2,6 +2,8 @@
 from icevision.models.mmdet.models import faster_rcnn
 from icevision.models.mmdet.models import retinanet
 from icevision.models.mmdet.models import fcos
+from icevision.models.mmdet.models import cornernet
+from icevision.models.mmdet.models import centripetalnet
 
 # segmentation
 from icevision.models.mmdet.models import mask_rcnn
diff --git a/icevision/models/mmdet/models/centripetalnet/__init__.py b/icevision/models/mmdet/models/centripetalnet/__init__.py
new file mode 100644
--- /dev/null
+++ b/icevision/models/mmdet/models/centripetalnet/__init__.py
@@ -0,0 +1 @@
+from icevision.models.mmdet.common.bbox.single_stage import *
diff --git a/icevision/models/mmdet/models/cornernet/__init__.py b/icevision/models/mmdet/models/cornernet/__init__.py
new file mode 100644
--- /dev/null
+++ b/icevision/models/mmdet/models/cornernet/__init__.py
@@ -0,0 +1 @@
+from icevision.models.mmdet.common.bbox.single_stage import *


Test patch:
Repository: airctic/icevision

Issue:
Fix the readme docs, and code snippet links
readme docs points to 404
code snippet is out-dated




Discussion:

Resolving patch:
diff --git a/docs/autogen.py b/docs/autogen.py
--- a/docs/autogen.py
+++ b/docs/autogen.py
@@ -418,6 +418,12 @@ def generate(dest_dir: Path):
         dest_dir / "backbones.md",
     )
 
+    # README DOCS
+    shutil.copyfile(
+        icevision_dir / "docs/README.md",
+        dest_dir / "readme_mkdocs.md",
+    )
+
 
 if __name__ == "__main__":
     generate(icevision_dir / "docs" / "sources")


Test patch:
Repository: airctic/icevision

Issue:
Adding Non Unique Names To ClassMap Must Be Illegal
Currently, `add_name` doesn't check if the added `name` is a duplicate or not. This should be illegal, as classes must be unique

https://github.com/airctic/icevision/blob/82f3c7322d5adbc41d6a1b7b9e4327eb32ad23c4/icevision/core/class_map.py#L47-L51


Discussion:
valid point! up for a PR rahuuuul? =)

Resolving patch:
diff --git a/icevision/core/class_map.py b/icevision/core/class_map.py
--- a/icevision/core/class_map.py
+++ b/icevision/core/class_map.py
@@ -44,7 +44,13 @@ def get_by_name(self, name: str) -> int:
             else:
                 raise e
 
-    def add_name(self, name) -> int:
+    def add_name(self, name: str) -> int:
+        # Raise error if trying to add duplicate value
+        if name in self._id2class:
+            raise ValueError(
+                f"'{name}' already exists in the ClassMap. You can only add new labels that are unique"
+            )
+
         self._id2class.append(name)
         id = len(self._class2id)
         self._class2id[name] = id


Test patch:
diff --git a/tests/core/test_class_map.py b/tests/core/test_class_map.py
--- a/tests/core/test_class_map.py
+++ b/tests/core/test_class_map.py
@@ -26,3 +26,6 @@ def test_class_map_safety(classes):
     class_map = ClassMap(classes, background=None)
     classes.insert(0, "x")
     assert class_map.get_by_id(0) == "a"
+
+    with pytest.raises(ValueError):
+        class_map.add_name(class_map._id2class[0])
Repository: airctic/icevision

Issue:
Add EfficientDet AdvProp-AA
## 🚀 Feature
Add EfficientDet AdvProp-AA pretrained backbones  for D0-D5

See https://github.com/google/automl/blob/master/efficientdet/Det-AdvProp.md


Discussion:

Resolving patch:
diff --git a/icevision/models/ross/efficientdet/backbones.py b/icevision/models/ross/efficientdet/backbones.py
--- a/icevision/models/ross/efficientdet/backbones.py
+++ b/icevision/models/ross/efficientdet/backbones.py
@@ -21,6 +21,12 @@
     "d6",
     "d7",
     "d7x",
+    "tf_d0_ap",
+    "tf_d1_ap",
+    "tf_d2_ap",
+    "tf_d3_ap",
+    "tf_d4_ap",
+    "tf_d5_ap",
 ]
 
 from icevision.models.ross.efficientdet.utils import *
@@ -50,3 +56,10 @@
 d6 = EfficientDetBackboneConfig(model_name="efficientdet_d6")
 d7 = EfficientDetBackboneConfig(model_name="efficientdet_d7")
 d7x = EfficientDetBackboneConfig(model_name="efficientdet_d7x")
+
+tf_d0_ap = EfficientDetBackboneConfig(model_name="tf_efficientdet_d0_ap")
+tf_d1_ap = EfficientDetBackboneConfig(model_name="tf_efficientdet_d1_ap")
+tf_d2_ap = EfficientDetBackboneConfig(model_name="tf_efficientdet_d2_ap")
+tf_d3_ap = EfficientDetBackboneConfig(model_name="tf_efficientdet_d3_ap")
+tf_d4_ap = EfficientDetBackboneConfig(model_name="tf_efficientdet_d4_ap")
+tf_d5_ap = EfficientDetBackboneConfig(model_name="tf_efficientdet_d5_ap")


Test patch:
diff --git a/tests/models/efficient_det/test_model.py b/tests/models/efficient_det/test_model.py
--- a/tests/models/efficient_det/test_model.py
+++ b/tests/models/efficient_det/test_model.py
@@ -10,6 +10,9 @@
         d0,
         d1,
         d2,
+        tf_d0_ap,
+        tf_d1_ap,
+        tf_d2_ap,
         tf_d0,
         tf_d1,
         tf_d2,
Repository: airctic/icevision

Issue:
Fix download_mmdet_configs
No need to download the zip file if it exists. This will solve the issue encountered in the Kaggle offline installation.



Discussion:

Resolving patch:
diff --git a/icevision/models/mmdet/download_configs.py b/icevision/models/mmdet/download_configs.py
--- a/icevision/models/mmdet/download_configs.py
+++ b/icevision/models/mmdet/download_configs.py
@@ -9,12 +9,26 @@
 
 def download_mmdet_configs() -> Path:
     save_dir = get_root_dir() / f"mmdetection_configs"
-    save_dir.mkdir(parents=True, exist_ok=True)
 
+    mmdet_config_path = save_dir / f"mmdetection_configs-{VERSION[1:]}/configs"
     download_path = save_dir / f"{VERSION}.zip"
-    if not download_path.exists():
-        logger.info("Downloading mmdet configs")
 
-        download_and_extract(f"{BASE_URL}/{VERSION}", download_path)
+    if mmdet_config_path.exists():
+        logger.info(
+            f"The mmdet config folder already exists. No need to downloaded it. Path : {mmdet_config_path}"
+        )
+    elif download_path.exists():
+        # The zip file was downloaded by not extracted yet
+        # Extract zip file
+        logger.info(f"Extracting the {VERSION}.zip file.")
+        save_dir = Path(download_path).parent
+        shutil.unpack_archive(filename=str(download_path), extract_dir=str(save_dir))
+    else:
+        save_dir.mkdir(parents=True, exist_ok=True)
 
-    return save_dir / f"mmdetection_configs-{VERSION[1:]}/configs"
+        download_path = save_dir / f"{VERSION}.zip"
+        if not download_path.exists():
+            logger.info("Downloading mmdet configs")
+            download_and_extract(f"{BASE_URL}/{VERSION}", download_path)
+
+    return mmdet_config_path


Test patch:
Repository: airctic/icevision

Issue:
Add kwargs to EfficientDet model() method
Add kwargs to EfficientDet model() method. This will allow to pass `pretrained_backbone` argument to EfficientDet `create_model_from_config()` method. That will prevent loading pretrained weights if the user wish to do so


Discussion:

Resolving patch:
diff --git a/icevision/models/ross/efficientdet/model.py b/icevision/models/ross/efficientdet/model.py
--- a/icevision/models/ross/efficientdet/model.py
+++ b/icevision/models/ross/efficientdet/model.py
@@ -13,6 +13,7 @@ def model(
     backbone: EfficientDetBackboneConfig,
     num_classes: int,
     img_size: int,
+    **kwargs,
 ) -> nn.Module:
     """Creates the efficientdet model specified by `model_name`.
 
@@ -39,6 +40,7 @@ def model(
         bench_labeler=True,
         num_classes=num_classes - 1,
         pretrained=backbone.pretrained,
+        **kwargs,
     )
 
     # TODO: Break down param groups for backbone


Test patch:
Repository: airctic/icevision

Issue:
Pillow Image class has no attribute shape
## 🐛 Bug
**Describe the bug**
Pillow Image class has no attribute shape. When using open_image function from utils/image_io.py the shape property is not defined for Pil Image class. 

This has been changed in 0.8.1 where we return PIL image instead of numpy array. To fix this one should try to access Image.height and Image.width fields instead or read these values from Image.size property.


**Expected behavior**
The show_records should be able to open the image without issues.

**Screenshots**
```python
show_records(records[:1])
```
![obraz](https://user-images.githubusercontent.com/52150545/125317783-8d685c80-e339-11eb-8e78-96c671729109.png)

**Desktop (please complete the following information):**
 - OS: Windows 10

**Additional context**
https://github.com/airctic/icevision/blob/d731a1c3d4a99c9bc9a887fd06c6fd82f0b1e76b/icevision/core/record_components.py#L118



Discussion:
this might be coming from the python poetry installation file. It is reproducible if icevision=0.8.1 is installed without specifying [all] egg


Resolving patch:
diff --git a/icevision/core/record_components.py b/icevision/core/record_components.py
--- a/icevision/core/record_components.py
+++ b/icevision/core/record_components.py
@@ -115,7 +115,7 @@ def set_img(self, img: Union[PIL.Image.Image, np.ndarray]):
         assert isinstance(img, (PIL.Image.Image, np.ndarray))
         self.img = img
         if isinstance(img, PIL.Image.Image):
-            height, width = img.shape
+            width, height = img.size
         elif isinstance(img, np.ndarray):
             # else:
             height, width, _ = self.img.shape
@@ -136,7 +136,7 @@ def _repr(self) -> List[str]:
                     )
                 return [f"Img: {width}x{height}x{channels} <np.ndarray> Image"]
             elif isinstance(self.img, PIL.Image.Image):
-                height, width = self.img.shape
+                width, height = self.img.size
                 return [f"Img: {width}x{height} <PIL.Image; mode='{self.img.mode}'>"]
         else:
             return [f"Img: {self.img}"]


Test patch:
Repository: airctic/icevision

Issue:
Efficientdet inference returns wrong bbox predictions
## 🐛 Bug
When running inference on efficientdet models, the predictions are squeezed to only fit square aspect ratio. This problem is only visible when running efficientdet in rectangular input shape (eg 512x768). Here is a screenshot of default behavior:
![image](https://user-images.githubusercontent.com/52150545/130605997-de6572df-e9f0-4939-aa1b-3787d88ffd72.png)

Note that predictions are squezzed, seemingly to only square image resolution. I have discovered that the bug comes from `process_infer_record` function, where the image input shape is passed to effdet in the wrong notation (H, W instead of W, H).

I applied that fix and the result is working as expected:
![image](https://user-images.githubusercontent.com/52150545/130606249-2f6610bf-1044-41d1-abf8-597fbf3562a5.png)


**To Reproduce**
Steps to reproduce the behavior:
1. Train efficientdet model in rectangular image input shape
2. Run inference




Discussion:

Resolving patch:
diff --git a/icevision/models/ross/efficientdet/dataloaders.py b/icevision/models/ross/efficientdet/dataloaders.py
--- a/icevision/models/ross/efficientdet/dataloaders.py
+++ b/icevision/models/ross/efficientdet/dataloaders.py
@@ -179,7 +179,7 @@ def process_train_record(record) -> tuple:
 def process_infer_record(record) -> tuple:
     """Extracts information from record and prepares a format required by the EffDet inference"""
     image = im2tensor(record.img)
-    image_size = image.shape[-2:]
+    n_channels, image_height, image_width = image.shape
     image_scale = 1.0
-
-    return image, image_size, image_scale
+    # EffDet expects image size to be passed in W, H notation
+    return image, (image_width, image_height), image_scale


Test patch: