forked from NVIDIA-AI-IOT/tao-toolkit-triton-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Re-Identification] End-to-End Inference Using Triton
- Loading branch information
1 parent
c480bd7
commit 7fd35e3
Showing
21 changed files
with
1,121 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: "re_identification_tao" | ||
platform: "tensorrt_plan" | ||
max_batch_size: 16 | ||
input [ | ||
{ | ||
name: "input" | ||
data_type: TYPE_FP32 | ||
format: FORMAT_NCHW | ||
dims: [ 3, 256, 128 ] | ||
} | ||
] | ||
output [ | ||
{ | ||
name: "fc_pred" | ||
data_type: TYPE_FP32 | ||
dims: [ 256 ] | ||
} | ||
] | ||
dynamic_batching { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
# Generate a re_identification model. | ||
echo "Converting the re_identification model" | ||
mkdir -p /model_repository/re_identification_tao/1 | ||
tao-converter /tao_models/re_id_model/resnet50_market1501.etlt \ | ||
-k nvidia_tao \ | ||
-d 3,256,128 \ | ||
-p input,1x3x256x128,4x3x256x128,16x3x256x128 \ | ||
-o fc_pred \ | ||
-t fp16 \ | ||
-m 16 \ | ||
-e /model_repository/re_identification_tao/1/model.plan | ||
/opt/tritonserver/bin/tritonserver --model-store /model_repository |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import torch | ||
import re | ||
import sys | ||
import os | ||
import json | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from re_ranking import R1_mAP_reranking | ||
|
||
|
||
def main(): | ||
if sys.argv[2]: | ||
json_metadata_path = sys.argv[1] | ||
output_dir = sys.argv[2] | ||
f = open(json_metadata_path) | ||
pattern = re.compile(r'([-\d]+)_c(\d)') | ||
data = json.load(f) | ||
|
||
pids = [] | ||
camids = [] | ||
img_paths = [] | ||
embeddings = [] | ||
num_query = 0 | ||
|
||
for row in data: | ||
img_path = row["img_path"] | ||
if "query" in img_path: | ||
num_query += 1 | ||
embedding = row["embedding"] | ||
pid, camid = map(int, pattern.search(img_path).groups()) | ||
if pid == -1: continue # junk images are ignored | ||
camid -= 1 # index starts from 0 | ||
embeddings.append(embedding) | ||
pids.append(pid) | ||
camids.append(camid) | ||
img_paths.append(img_path) | ||
metrics = R1_mAP_reranking(num_query, output_dir, feat_norm=True) | ||
metrics.reset() | ||
metrics.update(torch.tensor(embeddings), pids, camids, img_paths) | ||
cmc, _ = metrics.compute() | ||
f.close() | ||
|
||
plt.figure() | ||
cmc_percentages = [value * 100 for value in cmc] | ||
plt.xticks(np.arange(len(cmc_percentages)), np.arange(1, len(cmc_percentages)+1)) | ||
plt.plot(cmc_percentages, marker="*") | ||
plt.title('Cumulative Matching Characteristics (CMC) curve') | ||
plt.grid() | ||
plt.ylabel('Matching Rate[%]') | ||
plt.xlabel('Rank') | ||
output_cmc_curve_plot_path = os.path.join(output_dir, 'cmc_curve.png') | ||
plt.savefig(output_cmc_curve_plot_path) | ||
|
||
print("Output CMC curve plot saved at %s" % output_cmc_curve_plot_path) | ||
|
||
else: | ||
print("Usage: %s json_metadata_path output_dir" % __file__) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.