Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
irexyc committed May 18, 2023
1 parent 2c7d054 commit 5a2b1bf
Show file tree
Hide file tree
Showing 33 changed files with 231 additions and 179 deletions.
2 changes: 1 addition & 1 deletion csrc/mmdeploy/triton/instance_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ TRITONSERVER_Error* ModelInstanceState::Execute(TRITONBACKEND_Request** requests
}
}

// merget inputs for example: [[a,a,a], [b,b,b], [c,c,c]] -> [[aaa], [(b,c), (b,c), (b,c)]]
// merge inputs for example: [[a,a,a], [b,b,b], [c,c,c]] -> [[aaa], [(b,c), (b,c), (b,c)]]
if (!merge_inputs_.empty()) {
int n_example = vec_inputs[0].size();
::mmdeploy::Value inputs;
Expand Down
6 changes: 5 additions & 1 deletion demo/triton/image-classification/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Image classification serving


## Starting a docker container

```
docker run -it --rm --gpus all openmmlab/mmdeploy:triton-22.12
```

## Convert pytorch model to tensorrt model

```
cd /root/workspace/mmdeploy
python3 tools/deploy.py \
Expand All @@ -20,6 +21,7 @@ python3 tools/deploy.py \
```

## Convert tensorrt model to triton format

```
cd /root/workspace/mmdeploy
python3 demo/triton/to_triton_model.py \
Expand All @@ -28,11 +30,13 @@ python3 demo/triton/to_triton_model.py \
```

## Start triton server

```
tritonserver --model-repository=/model-repository
```

## Run client code output container

```
python3 demo/triton/image-classification/grpc_client.py \
model \
Expand Down
27 changes: 14 additions & 13 deletions demo/triton/image-classification/grpc_client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright (c) OpenMMLab. All rights reserved.
import argparse

import cv2
from tritonclient.grpc import InferenceServerClient, InferInput, InferRequestedOutput
from tritonclient.grpc import (InferenceServerClient, InferInput,
InferRequestedOutput)


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('model_name', type=str,
help='model name')
parser.add_argument('image', type=str,
help='image path')
parser.add_argument('model_name', type=str, help='model name')
parser.add_argument('image', type=str, help='image path')
return parser.parse_args()


Expand All @@ -22,14 +22,16 @@ def __init__(self, url, model_name, model_version):
self._client = InferenceServerClient(self._url)
model_config = self._client.get_model_config(self._model_name,
self._model_version)
model_metadata = self._client.get_model_metadata(self._model_name,
self._model_version)
model_metadata = self._client.get_model_metadata(
self._model_name, self._model_version)
print(f'[model config]:\n{model_config}')
print(f'[model metadata]:\n{model_metadata}')
self._inputs = {input.name: input for input in model_metadata.inputs}
self._input_names = list(self._inputs)
self._outputs = {
output.name: output for output in model_metadata.outputs}
output.name: output
for output in model_metadata.outputs
}
self._output_names = list(self._outputs)
self._outputs_req = [
InferRequestedOutput(name) for name in self._outputs
Expand All @@ -43,8 +45,7 @@ def infer(self, image):
results: dict, {name : numpy.array}
"""

inputs = [InferInput(self._input_names[0], image.shape,
"UINT8")]
inputs = [InferInput(self._input_names[0], image.shape, 'UINT8')]
inputs[0].set_data_from_numpy(image)
results = self._client.infer(
model_name=self._model_name,
Expand All @@ -65,11 +66,11 @@ def visualize(results):
print(f'label {labels[i]} score {scores[i]}')


if __name__ == "__main__":
if __name__ == '__main__':
args = parse_args()
model_name = args.model_name
model_version = "1"
url = "localhost:8001"
model_version = '1'
url = 'localhost:8001'
client = GRPCTritonClient(url, model_name, model_version)
img = cv2.imread(args.image)
results = client.infer(img)
Expand Down
2 changes: 1 addition & 1 deletion demo/triton/image-classification/serving/model/1/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This directory holds the model files.
This directory holds the model files.
6 changes: 5 additions & 1 deletion demo/triton/instance-segmentation/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Instance segmentation serving


## Starting a docker container

```
docker run -it --rm --gpus all openmmlab/mmdeploy:triton-22.12
```

## Convert pytorch model to tensorrt model

```
cd /root/workspace/mmdeploy
python3 tools/deploy.py \
Expand All @@ -20,6 +21,7 @@ python3 tools/deploy.py \
```

## Convert tensorrt model to triton format

```
cd /root/workspace/mmdeploy
python3 demo/triton/to_triton_model.py \
Expand All @@ -28,11 +30,13 @@ python3 demo/triton/to_triton_model.py \
```

## Start triton server

```
tritonserver --model-repository=/model-repository
```

## Run client code output container

```
python3 demo/triton/instance-segmentation/grpc_client.py \
model \
Expand Down
29 changes: 15 additions & 14 deletions demo/triton/instance-segmentation/grpc_client.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import cv2
from tritonclient.grpc import InferenceServerClient, InferInput, InferRequestedOutput
import math

import cv2
from tritonclient.grpc import (InferenceServerClient, InferInput,
InferRequestedOutput)


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('model_name', type=str,
help='model name')
parser.add_argument('image', type=str,
help='image path')
parser.add_argument('model_name', type=str, help='model name')
parser.add_argument('image', type=str, help='image path')
return parser.parse_args()


Expand All @@ -23,14 +23,16 @@ def __init__(self, url, model_name, model_version):
self._client = InferenceServerClient(self._url)
model_config = self._client.get_model_config(self._model_name,
self._model_version)
model_metadata = self._client.get_model_metadata(self._model_name,
self._model_version)
model_metadata = self._client.get_model_metadata(
self._model_name, self._model_version)
print(f'[model config]:\n{model_config}')
print(f'[model metadata]:\n{model_metadata}')
self._inputs = {input.name: input for input in model_metadata.inputs}
self._input_names = list(self._inputs)
self._outputs = {
output.name: output for output in model_metadata.outputs}
output.name: output
for output in model_metadata.outputs
}
self._output_names = list(self._outputs)
self._outputs_req = [
InferRequestedOutput(name) for name in self._outputs
Expand All @@ -44,8 +46,7 @@ def infer(self, image):
results: dict, {name : numpy.array}
"""

inputs = [InferInput(self._input_names[0], image.shape,
"UINT8")]
inputs = [InferInput(self._input_names[0], image.shape, 'UINT8')]
inputs[0].set_data_from_numpy(image)
results = self._client.infer(
model_name=self._model_name,
Expand Down Expand Up @@ -83,11 +84,11 @@ def visualize(img, results):
cv2.imwrite('instance-segmentation.jpg', img)


if __name__ == "__main__":
if __name__ == '__main__':
args = parse_args()
model_name = args.model_name
model_version = "1"
url = "localhost:8001"
model_version = '1'
url = 'localhost:8001'
client = GRPCTritonClient(url, model_name, model_version)
img = cv2.imread(args.image)
results = client.infer(img)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This directory holds the model files.
This directory holds the model files.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ output {
name: "mask_offs"
data_type: TYPE_INT32
dims: [ -1, 3 ]
}
}
7 changes: 6 additions & 1 deletion demo/triton/keypoint-detection/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Keypoint detection serving

## Starting a docker container

```
docker run -it --rm --gpus all openmmlab/mmdeploy:triton-22.12
```

## Convert pytorch model to tensorrt model

```
cd /root/workspace/mmdeploy
python3 tools/deploy.py \
Expand All @@ -19,6 +21,7 @@ python3 tools/deploy.py \
```

## Convert tensorrt model to triton format

```
cd /root/workspace/mmdeploy
python3 demo/triton/to_triton_model.py \
Expand All @@ -27,13 +30,15 @@ python3 demo/triton/to_triton_model.py \
```

## Start triton server

```
tritonserver --model-repository=/model-repository
```

## Run client code output container

```
python3 demo/triton/keypoint-detection/grpc_client.py \
model \
/path/to/image
```
```
42 changes: 21 additions & 21 deletions demo/triton/keypoint-detection/grpc_client.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import json

import cv2
from tritonclient.grpc import InferenceServerClient, InferInput, InferRequestedOutput
import numpy as np
import json
from tritonclient.grpc import (InferenceServerClient, InferInput,
InferRequestedOutput)


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('model_name', type=str,
help='model name')
parser.add_argument('image', type=str,
help='image path')
parser.add_argument('model_name', type=str, help='model name')
parser.add_argument('image', type=str, help='image path')
return parser.parse_args()


Expand All @@ -24,14 +24,16 @@ def __init__(self, url, model_name, model_version):
self._client = InferenceServerClient(self._url)
model_config = self._client.get_model_config(self._model_name,
self._model_version)
model_metadata = self._client.get_model_metadata(self._model_name,
self._model_version)
model_metadata = self._client.get_model_metadata(
self._model_name, self._model_version)
print(f'[model config]:\n{model_config}')
print(f'[model metadata]:\n{model_metadata}')
self._inputs = {input.name: input for input in model_metadata.inputs}
self._input_names = list(self._inputs)
self._outputs = {
output.name: output for output in model_metadata.outputs}
output.name: output
for output in model_metadata.outputs
}
self._output_names = list(self._outputs)
self._outputs_req = [
InferRequestedOutput(name) for name in self._outputs
Expand All @@ -46,10 +48,10 @@ def infer(self, image, box):
results: dict, {name : numpy.array}
"""

inputs = [InferInput(self._input_names[0], image.shape,
"UINT8"),
InferInput(self._input_names[1], box.shape,
"BYTES")]
inputs = [
InferInput(self._input_names[0], image.shape, 'UINT8'),
InferInput(self._input_names[1], box.shape, 'BYTES')
]
inputs[0].set_data_from_numpy(image)
inputs[1].set_data_from_numpy(box)
results = self._client.infer(
Expand All @@ -72,20 +74,18 @@ def visualize(img, results):
cv2.imwrite('keypoint-detection.jpg', img)


if __name__ == "__main__":
if __name__ == '__main__':
args = parse_args()
model_name = args.model_name
model_version = "1"
url = "localhost:8001"
model_version = '1'
url = 'localhost:8001'
client = GRPCTritonClient(url, model_name, model_version)
img = cv2.imread(args.image)
bbox = {
'type': 'PoseBbox',
'value': [
{
'bbox': [0.0, 0.0, img.shape[1], img.shape[0]]
}
]
'value': [{
'bbox': [0.0, 0.0, img.shape[1], img.shape[0]]
}]
}
bbox = np.array([json.dumps(bbox).encode('utf-8')])
results = client.infer(img, bbox)
Expand Down
2 changes: 1 addition & 1 deletion demo/triton/keypoint-detection/serving/model/1/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This directory holds the model files.
This directory holds the model files.
2 changes: 1 addition & 1 deletion demo/triton/keypoint-detection/serving/model/config.pbtxt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ parameters {
value: {
string_value: "0 1"
}
}
}
Loading

0 comments on commit 5a2b1bf

Please sign in to comment.