GithubHelp home page GithubHelp logo

krumo / domain-adaptive-faster-rcnn-pytorch Goto Github PK

View Code? Open in Web Editor NEW
302.0 7.0 68.0 4.16 MB

Domain Adaptive Faster R-CNN in PyTorch

License: MIT License

Dockerfile 0.54% Python 76.57% C++ 2.39% Cuda 18.90% C 1.59%
domain-adaptation object-detection

domain-adaptive-faster-rcnn-pytorch's People

Contributors

krumo 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

domain-adaptive-faster-rcnn-pytorch's Issues

ImportError: No module named 'torchvision'

my env is
torch 1.4.0
torchvision 0.5.0
cuda 10.1

Traceback (most recent call last):
  File "D:/Domain-Adaptive-Faster-RCNN-PyTorch/train_net.py", line 18, in <module>
    from maskrcnn_benchmark.engine.inference import inference
  File "D:\Domain-Adaptive-Faster-RCNN-PyTorch\maskrcnn_benchmark\engine\inference.py", line 10, in <module>
    from maskrcnn_benchmark.data.datasets.evaluation import evaluate
  File "D:\Domain-Adaptive-Faster-RCNN-PyTorch\maskrcnn_benchmark\data\datasets\evaluation\__init__.py", line 3, in <module>
    from .coco import coco_evaluation
  File "D:\Domain-Adaptive-Faster-RCNN-PyTorch\maskrcnn_benchmark\data\datasets\evaluation\coco\__init__.py", line 1, in <module>
    from .coco_eval import do_coco_evaluation
  File "D:\Domain-Adaptive-Faster-RCNN-PyTorch\maskrcnn_benchmark\data\datasets\evaluation\coco\coco_eval.py", line 10, in <module>
    from maskrcnn_benchmark.structures.boxlist_ops import boxlist_iou
  File "D:\Domain-Adaptive-Faster-RCNN-PyTorch\maskrcnn_benchmark\structures\boxlist_ops.py", line 6, in <module>
    from maskrcnn_benchmark.layers import nms as _box_nms
  File "D:\Domain-Adaptive-Faster-RCNN-PyTorch\maskrcnn_benchmark\layers\__init__.py", line 8, in <module>
    from .nms import nms
  File "D:\Domain-Adaptive-Faster-RCNN-PyTorch\maskrcnn_benchmark\layers\nms.py", line 4, in <module>
    from ._utils import _C
  File "D:\Domain-Adaptive-Faster-RCNN-PyTorch\maskrcnn_benchmark\layers\_utils.py", line 39, in <module>
    _C = _load_C_extensions()
  File "D:\Domain-Adaptive-Faster-RCNN-PyTorch\maskrcnn_benchmark\layers\_utils.py", line 35, in _load_C_extensions
    extra_include_paths=extra_include_paths,
  File "C:\Users\wzr\Miniconda3\envs\da\lib\site-packages\torch\utils\cpp_extension.py", line 684, in load
    is_python_module)
  File "C:\Users\wzr\Miniconda3\envs\da\lib\site-packages\torch\utils\cpp_extension.py", line 881, in _jit_compile
    return _import_module_from_library(name, build_directory, is_python_module)
  File "C:\Users\wzr\Miniconda3\envs\da\lib\site-packages\torch\utils\cpp_extension.py", line 1089, in _import_module_from_library
    file, path, description = imp.find_module(module_name, [path])
  File "C:\Users\wzr\Miniconda3\envs\da\lib\imp.py", line 297, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'torchvision'

missing folder for converting dataset to coco format

Hi, thanks for sharing the code.
But when I try to convert cityscapes to coco format using convert_cityscapes_to_coco.py script, I found that the csHelpers and cityscapesscripts are missing. Could you please update it, thanks in advance.

the result map 41.0 is with FPN or not

First of all, thanks for your excellent work!

May I ask you whether the result map 41.0 is with FPN or not since it is too much better than paper's.
I see the configuration in log.txt is without the FPN.

Thanks again

how to solve the img's label when resize img?

File "D:\000_zhuang\DA_F_RCNN_torch_c\maskrcnn_benchmark\data\transforms\transforms.py", line 60, in call
target = target.resize(image.size)
AttributeError: 'list' object has no attribute 'resize'

rpn loss

When calculating the loss of the rpn part, how do you deal with the label of the target domain? I found you treat source and target domain data equally?I only notice you process the target domain label when calculate the loss of roi head.
Looking forward to your reply

why is only batch size of 2 supported for consistency_loss?

Hi,

Thanks for sharing your code. I have a question:

