changtimwu / retail-ovmc-demo

0 stars 0 forks source link

input/output spec of a ReID model #2

Open changtimwu opened 3 years ago

changtimwu commented 3 years ago

quote from an official reid model info

Inputs
The net expects one input image of the shape 1, 3, 256, 128 in the B, C, H, W format, where:

B - batch size
C - number of channels
H - image height
W - image width
The expected color order is BGR.

Outputs
The net outputs a blob with the 1, 256 shape named descriptor which can be compared with other descriptors using the cosine distance.
changtimwu commented 3 years ago
    def _get_embeddings(self, frame, detections, mask=None):                                                         
        rois = []                                                                                                    
        embeddings = []                                                                                              

        if self.analyzer:                                                                                            
            self.current_detections = []                                                                             

        for i in range(len(detections)):                                                                             
            rect = detections[i]                                                                                     
            left, top, right, bottom = rect                                                                          
            crop = frame[top:bottom, left:right]                                                                     
            if mask and len(mask[i]) > 0:                                                                            
                crop = cv2.bitwise_and(crop, crop, mask=mask[i])                                                     
            if left != right and top != bottom:                                                                      
                rois.append(crop)                                                                                    

            if self.analyzer:                                                                                        
                self.current_detections.append(cv2.resize(crop, self.analyzer.crop_size))                            

        if rois:                                                                                                     
            embeddings = self.reid_model.forward(rois)                                                               
            assert len(rois) == len(embeddings)                                                                      

        return embeddings    

key point

https://github.com/openvinotoolkit/open_model_zoo/blob/master/demos/multi_camera_multi_target_tracking_demo/python/mc_tracker/sct.py#L267