ts.torch_handler 包¶
子包¶
- ts.torch_handler.request_envelope 包
- ts.torch_handler.unit_tests 包
- 子包
- 子模块
- ts.torch_handler.unit_tests.test_base_handler 模块
- ts.torch_handler.unit_tests.test_envelopes 模块
- ts.torch_handler.unit_tests.test_image_classifier 模块
- ts.torch_handler.unit_tests.test_image_segmenter 模块
- ts.torch_handler.unit_tests.test_mnist_kf 模块
- ts.torch_handler.unit_tests.test_object_detector 模块
- 模块内容
子模块¶
ts.torch_handler.base_handler 模块¶
用于加载 torchscript 或 eager 模式 [state_dict] 模型的默认基础处理程序。还为每个 torch serve 自定义模型规范提供 handle 方法
- class ts.torch_handler.base_handler.BaseHandler[source]¶
基类:
ABC
用于加载 torchscript 或 eager 模式 [state_dict] 模型的默认基础处理程序。还为每个 torch serve 自定义模型规范提供 handle 方法
- inference(*args, **kwargs)¶
- initialize(context)[source]¶
- Initialize 函数加载 model.pt 文件并初始化模型对象。
首先尝试加载 torchscript,否则加载基于 eager 模式 state_dict 的模型。
- 参数:
context (context) – 这是一个 JSON 对象,包含信息
parameters. (与模型工件相关) –
- Raises:
RuntimeError – 当 model.py 丢失时引发 RuntimeError
- postprocess(*args, **kwargs)¶
- preprocess(*args, **kwargs)¶
ts.torch_handler.contractions 模块¶
用于文本分类模型的缩略词映射。
ts.torch_handler.densenet_handler 模块¶
用于图像分类默认处理程序的模块
ts.torch_handler.image_classifier 模块¶
用于图像分类默认处理程序的模块
- class ts.torch_handler.image_classifier.ImageClassifier[source]¶
基类:
VisionHandler
ImageClassifier 处理程序类。此处理程序接收图像并返回该图像中对象的名称。
- image_processing = Compose( Resize(size=256, interpolation=bilinear, max_size=None, antialias=True) CenterCrop(size=(224, 224)) ToTensor() Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) )¶
- postprocess(*args, **kwargs)¶
- topk = 5¶
ts.torch_handler.image_segmenter 模块¶
用于图像分割默认处理程序的模块
- class ts.torch_handler.image_segmenter.ImageSegmenter[source]¶
基类:
VisionHandler
ImageSegmenter 处理程序类。此处理程序接收一批图像,并返回形状为 [N K H W] 的输出,其中 N - 批量大小,K - 类数,H - 高度,W - 宽度。
- image_processing = Compose( Resize(size=256, interpolation=bilinear, max_size=None, antialias=True) CenterCrop(size=(224, 224)) ToTensor() Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) )¶
ts.torch_handler.object_detector 模块¶
用于对象检测默认处理程序的模块
- class ts.torch_handler.object_detector.ObjectDetector[source]¶
基类:
VisionHandler
ObjectDetector 处理程序类。此处理程序接收图像,并分别返回检测到的类和边界框的列表
- image_processing = Compose( ToTensor() )¶
- initialize(context)[source]¶
- Initialize 函数加载 model.pt 文件并初始化模型对象。
首先尝试加载 torchscript,否则加载基于 eager 模式 state_dict 的模型。
- 参数:
context (context) – 这是一个 JSON 对象,包含信息
parameters. (与模型工件相关) –
- Raises:
RuntimeError – 当 model.py 丢失时引发 RuntimeError
- threshold = 0.5¶
ts.torch_handler.text_classifier 模块¶
用于文本分类默认处理程序的模块 不支持批量处理!
- class ts.torch_handler.text_classifier.TextClassifier[source]¶
基类:
TextHandler
TextClassifier 处理程序类。此处理程序接收文本(字符串)作为输入,并根据模型词汇表返回分类文本。
- inference(data, *args, **kwargs)[source]¶
推理请求通过此函数发出,用户需要覆盖 inference 函数以自定义它。
- 参数:
data (torch tensor) –
数据采用 Torch 张量的形式,其形状应与
模型输入形状。
- 返回:
- 来自模型的预测响应将返回
在此函数中。
- 返回类型:
(Torch 张量)
- ngrams = 2¶
ts.torch_handler.text_handler 模块¶
所有基于文本的默认处理程序的基础模块。包含各种基于文本的实用方法
ts.torch_handler.vision_handler 模块¶
所有视觉处理程序的基础模块
- class ts.torch_handler.vision_handler.VisionHandler[source]¶
基类:
BaseHandler
,ABC
所有视觉处理程序的基类
- initialize(context)[source]¶
- Initialize 函数加载 model.pt 文件并初始化模型对象。
首先尝试加载 torchscript,否则加载基于 eager 模式 state_dict 的模型。
- 参数:
context (context) – 这是一个 JSON 对象,包含信息
parameters. (与模型工件相关) –
- Raises:
RuntimeError – 当 model.py 丢失时引发 RuntimeError
- preprocess(*args, **kwargs)¶