I would like to compute and log the losses for the validation set during training. For doing this I followed a more recent version of mask_rcnn lines(128-174). However, the problem is that for evaluating on validation set batch size is 1 and for computing, the consistency loss batch size must be 2. I would like to know why is it the case?
Is it ok to use the batch size of 2 for computing this loss on the validation set?
Or do you have any other suggestions as a workaround regarding this?
Thank you

cityscape dataset

Hi, thanks for your work. Can you share the processed versions of cityscape and foggy cityscape datasets to reproduce the results?

img_head and ins_head

Have you tried res50 for sim10--cityscape experiment? Could you show the results of the experiment? I did the experiment but I only observed that img_head has good performance, but ins_head does not seem to have much effect.

How can I eval the AP for each classes?

Hi~Thanks for your share at first.And I have some problem with your work.How can I eval the AP for each classes for the experiment of cityscapes -> foggy_cityscapes like your paper.

backbone?

The original paper and other papers used VGG backbone instead of ResNet-50-fpn, so is the improvement of mAP reported on README come from a much stronger backbone? Or other tricks?

cannot import name '_C' from 'maskrcnn_benchmark'

ImportError: cannot import name '_C' from 'maskrcnn_benchmark' (/home/crx/zhanzan/Domain-Adaptive-Faster-RCNN-PyTorch_5/maskrcnn_benchmark/init.py)

I can run train_net.py in terminal successfully.
But I can't run this in pycharm.

What is the use of masks in rpn/loss.py?

Hi, I noticed that in rpn/loss.py, prepare_targets you have an output named "masks", but in call, you only do "torch.cat" to it and nothing else. So I am wondering what is the use of it? Thanks!

lambda trade off parameter?

In the paper "Domain Adaptive Faster R-CNN for Object Detection in the Wild" https://arxiv.org/pdf/1803.03243.pdf

The Loss is described as follows:
The final training loss of the proposed network is a summation of each individual part, which can be written as:
L = Ldet + λ(Limg + Lins + Lcst)
where λ is a trade-off parameter to balance the Faster R-CNN loss and our newly added domain adaptation components

In the code the loss is defined as:
losses = sum(loss for loss in loss_dict.values())
Where there is no reference to a trade-off parameter.

Is this handled somewhere else in the code or is the trade-off parameter left out intentionally?

Serious bug: adding target domain annotation boxes into rpn proposals

for iteration, ((source_images, source_targets, idx1), (target_images, target_targets, idx2)) in enumerate(zip(source_data_loader, target_data_loader), start_iter):
data_time = time.time() - end
arguments["iteration"] = iteration
images = (source_images+target_images).to(device)
targets = [target.to(device) for target in list(source_targets+target_targets)]

if self.training and targets is not None:
boxlists = self.add_gt_proposals(boxlists, targets)

def add_gt_proposals(self, proposals, targets):
"""
Arguments:
proposals: list[BoxList]
targets: list[BoxList]
"""
# Get the device we're operating on
device = proposals[0].bbox.device
gt_boxes = [target.copy_with_fields([]) for target in targets]
# later cat of bbox requires all fields to be present for all bbox
# so we need to add a dummy for objectness that's missing
for gt_box in gt_boxes:
gt_box.add_field("objectness", torch.ones(len(gt_box), device=device))
proposals = [
cat_boxlist((proposal, gt_box))
for proposal, gt_box in zip(proposals, gt_boxes)
]
return proposals

What is the difference between proposals and da_proposals in the forward method of box_head.py ?

Hello,

I was wondering what the difference between proposals and da_proposals in the forward method of box_head.py

When debugging the code-base they appear to be identical

image

Is there any difference between the two?

In the box_head.py forward method, proposals are used in the feature extractor passed to the predictor to generate the class_logits and box_regrssion needed to get the loss_classifier and loss_box_reg from the loss_evaluator() ... then da_proposals are used in the same way as above to run the loss_evaluator once again to obtain da_ins_labels.

        if self.training:
            # Faster R-CNN subsamples during training the proposals with a fixed
            # positive / negative ratio
            with torch.no_grad():
                proposals = self.loss_evaluator.subsample(proposals, targets)

        # extract features that will be fed to the final classifier. The
        # feature_extractor generally corresponds to the pooler + heads
        x = self.feature_extractor(features, proposals)
        # final classifier that converts the features into predictions
        class_logits, box_regression = self.predictor(x)

        if not self.training:
            result = self.post_processor((class_logits, box_regression), proposals)
            return x, result, {}, x, None

        loss_classifier, loss_box_reg, _ = self.loss_evaluator(
            [class_logits], [box_regression]
        )

        if self.training:
            with torch.no_grad():
                da_proposals = self.loss_evaluator.subsample_for_da(proposals, targets)

        da_ins_feas = self.feature_extractor(features, da_proposals)
        class_logits, box_regression = self.predictor(da_ins_feas)
        lc2, lbr2, da_ins_labels = self.loss_evaluator(
            [class_logits], [box_regression]
        )

