Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

[feat] Add serve #399

Merged
merged 33 commits into from
Jun 11, 2021
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
convert to code-block
  • Loading branch information
tchaton committed Jun 11, 2021
commit b3d6c79bb42c0b2c969df47790dc30e1c9d9c578
10 changes: 5 additions & 5 deletions docs/source/general/serve.rst
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ we will implement a ``ClassificationInference`` class, which overrides :class:`~

First, we need make the following imports:

.. testcode:: image_classification
.. code-block:: image_classification

import torch
import torchvision
@@ -84,7 +84,7 @@ The name of the inference method isn't constrained, but we will use ``classify``

Our classify function will take a tensor image, apply some normalization on it, and forward it through the model.

.. testcode:: image_classification
.. code-block:: image_classification

def classify(img):
img = img.float() / 255
@@ -110,7 +110,7 @@ which implements a ``serialize`` and ``deserialize`` function.

.. note:: Grid Serve has already several :class:`~flash.core.serve.types.base.BaseType` built-in such as :class:`~flash.core.serve.types.image.Image` or :class:`~flash.core.serve.types.text.Text`.

.. testcode:: image_classification
.. code-block:: image_classification


class ClassificationInference(ModelComponent):
@@ -139,7 +139,7 @@ Using the `PyTorchVision library <https://github.com/pytorch/vision>`_, we creat

.. note:: TorchScript is a way to create serializable and optimizable models from PyTorch code. Any TorchScript program can be saved from a Python process and loaded in a process where there is no Python dependency.

.. testcode:: image_classification
.. code-block:: image_classification

model = torchvision.models.resnet18(pretrained=True).eval()
torch.jit.script(model).save("resnet.pt")
@@ -154,7 +154,7 @@ The ``ClassificationInference`` instance will be passed as argument to a :class:
Once the :class:`~flash.core.serve.Composition` class is instantiated, just call its :func:`~flash.core.serve.Composition.serve` method.


.. testcode:: image_classification
.. code-block:: image_classification

resnet = GridModel("resnet.pt")
comp = ClassificationInference(resnet)