ts.torch_handler package¶
Subpackages¶
- ts.torch_handler.request_envelope package
- ts.torch_handler.unit_tests package
- Subpackages
- Submodules
- ts.torch_handler.unit_tests.test_base_handler module
- ts.torch_handler.unit_tests.test_envelopes module
- ts.torch_handler.unit_tests.test_image_classifier module
- ts.torch_handler.unit_tests.test_image_segmenter module
- ts.torch_handler.unit_tests.test_mnist_kf module
- ts.torch_handler.unit_tests.test_object_detector module
- Module contents
Submodules¶
ts.torch_handler.base_handler module¶
Base default handler to load torchscript or eager mode [state_dict] models Also, provides handle method per torch serve custom model specification
- class ts.torch_handler.base_handler.BaseHandler[source]¶
Bases:
abc.ABC
Base default handler to load torchscript or eager mode [state_dict] models Also, provides handle method per torch serve custom model specification
- handle(data, context)[source]¶
- Entry point for default handler. It takes the data from the input request and returns
the predicted outcome for the input.
- inference(data, *args, **kwargs)[source]¶
The Inference Function is used to make a prediction call on the given input request. The user needs to override the inference function to customize it.
- Parameters
data (Torch Tensor) – A Torch Tensor is passed to make the Inference Request.
shape should match the model input shape. (The) –
- Returns
The Predicted Torch Tensor is returned in this function.
- Return type
Torch Tensor
- initialize(context)[source]¶
- Initialize function loads the model.pt file and initialized the model object.
First try to load torchscript else load eager mode state_dict based model.
- Parameters
context (context) – It is a JSON Object containing information
to the model artifacts parameters. (pertaining) –
- Raises
RuntimeError – Raises the Runtime error when the model.py is missing
- postprocess(data)[source]¶
The post process function makes use of the output from the inference and converts into a Torchserve supported response output.
- Parameters
data (Torch Tensor) – The torch tensor received from the prediction output of the model.
- Returns
The post process function returns a list of the predicted output.
- Return type
List
ts.torch_handler.contractions module¶
contraction map for text classification models.
ts.torch_handler.densenet_handler module¶
Module for image classification default handler
- class ts.torch_handler.densenet_handler.DenseNetHandler[source]¶
Bases:
object
DenseNetHandler handler class. This handler takes an image and returns the name of object in that image.