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

json_category_id_to_contiguous_id? #622

Closed
WeiHao97 opened this issue Apr 1, 2019 · 2 comments
Closed

json_category_id_to_contiguous_id? #622

WeiHao97 opened this issue Apr 1, 2019 · 2 comments

Comments

@WeiHao97
Copy link

WeiHao97 commented Apr 1, 2019

❓ Questions and Help

Hi, Can I ask two questions:
I am applying your model to my dataset which has 1(background)+3 (classes). I labeled each class using 1,2,3 and save the class name in my json file.
Now, I'm confused by this part:


    classes = [obj["category_id"] for obj in anno]
    classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
    classes = torch.tensor(classes)

    Instead, I am suing:
    classes = torch.tensor(classes) where classes is a list storing discrete value from 1 to 3.

Is this problematic? Thank you for your generous reply.

Also, I encountered the 'mismatch issue':


2019-04-01 01:26:21,619 maskrcnn_benchmark.utils.model_serialization INFO: rpn.head.conv.weight loaded from rpn.head.conv.weight of shape (256, 256, 3, 3)
Traceback (most recent call last):
File "tools/train_net.py", line 174, in
main()
File "tools/train_net.py", line 167, in main
model = train(cfg, args.local_rank, args.distributed)
File "tools/train_net.py", line 53, in train
extra_checkpoint_data = checkpointer.load(cfg.MODEL.WEIGHT)
File "/srv/home/whao/pytorch/maskrcnn-benchmark/maskrcnn_benchmark/utils/checkpoint.py", line 62, in load
self._load_model(checkpoint)
File "/srv/home/whao/pytorch/maskrcnn-benchmark/maskrcnn_benchmark/utils/checkpoint.py", line 98, in _load_model
load_state_dict(self.model, checkpoint.pop("model"))
File "/srv/home/whao/pytorch/maskrcnn-benchmark/maskrcnn_benchmark/utils/model_serialization.py", line 80, in load_state_dict
model.load_state_dict(model_state_dict)
File "/srv/home/whao/anaconda3/envs/PTMRCNN/lib/python3.6/site-packages/torch/nn/modules/module.py", line 771, in load_state_dict
self.class.name, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for GeneralizedRCNN:
size mismatch for roi_heads.mask.predictor.mask_fcn_logits.weight: copying a param with shape torch.Size([81, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([4, 256, 1, 1]).
size mismatch for roi_heads.mask.predictor.mask_fcn_logits.bias: copying a param with shape torch.Size([81]) from checkpoint, the shape in current model is torch.Size([4]).


And I did change the class number to 4 from 81.
I then tried to modify the checkpoint fille like, #166, But get a problem of "'NoneType' object is not iterable" at


extra_checkpoint_data = checkpointer.load(cfg.MODEL.WEIGHT)
arguments.update(extra_checkpoint_data)


in train_net.

@chengyangfu
Copy link
Contributor

chengyangfu commented Apr 1, 2019

Ideally, you don't need to modify the coco.py. In your case, you just need to modify your dataset json file to make sure the categories look like the following.
If you check the COCO json file, you will find out the id is not continuous. Therefore, this design can make the conversion between the original id and continuous id eaily.

data['categories'] 
[{'supercategory': 'SUPER', 'id': 1, 'name': 'CLASS1'},
 {'supercategory': 'SUPER', 'id': 2, 'name': 'CLASS2'},
 {'supercategory': 'SUPER', 'id': 3, 'name': 'CLASS3'}
]

For your second question, you also need to remove the layers related to mask prediction.
roi_heads.mask.predictor.mask_fcn_logits.weight, roi_heads.mask.predictor.mask_fcn_logits.bias

@chengyangfu
Copy link
Contributor

I'm closing this issue, please let me know if you have any further question.

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

2 participants