mirror of
				https://github.com/PaddlePaddle/FastDeploy.git
				synced 2025-10-31 11:56:44 +08:00 
			
		
		
		
	 34bea7649d
			
		
	
	34bea7649d
	
	
	
		
			
			* Add Sophgo Device add sophgo backend in fastdeploy add resnet50, yolov5s, liteseg examples. * replace sophgo lib with download links; fix model.cc bug * modify CodeStyle * remove unuseful files;change the names of sophgo device and sophgo backend * sophgo support python and add python examples * remove unuseful rows in cmake according pr Co-authored-by: Zilong Xing <zilong.xing@sophgo.com>
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import fastdeploy as fd
 | ||
| import cv2
 | ||
| import os
 | ||
| 
 | ||
| 
 | ||
| def parse_arguments():
 | ||
|     import argparse
 | ||
|     import ast
 | ||
|     parser = argparse.ArgumentParser()
 | ||
|     parser.add_argument("--model", required=True, help="Path of model.")
 | ||
|     parser.add_argument(
 | ||
|         "--config_file", required=True, help="Path of config file.")
 | ||
|     parser.add_argument(
 | ||
|         "--image", type=str, required=True, help="Path of test image file.")
 | ||
|     parser.add_argument(
 | ||
|         "--topk", type=int, default=1, help="Return topk results.")
 | ||
| 
 | ||
|     return parser.parse_args()
 | ||
| 
 | ||
| 
 | ||
| args = parse_arguments()
 | ||
| 
 | ||
| # 配置runtime,加载模型
 | ||
| runtime_option = fd.RuntimeOption()
 | ||
| runtime_option.use_sophgo()
 | ||
| 
 | ||
| model_file = args.model
 | ||
| params_file = ""
 | ||
| config_file = args.config_file
 | ||
| 
 | ||
| model = fd.vision.classification.PaddleClasModel(
 | ||
|     model_file,
 | ||
|     params_file,
 | ||
|     config_file,
 | ||
|     runtime_option=runtime_option,
 | ||
|     model_format=fd.ModelFormat.SOPHGO)
 | ||
| 
 | ||
| # 预测图片分类结果
 | ||
| im = cv2.imread(args.image)
 | ||
| result = model.predict(im, args.topk)
 | ||
| print(result)
 |