Add some comments for python api (#327)

* Add some comments for python api

* Update setup.py

* Update runtime.py
This commit is contained in:
Jason
2022-10-09 10:05:18 +08:00
committed by GitHub
parent a3fa5989d2
commit 5d4372955f
11 changed files with 239 additions and 13 deletions

View File

@@ -13,6 +13,7 @@
# limitations under the License.
from __future__ import absolute_import
from typing import Union, List
import logging
from .... import FastDeployModel, ModelFormat
from .... import c_lib_wrap as C
@@ -25,6 +26,14 @@ class PPYOLOE(FastDeployModel):
config_file,
runtime_option=None,
model_format=ModelFormat.PADDLE):
"""Load a PPYOLOE model exported by PaddleDetection.
:param model_file: (str)Path of model file, e.g ppyoloe/model.pdmodel
:param params_file: (str)Path of parameters file, e.g ppyoloe/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
:param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
"""
super(PPYOLOE, self).__init__(runtime_option)
assert model_format == ModelFormat.PADDLE, "PPYOLOE model only support model format of ModelFormat.Paddle now."
@@ -33,9 +42,15 @@ class PPYOLOE(FastDeployModel):
model_format)
assert self.initialized, "PPYOLOE model initialize failed."
def predict(self, input_image):
assert input_image is not None, "The input image data is None."
return self._model.predict(input_image)
def predict(self, im):
"""Detect an input image
:param im: (numpy.ndarray)The input image data, 3-D array with layout HWC, BGR format
:return: DetectionResult
"""
assert im is not None, "The input image data is None."
return self._model.predict(im)
class PPYOLO(PPYOLOE):
@@ -45,6 +60,14 @@ class PPYOLO(PPYOLOE):
config_file,
runtime_option=None,
model_format=ModelFormat.PADDLE):
"""Load a PPYOLO model exported by PaddleDetection.
:param model_file: (str)Path of model file, e.g ppyolo/model.pdmodel
:param params_file: (str)Path of parameters file, e.g ppyolo/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
"""
super(PPYOLOE, self).__init__(runtime_option)
assert model_format == ModelFormat.PADDLE, "PPYOLO model only support model format of ModelFormat.Paddle now."
@@ -61,6 +84,15 @@ class PPYOLOv2(PPYOLOE):
config_file,
runtime_option=None,
model_format=ModelFormat.PADDLE):
"""Load a PPYOLOv2 model exported by PaddleDetection.
:param model_file: (str)Path of model file, e.g ppyolov2/model.pdmodel
:param params_file: (str)Path of parameters file, e.g ppyolov2/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
:param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
"""
super(PPYOLOE, self).__init__(runtime_option)
assert model_format == ModelFormat.PADDLE, "PPYOLOv2 model only support model format of ModelFormat.Paddle now."
@@ -77,6 +109,15 @@ class PaddleYOLOX(PPYOLOE):
config_file,
runtime_option=None,
model_format=ModelFormat.PADDLE):
"""Load a YOLOX model exported by PaddleDetection.
:param model_file: (str)Path of model file, e.g yolox/model.pdmodel
:param params_file: (str)Path of parameters file, e.g yolox/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
:param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
"""
super(PPYOLOE, self).__init__(runtime_option)
assert model_format == ModelFormat.PADDLE, "PaddleYOLOX model only support model format of ModelFormat.Paddle now."
@@ -93,6 +134,15 @@ class PicoDet(PPYOLOE):
config_file,
runtime_option=None,
model_format=ModelFormat.PADDLE):
"""Load a PicoDet model exported by PaddleDetection.
:param model_file: (str)Path of model file, e.g picodet/model.pdmodel
:param params_file: (str)Path of parameters file, e.g picodet/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
:param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
"""
super(PPYOLOE, self).__init__(runtime_option)
assert model_format == ModelFormat.PADDLE, "PicoDet model only support model format of ModelFormat.Paddle now."
@@ -109,6 +159,15 @@ class FasterRCNN(PPYOLOE):
config_file,
runtime_option=None,
model_format=ModelFormat.PADDLE):
"""Load a FasterRCNN model exported by PaddleDetection.
:param model_file: (str)Path of model file, e.g fasterrcnn/model.pdmodel
:param params_file: (str)Path of parameters file, e.g fasterrcnn/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
:param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
"""
super(PPYOLOE, self).__init__(runtime_option)
assert model_format == ModelFormat.PADDLE, "FasterRCNN model only support model format of ModelFormat.Paddle now."
@@ -125,6 +184,15 @@ class YOLOv3(PPYOLOE):
config_file,
runtime_option=None,
model_format=ModelFormat.PADDLE):
"""Load a YOLOv3 model exported by PaddleDetection.
:param model_file: (str)Path of model file, e.g yolov3/model.pdmodel
:param params_file: (str)Path of parameters file, e.g yolov3/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
:param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
"""
super(PPYOLOE, self).__init__(runtime_option)
assert model_format == ModelFormat.PADDLE, "YOLOv3 model only support model format of ModelFormat.Paddle now."
@@ -141,6 +209,15 @@ class MaskRCNN(FastDeployModel):
config_file,
runtime_option=None,
model_format=ModelFormat.PADDLE):
"""Load a MaskRCNN model exported by PaddleDetection.
:param model_file: (str)Path of model file, e.g maskrcnn/model.pdmodel
:param params_file: (str)Path of parameters file, e.g maskrcnn/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
:param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
"""
super(MaskRCNN, self).__init__(runtime_option)
assert model_format == ModelFormat.PADDLE, "MaskRCNN model only support model format of ModelFormat.Paddle now."