def __init__(self, ai_settings, follow_flag=False): self.ai_settings = ai_settings # 初始化角度预测器 valid_places = ( Place(TargetType.kFPGA, PrecisionType.kFP16, DataLayoutType.kNHWC), Place(TargetType.kHost, PrecisionType.kFloat), Place(TargetType.kARM, PrecisionType.kFloat), ) config = CxxConfig() model_dir = ai_settings.angle_model_path config.set_model_file(model_dir + "/model") config.set_param_file(model_dir + "/params") config.set_valid_places(valid_places) self.angle_predictor = CreatePaddlePredictor(config) # 初始化标志预测器 if follow_flag: label_model_path = ai_settings.follow_model_path elif not follow_flag: label_model_path = ai_settings.label_model_path model_dir = label_model_path pm_config = pm.PaddleMobileConfig() pm_config.precision = pm.PaddleMobileConfig.Precision.FP32 pm_config.device = pm.PaddleMobileConfig.Device.kFPGA pm_config.model_dir = model_dir pm_config.thread_num = 4 self.label_predictor = pm.CreatePaddlePredictor(pm_config) # 标志物相关变量 self.label_img = None self.angle_img = None self.ImgInd = 0
def load_label_model(self): model_dir = self.label_model_path pm_config = pm.PaddleMobileConfig() pm_config.precision = pm.PaddleMobileConfig.Precision.FP32 pm_config.device = pm.PaddleMobileConfig.Device.kFPGA pm_config.model_dir = model_dir pm_config.thread_num = 4 label_predictor = pm.CreatePaddlePredictor(pm_config) return label_predictor
def load_model(): # 加载已经训练好的手写数字识别模型(静态图) path = "hand_inference_model" model_dir = path pm_config = pm.PaddleMobileConfig() pm_config.precision = pm.PaddleMobileConfig.Precision.FP32 pm_config.device = pm.PaddleMobileConfig.Device.kFPGA pm_config.model_dir = model_dir pm_config.thread_num = 4 predictor = pm.CreatePaddlePredictor(pm_config) return predictor
def load_model(self, model_flie, param_file, thread_num, model_dir): ''' 加载PaddleMobile模型 参数:模型文件、模型参数文件、线程数、模型目录 返回:模型预测器 ''' pm_config = pm.PaddleMobileConfig() pm_config.precision = pm.PaddleMobileConfig.Precision.FP32 ######ok pm_config.device = pm.PaddleMobileConfig.Device.kFPGA ######ok if model_dir: pm_config.model_dir = model_dir else: pm_config.prog_file = model_flie pm_config.param_file = param_file pm_config.thread_num = thread_num predictor = pm.CreatePaddlePredictor(pm_config) return predictor
def load_model(self, model_dir, param_dir, thread_num): """ 加载PaddleMobile模型 :param model_dir: 模型文件路径 :param param_dir: 模型参数文件路径 :param thread_num: 线程数 :return: 模型预测器 """ pm_config = pm.PaddleMobileConfig() pm_config.precision = pm.PaddleMobileConfig.Precision.FP32 pm_config.device = pm.PaddleMobileConfig.Device.kFPGA pm_config.prog_file = model_dir pm_config.param_file = param_dir pm_config.thread_num = thread_num predictor = pm.CreatePaddlePredictor(pm_config) return predictor
def init(configs): global predictor model_dir = configs['model'] pm_config = pm.PaddleMobileConfig() pm_config.precision = pm.PaddleMobileConfig.Precision.FP32 pm_config.device = pm.PaddleMobileConfig.Device.kFPGA pm_config.prog_file = os.path.join(model_dir, "model") pm_config.param_file = os.path.join(model_dir, "params") pm_config.prog_file = model_dir + "/model" pm_config.param_file = model_dir + '/params' pm_config.thread_num = 4 print('') print('configuration for predictor is :') print('\tPrecision: ' + str(pm_config.precision)) print('\t Device: ' + str(pm_config.device)) print('\t Model: ' + str(pm_config.prog_file)) print('\t Params: ' + str(pm_config.param_file)) print('\tThreadNum: ' + str(pm_config.thread_num)) print('') predictor = pm.CreatePaddlePredictor(pm_config)
def __init__(self, configs, label_map, name): self.name = name self.predictor = None self.labels = [] self.classes = [] self.configs = configs self.model_dir = configs['model'] self.label_map = label_map self.pm_config = pm.PaddleMobileConfig() self.pm_config.precision = pm.PaddleMobileConfig.Precision.FP32 self.pm_config.device = pm.PaddleMobileConfig.Device.kFPGA self.pm_config.prog_file = os.path.join(self.model_dir, 'model') self.pm_config.param_file = os.path.join(self.model_dir, 'params') self.pm_config.thread_num = 4 print('configuration for predictor is :') print('\tPrecision: ' + str(self.pm_config.precision)) print('\t Device: ' + str(self.pm_config.device)) print('\t Model: ' + str(self.pm_config.prog_file)) print('\t Params: ' + str(self.pm_config.param_file)) print('\tThreadNum: ' + str(self.pm_config.thread_num)) self.predictor = pm.CreatePaddlePredictor(self.pm_config) self.tensor = self.init_tensor( (1, 3, configs['input_width'], configs['input_height'])) # init video_thread if self.name == 'video' or self.name == 'camera': self.video_thread = VideoThread(self.video_path, self.configs['input_width'], self.configs['input_height'], 1, 'video_thread') if self.name == 'video': self.video_path = configs[self.name] elif self.name == 'camera': self.video_path = configs[self.name]