CoDet
CoDet copied to clipboard
Demo Issue
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
Yes, it looks good to me.
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..pthTraceback (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 subscriptableAfterwards, 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_weightI want to know if what I'm doing is correct
我也是这么改的 应该没什么问题 ,请问你有没有尝试训练起来。