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

Object are localized but not classified #166

Closed
ltnghia opened this issue Nov 17, 2018 · 19 comments
Closed

Object are localized but not classified #166

ltnghia opened this issue Nov 17, 2018 · 19 comments

Comments

@ltnghia
Copy link

ltnghia commented Nov 17, 2018

❓ Questions and Help

I fine-tuned Faster R-CNN with backbone FPN-50 on Cityscapes dataset. Objects can be localized accurately but are always classified incorrectly, such as: all 'car' => 'bus', 'bus' => 'car' , 'person' => 'truck', 'bicycle' => 'motorcycle', etc. predictions.get_field("labels") is always incorrect. I don't know what's wrong. Please help me!

aachen_000018_000019_leftimg8bit

aachen_000028_000019_leftimg8bit

I fine-tune the network as follow:

  1. Remove layers having 'cls_score' and 'bbox_pred', and save model:
model = build_detection_model(cfg)
device = torch.device(cfg.MODEL.DEVICE)
model.to(device)
optimizer = make_optimizer(cfg, model)
scheduler = make_lr_scheduler(cfg, optimizer)
save_to_disk = get_rank() == 0
checkpointer = DetectronCheckpointer(cfg, model, optimizer, scheduler, cfg.OUTPUT_DIR, save_to_disk)
checkpointer.load(cfg.MODEL.WEIGHT, init=True)
checkpointer.save(path_output)

maskrcnn_benchmark/utils/checkpoint.py is modified as:

class Checkpointer(object):
    def load(self, f=None, init=False):
        if self.has_checkpoint():
            # override argument with existing checkpoint
            f = self.get_checkpoint_file()
        if not f:
            # no checkpoint could be found
            self.logger.info("No checkpoint found. Initializing model from scratch")
            return {}
        self.logger.info("Loading checkpoint from {}".format(f))
        checkpoint = self._load_file(f)
        if init:
            checkpoint['model'] = {k.replace('module.', ''): v for k, v in checkpoint['model'].items()
                                    if 'cls_score' not in k and 'bbox_pred' not in k and 'mask_fcn_logits' not in k}
        self._load_model(checkpoint)
        if "optimizer" in checkpoint and self.optimizer:
            self.logger.info("Loading optimizer from {}".format(f))
            self.optimizer.load_state_dict(checkpoint.pop("optimizer"))
        if "scheduler" in checkpoint and self.scheduler:
            self.logger.info("Loading scheduler from {}".format(f))
            self.scheduler.load_state_dict(checkpoint.pop("scheduler"))
  1. Change config file: NUM_CLASSES: 8, for background and 7 object classes
  2. Load model and train as normal. Here is loss:
    newplot
@chengyangfu
Copy link
Contributor

chengyangfu commented Nov 17, 2018

It looks just a visualization error.
If you are using the demo program in ./demo, you need to change the class names(from COCO to Cityscapes) in ./demo/predictor.py.

@ltnghia
Copy link
Author

ltnghia commented Nov 18, 2018

It isn't visualization error. I checked class names, they're correct.
predictions.get_field("labels") is always incorrect. Thus, both visualization and evaluation cannot work.

@fmassa
Copy link
Contributor

fmassa commented Nov 19, 2018

The order of the indices of the class should be the same for the training set.
So make sure that it's not mixed up.
For example, during training you might have the following order

car
bus
truck

and in testing

truck
car
bus

@lucasjinreal
Copy link

@ltnghia Have u success trained cityscapes? would u like to send a PR to master branch so that maskrcnn model can be trained on that ?

@ltnghia
Copy link
Author

ltnghia commented Nov 20, 2018

@fmassa: still not find out the reason. The class name / class order for both training and testing are the same. But predictions.get_field("labels") is always wrong.
@jinfagang: I still stuck in training. When I successfully train on Cityscape, I'll send a PR.

@lucasjinreal
Copy link

@ltnghia Hoping for that

@fmassa
Copy link
Contributor

fmassa commented Nov 20, 2018

@ltnghia given the results you have, I'd really expect it to be because of misaligned labels for the predictor. I'd check if the labels are actually contiguous in the training set? Maybe there is one index which is skipped?

@ltnghia
Copy link
Author

ltnghia commented Nov 24, 2018

@fmassa: I found out my stupid mistake. I sorted labels by name instead of ID.
Thank you.

@ltnghia ltnghia closed this as completed Nov 24, 2018
@ranjiewwen
Copy link

ranjiewwen commented Dec 7, 2018

@fmassa: I found out this stupid mistake. Thank you.

  • what the mistake? i also trained on cityscapes , i find the label is error and the result box_Ap,and segm_AP is low .

