首页 版块 访问AI主站 注册 发帖
11ssbbjj
523
积分 积分商城
0
获赞
部署推理预测
Ta的回复 :补充 以上问题的:  from __future__ import absolute_import from __future__ import division import numpy as np import paddle.fluid as fluid from paddle.fluid.core import PaddleTensor, AnalysisConfig, create_paddle_predictor from processor import postprocess, base64_to_cv2 from data_feed import reader class FaceDetector(): """ predictor config setting """ config = AnalysisConfig("rat/model", "rat/params") # config.disable_glog_info() config.disable_gpu() # config.enable_use_gpu(memory_pool_init_size_mb=1000, device_id=0) # config.enable_tensorrt_engine( # workspace_size = 1<<30, # max_batch_size=1, min_subgraph_size=5, # precision_mode=AnalysisConfig.Precision.Float32, # use_static=True, use_calib_mode=False) predictor = create_paddle_predictor(config) def face_detection(self, images=None, paths=None, data=None, batch_size=1, output_dir='face_detector_predict_output', visualization=False, confs_threshold=0.9, iou_threshold=0.6): """ API for face detection. Args: images (list(numpy.ndarray)): images data, shape of each is [H, W, C] paths (list[str]): The paths of images. batch_size (int): batch size. use_gpu (bool): Whether to use gpu. output_dir (str): The path to store output images. visualization (bool): Whether to save image or not. confs_threshold (float): threshold for confidence coefficient. iou_threshold (float): threshold for iou. Returns: res (list[dict()]): The result of face detection and save path of images. """ # compatibility with older versions if data and 'image' in data: if paths is None: paths = [] paths += data['image'] # get all data all_data = [] for yield_data in reader(images, paths): all_data.append(yield_data) print(44, all_data) total_num = len(all_data) print(45 , total_num) loop_num = int(np.ceil(total_num / batch_size)) print(46, loop_num) res = [] for iter_id in range(loop_num): batch_data = list() handle_id = iter_id * batch_size for image_id in range(batch_size): try: batch_data.append(all_data[handle_id + image_id]) except: pass # feed batch image batch_image = np.array([data['image'] for data in batch_data]) print(47, batch_image) batch_image = PaddleTensor(batch_image.astype('float32')) print(48, batch_image) data_out = self.predictor.run([batch_image]) print(56, data_out) confidences = data_out[0].as_ndarray() boxes = data_out[1].as_ndarray() # postprocess one by one for i in range(len(batch_data)): out, img = postprocess( confidences=confidences[i], boxes=boxes[i], orig_im=batch_data[i]['orig_im'], orig_im_shape=batch_data[i]['orig_im_shape'], orig_im_path=batch_data[i]['orig_im_path'], output_dir=output_dir, visualization=visualization, confs_threshold=confs_threshold, iou_threshold=iou_threshold) res.append(out) return res, img   result, img = face_detector.face_detection(images=[image])
4
部署推理预测
Ta的回复 :项目“Jeston Tx2 预测部署”共享链接(有效期三天):https://aistudio.baidu.com/studio/project/partial/verify/1719294/4f815971f0e14770b46a84c3b4456bdb
4
切换版块
智能客服