Unless I'm missing something could you not call the loss evaluator once and then return the da_ins_labels like this if they are identical anyway?

        loss_classifier, loss_box_reg, da_ins_labels = self.loss_evaluator(
            [class_logits], [box_regression]
        )

I feel I could be missing something here, it would be great if you could advise. Thanks! 😄

About DA configs

Hello, thanks for your excellent work!
Could you tell me how to train DA from VOC to Clipart or Watercolor. The result I tried by myself is just 0.02. Maybe the config file requires some changes? Or something else?
Thanks a lot~

Detectron2 Implementation of DA-Faster RCNN

Hello,
thank you for your incredible work. Since this is one of the most important paper for unsupervised domain adaptation for object detection I have reimplemented this architecture using Detectron2. This allow many people to easily use this architecture because i created a Google Colab Notebook. Could you please add this repo to your section "Other implementation"?
link to the repo: https://github.com/GiovanniPasq/DA-Faster-RCNN
Thank you

Environment compilation failure problem

Thank you very much for providing such excellent open source code for learning, and compiling according to the official guidance of mask-rcnn, the environment cannot be compiled successfully. Can you provide the environment configuration that can successfully compile and run this project? I have tried to use pytorch1.0, torchvision=0.2.2 and pytorch1.2, torchvision=0.4.0, but the project cannot be run correctly.

Why I have to provide the ann_file of target domain dataset?

Original domain adaptive faster rcnn is unsupervised for target domain, which means that there isn't any label of target domain dataset. But in paths_catalog.py: it provides the ann_file for foggy_cityscapes_...._train_cocostyle, why? Doesn't it mean that the model already see the foggy_cityscapes image in the training process?How can I train the model with unlabeled target domain dataset?
Thanks!

Image level adaptation with FPN

Hello @krumo , thanks for the great work! I am trying to use your project with a ResNet backbone with a feature pyramid network on top, I would like to ask you if you have any clue about how to apply the domain discriminator at the image level in this case, as the backbone returns feature maps of different sizes, and it is not possible to simply concatenate them. I've noticed that it is stated that DomainAdaptationModule works for both FPN and non-FPN and that a boolean USE_FPN parameter is mentioned but not used, maybe you already thought of an expected behavior?

def __init__(self, in_channels):
"""
Arguments:
in_channels (int): number of channels of the input feature
USE_FPN (boolean): whether FPN feature extractor is used
"""
super(DAImgHead, self).__init__()

Thanks!

This implementation is quit diffrent from the original paper

This implementation is based on maskrcnn-benchmark, from which the faster rcnn is not the same in the original paper, for example
1 origin backbone: vgg16, here: resnet
2 origin roi pooler: roi pool, here: roi align
3 origin roi feature: 2 mlp, here ResNet50Conv5
and so on
These difference is default in the maskrcnn-benchmark.
People who refers to this implementation so really pay attention to these difference.

KeyError: 'Non-existent config key: MODEL.DOMAIN_ADAPTATION_ON' caused by cfg.merge_from_file

Hi, when i run the script to test trained model, KeyError occurs.
the used script: python tools/test_net.py --config_file "configs/da_faster_rcnn/e2e_da_faster_rcnn_R_50_C4_cityscapes_to_foggy_cityscapes.yaml" MODEL.WEIGHT trainedmodels/model_final.pth
detailed error:
Traceback (most recent call last):
File "tools/test_net.py", line 98, in
main()
File "tools/test_net.py", line 50, in main
cfg.merge_from_file(args.config_file)
File "/home/casia_robot_lwy/anaconda3/envs/py3_env/lib/python3.7/site-packages/yacs/config.py", line 213, in merge_from_file
self.merge_from_other_cfg(cfg)
File "/home/casia_robot_lwy/anaconda3/envs/py3_env/lib/python3.7/site-packages/yacs/config.py", line 217, in merge_from_other_cfg
_merge_a_into_b(cfg_other, self, self, [])
File "/home/casia_robot_lwy/anaconda3/envs/py3_env/lib/python3.7/site-packages/yacs/config.py", line 460, in _merge_a_into_b
_merge_a_into_b(v, b[k], root, key_list + [k])
File "/home/casia_robot_lwy/anaconda3/envs/py3_env/lib/python3.7/site-packages/yacs/config.py", line 473, in _merge_a_into_b
raise KeyError("Non-existent config key: {}".format(full_key))
KeyError: 'Non-existent config key: MODEL.DOMAIN_ADAPTATION_ON'

