Ejemplo n.º 1
0
 def pdx_predict_det(self,img):
     '''
     目标检测接口
     将帧图片传给服务端预测返回筛选之后的boxes
     将poxes的结果可视化
     '''
     or_img = img
     img = image_to_base64(img)
     respone = self.stub.paddlex_predict_det(PaddleXserver_pb2.image(
         _image = img
     ))
     result = []
     for value in respone.boxes:
         dict_temp = {}
         dict_temp['category_id'] = value.category_id
         dict_temp['bbox'] = []
         dict_temp['bbox'].append(value.bbox.xmin)
         dict_temp['bbox'].append(value.bbox.ymin)
         dict_temp['bbox'].append(value.bbox.width)
         dict_temp['bbox'].append(value.bbox.height)
         dict_temp['score'] = value.score
         dict_temp['category'] = value.category
         result.append(dict_temp)
     visualize_img = pdx.det.visualize(or_img,result,threshold=0,save_dir=None)
     return visualize_img
Ejemplo n.º 2
0
 def pdx_predict_det_seg(self,img):
     '''
     实例分割接口
     将帧图发送服务端,返回结果
     可视化结果
     '''
     or_img = img
     img = image_to_base64(img)
     respone = self.stub.paddlex_predict_det_seg(PaddleXserver_pb2.image(
         _image = img
     ))
     result = []
     for value in respone.boxes_seg:
         dict_temp = {}
         dict_temp['category_id'] = value.category_id
         dict_temp['bbox'] = []
         dict_temp['bbox'].append(value.bbox.xmin)
         dict_temp['bbox'].append(value.bbox.ymin)
         dict_temp['bbox'].append(value.bbox.width)
         dict_temp['bbox'].append(value.bbox.height)
         dict_temp['score'] = value.score
         dict_temp['mask'] = base64_to_image(value._mask)
         dict_temp['category'] = value.category
         result.append(dict_temp)
     visualize_img = pdx.det.visualize(or_img,result,threshold=0,save_dir=None)
     return visualize_img
Ejemplo n.º 3
0
    def paddlex_predict_det(self, request, context):
        '''
        目标检测接口
        获得上传的帧图片,将预测完毕的图片筛选后返回
        '''
        img = base64_to_image(request._image)

        #写入图片用
        result = self.server_predict.predict(img)
        det_inputs_result = PaddleXserver_pb2.det_inputs_result()
        for value in result:
            #循环读取result字典
            # 返回符合score的box
            if value['score'] < self.server_predict.score.default_threshold:
                continue
            #把真值赋给数据对象
            temp = det_inputs_result.boxes.add()
            temp.category_id = value['category_id']
            temp.bbox.xmin = value['bbox'][0]
            temp.bbox.ymin = value['bbox'][1]
            temp.bbox.width = value['bbox'][2]
            temp.bbox.height = value['bbox'][3]
            temp.score = value['score']
            temp.category = value['category']
        return det_inputs_result
Ejemplo n.º 4
0
 def paddlex_predict_det_seg(self, request, context):
     '''
     实例分割接口
     接受帧图预测
     结果筛选后返回
     '''
     img = base64_to_image(request._image)
     #写入图片用
     result = self.server_predict.predict(img)
     det_seg_inputs_result = PaddleXserver_pb2.det_seg_inputs_result(
     )  #返回符合score的box
     for value in result:
         if value['score'] < self.server_predict.score.default_threshold:
             continue
         #把真值赋给数据对象
         temp = det_seg_inputs_result.boxes_seg.add()
         temp.category_id = value['category_id']
         temp.bbox.xmin = value['bbox'][0]
         temp.bbox.ymin = value['bbox'][1]
         temp.bbox.width = value['bbox'][2]
         temp.bbox.height = value['bbox'][3]
         temp.score = value['score']
         temp._mask = image_to_base64(value['mask'])
         temp.category = value['category']
     return det_seg_inputs_result
Ejemplo n.º 5
0
 def paddlex_init(self,request,context):
     '''
     用获得的参数初始化加载模型
     返回加载模型的结果
     '''
     self.server_predict = Server_Predict(request.model_dir,request.use_gpu,request.gpu_id)
     respone = self.server_predict.load_model()
     return PaddleXserver_pb2.paddlex_init_result(init_result = respone)
Ejemplo n.º 6
0
 def load_model(self):
     '''
     将参数传给服务端,加载模型返回加载结果
     '''
     # print('use model_dir'+self.model_dir)
     respone =  self.stub.paddlex_init(PaddleXserver_pb2.paddlex_init_cmd(
         model_dir = self.model_dir,
         use_gpu = self.use_gpu,
         gpu_id = self.gpu_id
     ))
     return respone.init_result
Ejemplo n.º 7
0
 def paddlex_predict_cls(self,request,context):
     '''
     图像分类接口
     返回的结果只有一个不是一组
     '''
     img = base64_to_image(request._image)
     result = self.server_predict.predict(img)
     cls_inputs_result = PaddleXserver_pb2.cls_inputs_result()
     #把真值赋给数据对象,只返回第一个值
     cls_inputs_result.category_id = result[0]['category_id']
     cls_inputs_result.score = result[0]['score']
     cls_inputs_result.category = result[0]['category']
     return cls_inputs_result
Ejemplo n.º 8
0
 def paddlex_predict_seg(self,request,context):
     '''
     语义分割接口
     解释帧图返回预测结果
     '''
     img = base64_to_image(request._image)
     result = self.server_predict.predict(img)
     seg_inputs_result = PaddleXserver_pb2.seg_inputs_result()
     #把真值赋给数据对象
     score_maps = (result['score_map']*255).astype(np.uint8)
     score_maps = np.array_split(score_maps,score_maps.shape[2],axis=2)
     for mask in score_maps:
         score_map = seg_inputs_result._score_map.add()
         score_map.value = image_to_base64(mask)
     seg_inputs_result.label_map = image_to_base64(result['label_map'])
     seg_inputs_result.set_threshold = self.server_predict.score.default_threshold
     return seg_inputs_result
Ejemplo n.º 9
0
 def pdx_predict_cls(self,img):
     '''
     图像分类接口
     将帧图发送服务端,返回结果一个
     '''
     
     img = image_to_base64(img)
     respone = self.stub.paddlex_predict_cls(PaddleXserver_pb2.image(
         _image = img
     ))
     result = []
     dict_temp = {}
     dict_temp['category_id'] = respone.category_id
     dict_temp['score'] = respone.score
     dict_temp['category'] = respone.category
     result.append(dict_temp)        
     return result
Ejemplo n.º 10
0
 def pdx_predict_seg(self,img):
     '''
     语义分割接口
     将帧图发送服务端,返回一个分割结果
     '''
     or_img = img
     img = image_to_base64(img)
     respone = self.stub.paddlex_predict_seg(PaddleXserver_pb2.image(
         _image = img
     ))
     dict_temp = {}
     dict_temp['score_map'] = []
     for value in respone._score_map:
         temp = base64_to_image(value.value)
         temp = temp[:,:,np.newaxis]/255
         dict_temp['score_map'].append(temp.astype('float32'))
     dict_temp['score_map'] = np.concatenate(dict_temp['score_map'],axis=2)
     dict_temp['label_map'] = base64_to_image(respone.label_map)
     visualize_img = pdx.seg.visualize(or_img, dict_temp, weight=respone.set_threshold, save_dir=None, color=None)
     return visualize_img