Giter Club home page Giter Club logo

detectron2-helpers's Introduction

detectron2-helpers

Helpers for detectron2

DummyAlbuMapper allows you to use albumentations during fitting detectron2 for detection tasks.

It requires improvements to work with keypoints and masks.

To use custom dataset_mapper you also need to define new class Trainer with modified build_train_loader. Smth like this:

from detectron2.engine import DefaultTrainer


class Trainer(DefaultTrainer):
    @classmethod
    def build_train_loader(cls, cfg):
        mapper = DummyAlbuMapper(cfg, is_train=True)
        return build_detection_train_loader(cfg, mapper=mapper)

detectron2-helpers's People

Contributors

denilv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

detectron2-helpers's Issues

build_detection_train_loader

In the code that you write on README.MD, there's no implementation of build_detection_train_loader.

from detectron2.engine import DefaultTrainer


class Trainer(DefaultTrainer):
    @classmethod
    def build_train_loader(cls, cfg):
        mapper = DummyAlbuMapper(cfg, is_train=True)
        return build_detection_train_loader(cfg, mapper=mapper)

Is it from detectorn2.data import build_detection_train_loader ??

from detectorn2.data import build_detection_train_loader

Running Augmentation with register_coco_instances

Hello dnilv, thanks for your work!
I am having trouble running your augmentation helper. What am I doing wrong here? Is it possible to use your code with the register_coco_instances Dataset registration? Do you have any example 'how to use' notebook?

I registered the datasets with register_coco_instances:

from detectron2.data.datasets import register_coco_instances
for d in ["train", "test"]:
    register_coco_instances(f"dataset_{d}", {}, f"/content/{d}.json", f"/content/{d}")

Added this to the config:
cfg.INPUT.ALBUMENTATIONS = "/content/sample-detection-albu-config.json"

I am using your DummyAlbuMapper and used that to define a new Trainer instance:

class Trainer(DefaultTrainer):
    @classmethod
    def build_train_loader(cls, cfg):
        mapper = DummyAlbuMapper(cfg, is_train=True)
        return build_detection_train_loader(cfg, mapper=mapper)

trainer = Trainer(cfg)
trainer.train()

When I try to train the model I get following Error:

[06/29 23:04:24 d2.engine.train_loop]: Starting training from iteration 0
ERROR [06/29 23:04:25 d2.engine.train_loop]: Exception during training:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/detectron2/engine/train_loop.py", line 132, in train
    self.run_step()
  File "/usr/local/lib/python3.6/dist-packages/detectron2/engine/train_loop.py", line 215, in run_step
    loss_dict = self.model(data)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/detectron2/modeling/meta_arch/rcnn.py", line 130, in forward
    _, detector_losses = self.roi_heads(images, features, proposals, gt_instances)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/detectron2/modeling/roi_heads/roi_heads.py", line 669, in forward
    losses.update(self._forward_mask(features, proposals))
  File "/usr/local/lib/python3.6/dist-packages/detectron2/modeling/roi_heads/roi_heads.py", line 773, in _forward_mask
    return self.mask_head(mask_features, proposals)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/detectron2/modeling/roi_heads/mask_head.py", line 182, in forward
    return {"loss_mask": mask_rcnn_loss(x, instances, self.vis_period)}
  File "/usr/local/lib/python3.6/dist-packages/detectron2/modeling/roi_heads/mask_head.py", line 55, in mask_rcnn_loss
    gt_masks_per_image = instances_per_image.gt_masks.crop_and_resize(
  File "/usr/local/lib/python3.6/dist-packages/detectron2/structures/instances.py", line 60, in __getattr__
    raise AttributeError("Cannot find field '{}' in the given Instances!".format(name))
AttributeError: Cannot find field 'gt_masks' in the given Instances!
[06/29 23:04:25 d2.engine.hooks]: Total training time: 0:00:01 (0:00:00 on hooks)

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-33-3435b262f1ae> in <module>()
----> 1 trainer.train()

11 frames

/usr/local/lib/python3.6/dist-packages/detectron2/structures/instances.py in __getattr__(self, name)
     58     def __getattr__(self, name: str) -> Any:
     59         if name == "_fields" or name not in self._fields:
---> 60             raise AttributeError("Cannot find field '{}' in the given Instances!".format(name))
     61         return self._fields[name]
     62 

AttributeError: Cannot find field 'gt_masks' in the given Instances!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.