It seems that the target (foggy cityscapes) label is also used for training?

in trainer.py line 141-146
images = (source_images+target_images).to(device)
targets = [target.to(device) for target in list(source_targets+target_targets)]

loss_dict = model(images, targets)

losses = sum(loss for loss in loss_dict.values())

Does it seem that the target label is also used for calculating the detector_losses and proposal_losses?

Why I only got 0.12(AP50)?

Hello, I used cityscapes and foggy_cityscapes dataset to train the model according to the example usage,after 70000 iter ,the AP50 index obtained is only 0.12. I would like to ask where there may be a problem.

what does losses mean?

Hello. I checked your new git.
Thanks for your great work.

My question is the meaning of many losses.

  • loss /
  • loss_classifier /
  • loss_box_reg /
  • loss_objectness /
  • loss_rpn_box_reg /
  • loss_da_image /
  • loss_da_instance /
  • loss_da_consistency

where can I found detailed explanation of these loss?

Which package of cityscapes dataset should I use?

Hi, thanks for your excellent work. I have never accessed cityscapes dataset before, and the official download page really confuses me since there're so many individual packages (sub-dataset?) like gtFine, gtCoarse, leftImg8bit etc. I'm wondering which package should I download for this project? Are the data structures of these packages actually the same?

Same question comes with foggy_dataset, many thanks :)

masks in the call function of modelling.rpn.loss.py

In the call of modelling.rpn.loss.py a masks variable is generated

    def __call__(self, anchors, objectness, box_regression, targets):
        """
        Arguments:
            anchors (list[BoxList])
            objectness (list[Tensor])
            box_regression (list[Tensor])
            targets (list[BoxList])

        Returns:
            objectness_loss (Tensor)
            box_loss (Tensor
        """
        anchors = [cat_boxlist(anchors_per_image) for anchors_per_image in anchors]
        labels, regression_targets, masks = self.prepare_targets(anchors, targets)
        
        masks = torch.cat(masks, dim=0)
        
        sampled_pos_inds, sampled_neg_inds = self.fg_bg_sampler(labels)
        sampled_pos_inds = torch.nonzero(torch.cat(sampled_pos_inds, dim=0)).squeeze(1)
        sampled_neg_inds = torch.nonzero(torch.cat(sampled_neg_inds, dim=0)).squeeze(1)

        sampled_inds = torch.cat([sampled_pos_inds, sampled_neg_inds], dim=0)

        objectness, box_regression = \
                concat_box_prediction_layers(objectness, box_regression)

        objectness = objectness.squeeze()

        labels = torch.cat(labels, dim=0)
        regression_targets = torch.cat(regression_targets, dim=0)

        box_loss = smooth_l1_loss(
            box_regression[sampled_pos_inds],
            regression_targets[sampled_pos_inds],
            beta=1.0 / 9,
            size_average=False,
        ) / (sampled_inds.numel())

        objectness_loss = F.binary_cross_entropy_with_logits(
            objectness[sampled_inds], labels[sampled_inds]
        )

        return objectness_loss, box_loss

It is returned from prepare_targets in line 2 and then the cat() function is called to on itself to generate a new masks var in line 3.

However, it is not used in the rest of the call function.

Should these masks have been used somewhere or are they a redundant return from prepare_targets() ?

Thanks

IndexError: list index out of range, when run the test_net.py

when I run the test_net.py via using the following cmd, "IndexError: list index out of range" occurs.
used cmd:
python tools/test_net.py --config_file "configs/da_faster_rcnn/e2e_da_faster_rcnn_R_50_C4_cityscapes_to_foggy_cityscapes.yaml" MODEL.WEIGHT trainedmodels/model_cst.pth
File "/home/casia_robot_lwy/Documents/code_cv/da_object_detetion/Domain-Adaptive-Faster-RCNN-PyTorch-master/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 464, in getitem
selected_polygons.append(self.polygons[i])

occured error:
IndexError: list index out of range

errored image is 462/500 in val set of cityscapes, specifically, it is lindau_000020_000019_leftImg8bit.png

convert image

FileNotFoundError: [Errno 2] No such file or directory: './datasets/caronly_filtered_gtFine_val.json'

why set to float?What will happen if using the default dtype?

da_img_per_level = da_img_per_level.permute(0, 2, 3, 1)
da_img_label_per_level = torch.zeros_like(da_img_per_level, dtype=torch.float32)
da_img_label_per_level[masks, :] = 1

da_ins_loss = F.binary_cross_entropy_with_logits(
torch.squeeze(da_ins), da_ins_labels.type(torch.cuda.FloatTensor)
)

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.