Skip to content

Commit 2a3ad43

Browse files
RafalRafal
Rafal
authored and
Rafal
committed
Setup models
Signed-off-by: Rafal <[email protected]>
1 parent 61f318b commit 2a3ad43

File tree

12 files changed

+604
-0
lines changed

12 files changed

+604
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
# this software and associated documentation files (the "Software"), to deal in
7+
# the Software without restriction, including without limitation the rights to
8+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
# the Software, and to permit persons to whom the Software is furnished to do so,
10+
# subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
name: "dali"
23+
backend: "dali"
24+
max_batch_size: 128
25+
input [
26+
{
27+
name: "DALI_INPUT_0"
28+
data_type: TYPE_UINT8
29+
dims: [ -1 ]
30+
allow_ragged_batch: true
31+
}
32+
]
33+
34+
output [
35+
{
36+
name: "DALI_OUTPUT_0"
37+
data_type: TYPE_FP32
38+
dims: [ 224, 224, 3 ]
39+
}
40+
]
41+
42+
parameters: [
43+
{
44+
key: "num_threads"
45+
value: { string_value: "4" }
46+
}
47+
]
48+
49+
dynamic_batching {
50+
preferred_batch_size: [ 64, 128 ]
51+
max_queue_delay_microseconds: 1
52+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
import nvidia.dali as dali
22+
import nvidia.dali.types as types
23+
24+
25+
def parse_args():
26+
import argparse
27+
parser = argparse.ArgumentParser(description="Serialize the pipeline and save it to a file")
28+
parser.add_argument('file_path', type=str, help='The path where to save the serialized pipeline')
29+
return parser.parse_args()
30+
31+
32+
def preprocessing(images):
33+
images = dali.fn.decoders.image(images, device="mixed", output_type=types.RGB)
34+
images = dali.fn.resize(images, resize_x=224, resize_y=224)
35+
return dali.fn.crop_mirror_normalize(images,
36+
dtype=types.FLOAT,
37+
output_layout="HWC",
38+
crop=(224, 224),
39+
mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
40+
std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
41+
42+
@dali.pipeline_def(batch_size=1, num_threads=1, device_id=0)
43+
def pipe():
44+
images = dali.fn.external_source(device="cpu", name="DALI_INPUT_0", no_copy=True)
45+
return preprocessing(images)
46+
47+
48+
def main(filename):
49+
pipe().serialize(filename=filename)
50+
51+
52+
if __name__ == '__main__':
53+
args = parse_args()
54+
main(args.file_path)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
name: "dali_trt_resnet50"
24+
platform: "ensemble"
25+
max_batch_size: 128
26+
input [
27+
{
28+
name: "input"
29+
data_type: TYPE_UINT8
30+
dims: [ -1 ]
31+
}
32+
]
33+
output [
34+
{
35+
name: "classes"
36+
data_type: TYPE_INT32
37+
dims: [ 1 ]
38+
},
39+
{
40+
name: "probabilities"
41+
data_type: TYPE_FP32
42+
dims: [ 1001 ]
43+
}
44+
]
45+
ensemble_scheduling {
46+
step [
47+
{
48+
model_name: "dali"
49+
model_version: -1
50+
input_map {
51+
key: "DALI_INPUT_0"
52+
value: "input"
53+
}
54+
output_map {
55+
key: "DALI_OUTPUT_0"
56+
value: "preprocessed_image"
57+
}
58+
},
59+
{
60+
model_name: "resnet50_trt"
61+
model_version: -1
62+
input_map {
63+
key: "input_tensor:0"
64+
value: "preprocessed_image"
65+
}
66+
output_map {
67+
key: "classes"
68+
value: "classes"
69+
}
70+
output_map {
71+
key: "probabilities"
72+
value: "probabilities"
73+
}
74+
}
75+
]
76+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
# this software and associated documentation files (the "Software"), to deal in
7+
# the Software without restriction, including without limitation the rights to
8+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
# the Software, and to permit persons to whom the Software is furnished to do so,
10+
# subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
platform: "onnxruntime_onnx"
23+
backend: 'onnxruntime'
24+
max_batch_size: 128
25+
26+
instance_group {
27+
count: 2
28+
kind: KIND_GPU
29+
}
30+
dynamic_batching {
31+
preferred_batch_size: 64
32+
preferred_batch_size: 128
33+
max_queue_delay_microseconds: 1
34+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
# this software and associated documentation files (the "Software"), to deal in
7+
# the Software without restriction, including without limitation the rights to
8+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
# the Software, and to permit persons to whom the Software is furnished to do so,
10+
# subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
name: "resnet50_tf"
23+
platform: "tensorflow_savedmodel"
24+
max_batch_size: 128
25+
26+
# input [
27+
# {
28+
# name: "input_tensor:0"
29+
# data_type: TYPE_FP32
30+
# dims: [244, 244, 3]
31+
# }
32+
# ]
33+
34+
35+
instance_group {
36+
count: 2
37+
kind: KIND_GPU
38+
}
39+
dynamic_batching {
40+
preferred_batch_size: 64
41+
preferred_batch_size: 128
42+
max_queue_delay_microseconds: 1
43+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
# this software and associated documentation files (the "Software"), to deal in
7+
# the Software without restriction, including without limitation the rights to
8+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
# the Software, and to permit persons to whom the Software is furnished to do so,
10+
# subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
platform: "tensorrt_plan"
23+
max_batch_size: 128
24+
25+
instance_group {
26+
count: 2
27+
kind: KIND_GPU
28+
}
29+
dynamic_batching {
30+
preferred_batch_size: 64
31+
preferred_batch_size: 128
32+
max_queue_delay_microseconds: 1
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash -e
2+
3+
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
# Download checkpoint
17+
18+
mkdir -p ${CHECKPOINT_DIR}
19+
if [ -f "${CHECKPOINT_DIR}/checkpoint" ]; then
20+
echo "Checkpoint already downloaded."
21+
else
22+
echo "Downloading checkpoint ..."
23+
wget --content-disposition https://api.ngc.nvidia.com/v2/models/nvidia/rn50_tf_amp_ckpt/versions/20.06.0/zip -O \
24+
rn50_tf_amp_ckpt_20.06.0.zip || {
25+
echo "ERROR: Failed to download checkpoint from NGC"
26+
exit 1
27+
}
28+
unzip rn50_tf_amp_ckpt_20.06.0.zip -d ${CHECKPOINT_DIR}
29+
rm rn50_tf_amp_ckpt_20.06.0.zip
30+
echo "ok"
31+
fi
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
# this software and associated documentation files (the "Software"), to deal in
7+
# the Software without restriction, including without limitation the rights to
8+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
# the Software, and to permit persons to whom the Software is furnished to do so,
10+
# subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
import tritonclient.grpc as t_client
23+
import argparse
24+
import sys
25+
26+
def get_args():
27+
parser = argparse.ArgumentParser(description='Load or unload a model in Triton server.')
28+
parser.add_argument('action', action='store', choices=['load', 'unload', 'reload'])
29+
parser.add_argument('-u', '--url', required=False, action='store', default='localhost:8001', help='Server url.')
30+
parser.add_argument('-m', '--model', required=True, action='store', help='Model name.')
31+
return parser.parse_args()
32+
33+
34+
def main(args):
35+
client = t_client.InferenceServerClient(url=args.url)
36+
if args.action in ['reload', 'unload']:
37+
try:
38+
client.unload_model(args.model)
39+
print('Successfully unloaded model', args.model)
40+
except:
41+
print('Could not unload model', args.model)
42+
sys.exit(1)
43+
44+
if args.action in ['reload', 'load']:
45+
try:
46+
client.load_model(args.model)
47+
print('Successfully loaded model', args.model)
48+
except:
49+
print('Could not load model', args.model)
50+
sys.exit(1)
51+
52+
53+
if __name__ == '__main__':
54+
args = get_args()
55+
main(args)

0 commit comments

Comments
 (0)