티스토리 뷰

onnx 모델에는 operations 뿐만아니라 metadata 도 저장할 수 있다. 이를 잘 활용하면 하나의 onnx 파일로 별도의 config 파일 없이도 손쉽게 모델을 배포할 수 있을 것이다.
이를 C++ 에서 읽어올 수 있는 방법은 아래와 같다.
*onnxruntime 1.15.1 기준이다.
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <onnxruntime_cxx_api.h>
#include <opencv2/opencv.hpp>
#include <sstream>
#include <string>
#include <vector>
int main(int argc, char *argv[]) {
std::string model_file = "/app/models/yolov8n.onnx";
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "parse_metadata");
Ort::SessionOptions session_options;
Ort::Session session{nullptr};
Ort::AllocatorWithDefaultOptions allocator;
session = Ort::Session(env, model_file.c_str(), session_options);
auto model_metadata = session.GetModelMetadata();
auto custom_metadata_map_keys = model_metadata.GetCustomMetadataMapKeysAllocated(allocator);
std::cout << "Model Metadata: " << std::endl;
for (auto &key : custom_metadata_map_keys) {
std::string key_str = key.get();
std::string value_str = model_metadata.LookupCustomMetadataMapAllocated(key_str.c_str(), allocator).get();
std::cout << "key: " << key_str << " value: " << value_str << std::endl;
}
return 0;
}
앞으로 다양한 onnxruntime 예제 코드를 올리려고한다.
https://github.com/developer0hye/onnxruntime-cuda-cpp-example/tree/main
GitHub - developer0hye/onnxruntime-cuda-cpp-example
Contribute to developer0hye/onnxruntime-cuda-cpp-example development by creating an account on GitHub.
github.com
'Deep Learning' 카테고리의 다른 글
| [Deep Learning] C++ ONNXRuntime 1.15.1 official release 라이브러리 기준 TensorRT dynamic batch inference 방법 (0) | 2023.07.25 |
|---|---|
| [ONNXRuntime] ONNX 모델 CPU, GPU 결과 차이 기록 (0) | 2023.07.18 |
| [Deep Learning] ONNXRuntime Output이 계속 변한다면... (0) | 2023.07.03 |
| 비디오 입력 모델 개발 과정에서 발생한 실수 (3) | 2023.06.25 |
| 기록용 ignite optimizer multi groups warmup 관련 (0) | 2023.06.11 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 백준 1766
- 단축키
- FairMOT
- 조합
- 인공지능을 위한 선형대수
- 가장 긴 증가하는 부분 수열
- C++ Deploy
- cosine
- 파이참
- MOT
- 문제집
- 이분탐색
- Lowest Common Ancestor
- LCA
- 백준 11053
- 백준
- 위상 정렬 알고리즘
- PyCharm
- 백트래킹
- ㅂ
- 자료구조
- 백준 11437
- 순열
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
글 보관함
