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

How to exchange Mask R-CNN from YOLOv3 #270

Closed
szk-ryoma opened this issue Oct 19, 2023 · 0 comments
Closed

How to exchange Mask R-CNN from YOLOv3 #270

szk-ryoma opened this issue Oct 19, 2023 · 0 comments

Comments

@szk-ryoma
Copy link

szk-ryoma commented Oct 19, 2023

I was able to exchange to the MASK model and run deepsort.py, but the bounding box appears very large and the accuracy is very low.
I know that if it is a still image it detects with very high accuracy.
So the model is well trained.

Please give me some ideas on how to solve this problem.

The following code is the detector.py for MASK R-CNN.

class MASK_RCNN(object):
def init(self, model_path, mask_thresh, bbox_thresh):
self.model = torch.load(model_path)
self.device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
self.model.eval()
self.mask_thresh = mask_thresh
self.bbox_thresh = bbox_thresh

def __call__(self, input_img):
    img = Image.open(ori_img)
    img = img.convert("RGB")
    
    transform = transforms.Compose([transforms.ToTensor()])
    img = transform(img)

    with torch.no_grad():  
        result = self.model([img.to(self.device)])

    pre_boxes = result[0]['boxes'].cpu().detach().numpy()
    pre_labels = result[0]['labels'].cpu().detach().numpy()
    pre_scores = result[0]['scores'].cpu().detach().numpy()
    pre_masks = result[0]['masks'].cpu().detach().numpy()

    selected_indices = pre_scores > self.bbox_thresh
    box = pre_boxes[selected_indices]
    label = pre_labels[selected_indices]
    score = pre_scores[selected_indices]
    mask = pre_masks[selected_indices]

    return box, label, score, mask

bbox_xywh, label, score, mask = mask_detector(ori_img)
print(label)
mmm = label == 1
bbox_xywh = bbox_xywh[mmm]
score = score[mmm]
print(score)
print(bbox_xywh)
##############################################################
[1 1 1]
[0.9999887 0.99995875 0.9999497 ]
[[377.16418 72.82647 531.6579 378.49054 ]
[315.75507 107.948395 346.40503 189.95299 ]
[108.50862 66.49912 219.38882 344.93854 ]]

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