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

AttributeError: 'AblationLayer' object has no attribute 'f' #485

Open
LiuJiaji1999 opened this issue Feb 29, 2024 · 1 comment
Open

AttributeError: 'AblationLayer' object has no attribute 'f' #485

LiuJiaji1999 opened this issue Feb 29, 2024 · 1 comment

Comments

@LiuJiaji1999
Copy link

LiuJiaji1999 commented Feb 29, 2024

when i choose AblationCAM in YOLOv5 notebook,it will promt this issue,
this is my part code about YOLOBoxScoreTarget

def __init__(self, labels, bounding_boxes, iou_threshold=0.5): self.labels = labels self.bounding_boxes = bounding_boxes self.iou_threshold = iou_threshold def __call__(self, model_output): model_output = model([rgb_img]) boxes,_,_,confidences,categories = parse_detections(model_output) boxes = torch.Tensor(boxes) output = torch.Tensor([0]) if torch.cuda.is_available(): output = output.cuda() boxes = boxes.cuda() if len(boxes) == 0: return output for box, label in zip(self.bounding_boxes, self.labels): # print(type(box)) # <class 'tuple'> # print(box) # box[:] = (477, 271, 639, 471) box = torch.Tensor(np.array(box)[None,:]) if torch.cuda.is_available(): box = box.cuda() ious = torchvision.ops.box_iou(box, boxes) index = ious.argmax() if ious[0, index] > self.iou_threshold and categories[index] == label: score = ious[0, index] + confidences[index] output = output + score return output

And this is my test :

targets = [YOLOBoxScoreTarget(labels=names, bounding_boxes=boxes)] cam = AblationCAM(model, target_layers, ablation_layer=AblationLayer(), use_cuda=torch.cuda.is_available() ) grayscale_cam = cam(tensor, targets=targets)[0,:,:] cam_image = show_cam_on_image(img, grayscale_cam, use_rgb=True) Image.fromarray(cam_image)

@LiuJiaji1999
Copy link
Author

@jacobgil

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

1 participant