Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo Issue #20

Open
liang315 opened this issue Nov 29, 2024 · 2 comments
Open

Demo Issue #20

liang315 opened this issue Nov 29, 2024 · 2 comments

Comments

@liang315
Copy link

liang315 commented Nov 29, 2024

I encountered this problem when running the following script

python demo.py --config-file .\configs\CoDet_OVCOCO_R50_1x.yaml --input ..\VLDet\heatmap_inputs\000000059598.jpg --output .\demo_outputs\ --vocabulary co
co --opts MODEL.WEIGHTS .\models\CoDet_OVCOCO_R50_1x..pth
Traceback (most recent call last):
  File "demo.py", line 140, in <module>
    demo = VisualizationDemo(cfg, args)
  File "E:\VLDet\CoDet\codet\predictor.py", line 68, in __init__
    reset_cls_infer(self.predictor.model, classifier, num_classes)
  File "E:\VLDet\CoDet\codet\modeling\utils.py", line 63, in reset_cls_infer
    if model.roi_heads.box_predictor[0].cls_score.norm_weight:
TypeError: 'CoDetFastRCNNOutputLayers' object is not subscriptable

Afterwards, I modified the code in the reset_cls_infer function and it can be run

def reset_cls_infer(model, cls_path, num_classes):
    model.roi_heads.num_classes = num_classes
    if type(cls_path) == str:
        print('Resetting zs_weight', cls_path)
        zs_weight = torch.tensor(
            np.load(cls_path),
            dtype=torch.float32).permute(1, 0).contiguous() # D x C
    else:
        zs_weight = cls_path
    zs_weight = torch.cat(
        [zs_weight, zs_weight.new_zeros((zs_weight.shape[0], 1))],
        dim=1) # D x (C + 1)
    if model.roi_heads.box_predictor.cls_score.norm_weight:
    # if model.roi_heads.box_predictor[0].cls_score.norm_weight:
        zs_weight = F.normalize(zs_weight, p=2, dim=0)
    zs_weight = zs_weight.to(model.device)
    # for k in range(len(model.roi_heads.box_predictor)):
    #     del model.roi_heads.box_predictor[k].cls_score.detection_weight
    #     model.roi_heads.box_predictor[k].cls_score.detection_weight = zs_weight
    del model.roi_heads.box_predictor.cls_score.detection_weight
    model.roi_heads.box_predictor.cls_score.detection_weight = zs_weight

I want to know if what I'm doing is correct

@machuofan
Copy link
Collaborator

Yes, it looks good to me.

@sssssshf
Copy link

sssssshf commented Dec 5, 2024

I encountered this problem when running the following script

python demo.py --config-file .\configs\CoDet_OVCOCO_R50_1x.yaml --input ..\VLDet\heatmap_inputs\000000059598.jpg --output .\demo_outputs\ --vocabulary co
co --opts MODEL.WEIGHTS .\models\CoDet_OVCOCO_R50_1x..pth
Traceback (most recent call last):
  File "demo.py", line 140, in <module>
    demo = VisualizationDemo(cfg, args)
  File "E:\VLDet\CoDet\codet\predictor.py", line 68, in __init__
    reset_cls_infer(self.predictor.model, classifier, num_classes)
  File "E:\VLDet\CoDet\codet\modeling\utils.py", line 63, in reset_cls_infer
    if model.roi_heads.box_predictor[0].cls_score.norm_weight:
TypeError: 'CoDetFastRCNNOutputLayers' object is not subscriptable

Afterwards, I modified the code in the reset_cls_infer function and it can be run

def reset_cls_infer(model, cls_path, num_classes):
    model.roi_heads.num_classes = num_classes
    if type(cls_path) == str:
        print('Resetting zs_weight', cls_path)
        zs_weight = torch.tensor(
            np.load(cls_path),
            dtype=torch.float32).permute(1, 0).contiguous() # D x C
    else:
        zs_weight = cls_path
    zs_weight = torch.cat(
        [zs_weight, zs_weight.new_zeros((zs_weight.shape[0], 1))],
        dim=1) # D x (C + 1)
    if model.roi_heads.box_predictor.cls_score.norm_weight:
    # if model.roi_heads.box_predictor[0].cls_score.norm_weight:
        zs_weight = F.normalize(zs_weight, p=2, dim=0)
    zs_weight = zs_weight.to(model.device)
    # for k in range(len(model.roi_heads.box_predictor)):
    #     del model.roi_heads.box_predictor[k].cls_score.detection_weight
    #     model.roi_heads.box_predictor[k].cls_score.detection_weight = zs_weight
    del model.roi_heads.box_predictor.cls_score.detection_weight
    model.roi_heads.box_predictor.cls_score.detection_weight = zs_weight

I want to know if what I'm doing is correct

image

我也是这么改的 应该没什么问题 ,请问你有没有尝试训练起来。

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

No branches or pull requests

3 participants