@TuanHAnhVN
Copy link

@fmassa: I found out this stupid mistake. Thank you.

Hello Nghĩa, bạn train maskrcnn cho cityscapes thành công ko à. Có thể share cho mình thông tin được không nhỉ? Skype: kstn_hut_hat. Cảm ơn nha

@14211019
Copy link

@fmassa: still not find out the reason. The class name / class order for both training and testing are the same. But predictions.get_field("labels") is always wrong.
@jinfagang: I still stuck in training. When I successfully train on Cityscape, I'll send a PR.

hi, @ltnghia , did you try to do the instance segmentation task on this maskrcnn bechmark net using cityscapes? and could your results get around 36.5% segAP same as the maskrcnn paper?
if you have finished it ,could you share the configuration using single gpu ? such as the following parameters

SOLVER:
BASE_LR: 0.01
IMS_PER_BATCH: 8
WEIGHT_DECAY: 0.0001
STEPS: (3000,)
MAX_ITER: 4000

these parameters above is the official advice about training cityscapes model based on coco pretrained model with 8 gpus,so can you help me about how could i set these parameters when I only have one gpu? thanks so much.

@viet2411
Copy link

@ltnghia xin chào bạn, bạn cho mình hỏi là bạn sửa lại format của dataset cityscape sang format của COCO như thế nào vậy? Hay là bạn chỉnh sửa trực tiếp model để model có thể nhận cityscape luôn?

@tuanhanhdmprof
Copy link

@ltnghia xin chào bạn, bạn cho mình hỏi là bạn sửa lại format của dataset cityscape sang format của COCO như thế nào vậy? Hay là bạn chỉnh sửa trực tiếp model để model có thể nhận cityscape luôn?

nó có file convert sang coco đó bạn. Bạn tổ chức đúng cấu trúc thư mục là đc nhé

@viet2411
Copy link

viet2411 commented Jul 1, 2019

@tuanhanhdmprof mình đã cố gắng sử dụng file convert này https://github.com/facebookresearch/Detectron/blob/master/tools/convert_cityscapes_to_coco.py nhưng vẫn không thành công. Bạn có thể chỉ rõ cho mình nên sắp xếp thư mục dataset như thế nào được không?

@tuanhanhdmprof
Copy link

tuanhanhdmprof commented Jul 2, 2019

@tuanhanhdmprof mình đã cố gắng sử dụng file convert này https://github.com/facebookresearch/Detectron/blob/master/tools/convert_cityscapes_to_coco.py nhưng vẫn không thành công. Bạn có thể chỉ rõ cho mình nên sắp xếp thư mục dataset như thế nào được không?

Mình nhầm ý trên. Hướng dẫn để convert nhé:

  1. Download file json của cityscapes về.
  2. Download / pip install cityscapesScripts.
  3. tổ chức thư mục:
    -- root
    ---- gtFine_trainvaltest
    ---- Detectron
    ---- output
  4. run lệnh sau:
    python ./Detectron/tools/convert_cityscapes_to_coco.py --dataset cityscapes_instance_only --datadir . --outdir ./output/

cái thứ 3 cấu trúc lại thì sửa lại lệnh run trên là ok

@viet2411
Copy link

viet2411 commented Jul 2, 2019

@tuanhanhdmprof
Mình đã làm theo chỉ dẫn của bạn (mình có gắn kèm ảnh ở đây. Chỗ khoanh đỏ là thư mục đã cấu trúc theo chỉ dẫn của bạn).
Tuy nhiên mình vẫn gặp lại lỗi này. gtFine_val là folder chứa gì vậy? Ảnh validation gốc chăng?
cc

@tuanhanhdmprof
Copy link

@tuanhanhdmprof
Mình đã làm theo chỉ dẫn của bạn (mình có gắn kèm ảnh ở đây. Chỗ khoanh đỏ là thư mục đã cấu trúc theo chỉ dẫn của bạn).
Tuy nhiên mình vẫn gặp lại lỗi này. gtFine_val là folder chứa gì vậy? Ảnh validation gốc chăng?
cc

nó là thư mục chưa mấy file json ấy bạn (chính là thông tin của các object trong ảnh ấy theo format cityscapes ban đầu)

@luisdecker
Copy link

Can someone make a tutorial on how to convert the cityscapes dataset and put it to train a mask-rcnn model?

@sandeep-d-patil
Copy link

Hey @luisdecker you can check out my repo, have tried to make a cityscapes dataset, similar to matterport repo. Hope this helps!

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

No branches or pull requests