-
Notifications
You must be signed in to change notification settings - Fork 17
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
Multi object segmentation support #22
Comments
Here is what I rewrite, please check whether it is correct;
|
Solve it by the code shown below def get_id_from_mask(self,color_image,mask_list,bbox_list):
"""
Get mesh_id from cnos/data/obj_dta
Args:
color_image (_type_): _description_
mask_list (_type_): should be a list with np.uint8, or np.array with (N*width*height)
bbox_list (_type_): should be a list with [[x1,y1,x2,y2],[x1,y1,x2,y2],...]
Returns:
_type_: _description_
"""
#1: init color_image and detections
color_image=cv.cvtColor(color_image,cv.COLOR_BGR2RGB)
if type(mask_list)==list:
mask_list=np.array(mask_list).astype(np.float32)/255.0
elif type(mask_list)==np.ndarray:
mask_list=mask_list.astype(np.float32)/255.0
bbox_list=np.array(bbox_list).astype(np.float32)
masks_tensor=torch.tensor(mask_list).cuda()#num_bbox*H*W
bbox_tensor=torch.tensor(bbox_list).cuda()#num_bbox*4
detections={'masks':masks_tensor,'boxes':bbox_tensor}
detections=Detections(detections)
decriptors=self.descriptor_model.forward(np.array(color_image),detections)#num_bbox*1024
#2: compare similarity
metric=PairwiseSimilarity()
scores=metric(decriptors,self.all_ref_feats)#(num_bbox*1024, N*42*1024)->(num_bbox*N*42)
#select top-k detections and compute their mean score as the final score
top5_scores,_=torch.topk(scores,k=5,dim=-1)#(num_bbox*N*42)->(num_bbox*N*5)
avg_top5_scores=torch.mean(top5_scores,dim=-1)#(num_bbox*N*5)->(num_bbox*N)
#get final score and index
max_value,best_match_idx=torch.max(avg_top5_scores,dim=1)#(num_bbox*N)->(num_bbox)
confidence_list=max_value.cpu().numpy()
best_match_idx=best_match_idx.cpu().numpy()
#get class name from sellf._object_name_list
class_list=[self._object_name_list[index] for index in best_match_idx]
return class_list,confidence_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the great work! I now want to get multiple objects from the image, any reference code for me?
After detail read the code, may be need to change this line into ref_feats with multi object shape? But I am not very confidence to solve the problem.
The final hope that can get a all_masks np.array, which include all object mask~
The text was updated successfully, but these errors were encountered: