(self, model_path, post_p_thre=0.7, gpu_id=None)
初始化pytorch模型
        :param model_path: 模型地址(可以是模型的参数或者参数和计算图一起保存的文件)
        :param gpu_id: 在哪一块gpu上运行
初始化pytorch模型
        :param model_path: 模型地址(可以是模型的参数或者参数和计算图一起保存的文件)
        :param gpu_id: 在哪一块gpu上运行
初始化pytorch模型 : param model_path : 模型地址 ( 可以是模型的参数或者参数和计算图一起保存的文件 ) : param gpu_id : 在哪一块gpu上运行
def __init__(self, model_path, post_p_thre=0.7, gpu_id=None):
        '''
        初始化pytorch模型
        :param model_path: 模型地址(可以是模型的参数或者参数和计算图一起保存的文件)
        :param gpu_id: 在哪一块gpu上运行
        '''
        self.gpu_id = gpu_id

        if self.gpu_id is not None and isinstance(self.gpu_id, int) and torch.cuda.is_available():
            self.device = torch.device("cuda:%s" % self.gpu_id)
        else:
            self.device = torch.device("cpu")
        print('device:', self.device)
        checkpoint = torch.load(model_path, map_location=self.device)

        config = checkpoint['config']
        config['arch']['backbone']['pretrained'] = False
        self.model = build_model(config['arch'])
        self.post_process = get_post_processing(config['post_processing'])
        self.post_process.box_thresh = post_p_thre
        self.img_mode = config['dataset']['train']['dataset']['args']['img_mode']
        self.model.load_state_dict(checkpoint['state_dict'])
        self.model.to(self.device)
        self.model.eval()

        self.transform = []
        for t in config['dataset']['train']['dataset']['args']['transforms']:
            if t['type'] in ['ToTensor', 'Normalize']:
                self.transform.append(t)
        self.transform = get_transforms(self.transform)
def __init__ ( self , model_path , post_p_thre = 0.7 , gpu_id = None ) : self . gpu_id = gpu_id if self . gpu_id is not None and isinstance ( self . gpu_id , int ) and torch . cuda . is_available ( ) : self . device = torch . device ( "cuda:%s" % self . gpu_id ) else : self . device = torch . device ( "cpu" ) print ( 'device:' , self . device ) checkpoint = torch . load ( model_path , map_location = self . device ) config = checkpoint [ 'config' ] config [ 'arch' ] [ 'backbone' ] [ 'pretrained' ] = False self . model = build_model ( config [ 'arch' ] ) self . post_process = get_post_processing ( config [ 'post_processing' ] ) self . post_process . box_thresh = post_p_thre self . img_mode = config [ 'dataset' ] [ 'train' ] [ 'dataset' ] [ 'args' ] [ 'img_mode' ] self . model . load_state_dict ( checkpoint [ 'state_dict' ] ) self . model . to ( self . device ) self . model . eval ( ) self . transform = [ ] for t in config [ 'dataset' ] [ 'train' ] [ 'dataset' ] [ 'args' ] [ 'transforms' ] : if t [ 'type' ] in [ 'ToTensor' , 'Normalize' ] : self . transform . append ( t ) self . transform = get_transforms ( self . transform )