[ONNX] Pytorch 모델을 ONNX 모델로 변환하기
ONNX 모델은 여러 다양한 플랫폼과 하드웨어에서 효율적인 추론을 가능하게 한다. 여기서 하드웨어는 리눅스, 윈도우, 맥 뿐만 아니라 여러 CPU, GPU 등의 하드웨어를 뜻한다. ONNX 모델 변환을 위해 필요한 import 문은 다음과 같다. # 필요한 import문 import io import numpy as np from torch import nn import torch.utils.model_zoo as model_zoo import torch.onnx 예제 모델은 아래에서 소개된 모델을 기반으로 한다. “Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Networ..
2020.08.23
[TensorRT] TRT_LOGGER 이용해서 로그 확인하기
TensorRT에서 Engine 을 실행하거나, serialize, deserialize 등을 수행 할 때 Log 를 확인할 수 있는 Logger 가 있다. class tensorrt.Logger(self: tensorrt.tensorrt.Logger, min_severity: tensorrt.tensorrt.Logger.Severity = Severity.WARNING) Logger 는 Builder / ICudaEngine / Runtime 에서 사용 할 수 있으며, 파라미터는 다음과 같다. min_severity : The initial minimum severity of this Logger 어느 정도의 로그까지 띄울 것인지에 대한 파라미터이다. 아래와 같은 식으로 사용할 수 있으며 if args..
2020.08.03
[TensorRT] Onnx 모델을 위한 Custom Plugin 구현 (작성중)
(2020/08/03) 계속 업데이트 중, 구현해보고 정리해서 올릴 예정, 지금은 관련된 내용 수집중 * 주의 할 점은 한달 전에 릴리즈된 TensorRT 7.1 버전으로 해야할 듯 TRT_SOURCE/parsers/onnx/ 에는 Split.hpp, ResizeNearest.hpp 등과 같은 많은 onnx plugin 이 존재하며, REGISTER_TENSORRT_PLUGIN 을 통해 시스템에 자동으로 등록되어 런타임 중에 직접 Onnx 모델을 구문 분석 할 수 있다고 한다. 먼저 가장 쉬운 방법은 builtin_op_importers.cpp 를 이용해서 필요한 함수에 대해 플러그인을 구현하고, onnx parser 를 다시 빌드 하는 것이다. onnx-tensorrt github 에 가서 builti..
2020.08.03
[Pytorch] 파이토치 시간 측정, How to measure time in PyTorch
Pytorch 에서 CUDA 호출이 비동기식이기 때문에 타이머를 시작 또는 중지 하기 전에 torch.cuda.synchronize() 를 통해 코드를 동기화 시켜주어야 한다. start = torch.cuda.Event(enable_timing=True) end = torch.cuda.Event(enable_timing=True) start.record() z = x + y end.record() # Waits for everything to finish running torch.cuda.synchronize() print(start.elapsed_time(end)) 참고자료 1 : https://discuss.pytorch.org/t/best-way-to-measure-timing/39496 Best..
2020.07.27
no image
[ONNX] onnx-graphsurgeon 이용하여 plugin 사용하기 - Group Normalization
TensorRT 7.1.2 버전 부터 Group Normalization plugin 을 지원하기 시작했다. 아래 Github 에서 ONNX GraphSurgeon 을 사용할 수 있으며, https://github.com/NVIDIA/TensorRT/tree/master/tools/onnx-graphsurgeon NVIDIA/TensorRT TensorRT is a C++ library for high performance inference on NVIDIA GPUs and deep learning accelerators. - NVIDIA/TensorRT github.com python 샘플 코드에 onnx_packnet 을 이용하여 group normalization plugin 을 추가하여 onnx ..
2020.07.21
no image
[ONNX] Netron : ONNX model Visualization
ONNX 모델을 netron Visualization 할 수 있다. https://github.com/lutzroeder/netron lutzroeder/netron Visualizer for neural network, deep learning and machine learning models - lutzroeder/netron github.com Netron supports ONNX (.onnx, .pb, .pbtxt), Keras (.h5, .keras), Core ML (.mlmodel), Caffe (.caffemodel, .prototxt), Caffe2 (predict_net.pb), Darknet (.cfg), MXNet (.model, -symbol.json), Barracuda (.nn..
2020.07.16
[TensorRT] TensorRT GA vs RC => Use the GA version
TensorRT 다운로드 시 특별한 이유가 없는 경우, GA 버전을 다운 받는 것을 추천한다. GA is a production release, it stands for "General Availability". It is the version most people should be using, for most activities. It has gone through a full test cycle. RC is a "Release Candidate". It is a preproduction version, an early release version. In general, the recommendation would be to use a GA version, unless you have a specifi..
2020.05.18
[Onnx] Onnx Tutorials (정리중)
Onnx Tutorials https://github.com/onnx/tutorials onnx/tutorials Tutorials for creating and using ONNX models. Contribute to onnx/tutorials development by creating an account on GitHub. github.com https://github.com/onnx/onnx-tensorrt onnx/onnx-tensorrt ONNX-TensorRT: TensorRT backend for ONNX. Contribute to onnx/onnx-tensorrt development by creating an account on GitHub. github.com https://githu..
2020.05.14
no image
[TensorRT] TensorRT 및 Tensor Core에서 NCHW vs NHWC 형식의 성능 차이
1. TensorRT : NCHW vs NHWC "It’s recommended to use NCHW format to get better performance with TensorRT." NVIDIA 에서는 TensorRT 입력 값으로 NCHW 포맷을 권장한다. 사용자가 TensorRT Engine 에 Input 값을 NHWC 포맷으로 입력해도 되지만, TensorRT 에서 최적화 될 때, 입력값과 호환되도록 여러 형식 변환기를 자동으로 삽입한다. 즉, NVIDIA는 입력값이 어찌되었던 GPU Acceleration 으로 인해 NCHW 를 형식을 채택한다. 또한, NHWC 형식을 선호하는 경우 UFF Parser 가 호환성을 처리할 수 있으며, 일반적으로 Caffe 는 NCHW 형식을 사용하며, 호환하..
2020.04.29
[TensorRT] 지원되는 연산자 목록 (2020.04.29 기준)
TensorRT 에서 지원되는 Operators 는 다음과 같다. (2020.04.29 기준) Caffe BatchNormalization BNLL Clip Concatenation Convolution Crop Deconvolution Dropout ElementWise ELU InnerProduct Input LeakyReLU LRN Permute Pooling Power Reduction ReLU, TanH, and Sigmoid Reshape SoftMax Scale Clip : When using the Clip operation, Caffe users must serialize their layers using ditcaffe.pb.h instead of caffe.pb.h in order t..
2020.04.29
no image
[ONNX] Pytorch 에서 Onnx 로 변환 시 Gather op 때문에 export 안되는 문제
Pytorch 에서 Onnx 모델로 변환시 Gather 와 같은 옵션 때문에 변환이 안되는 문제가 발생한다. 이유는 Onnx 에서 Gather 라는 옵션을 지원하지 않기 때문이다. (2020.04.28 기준) 아래와 같이 interpolate 를 scale factor 로 구현하였을 때 class ResizeModel(nn.Module): def __init__(self): super(ResizeModel, self).__init__() def forward(self, x): return F.interpolate(x, scale_factor=(2, 2), mode='nearest') 생성되는 그래프는 아래와 같다 위와 같이 구현할 경우 "Gather" 라는 op 이 붙어서 그래프가 생성되는데, Onnx ..
2020.04.28
no image
[TensorRT] NVIDIA TensorRT 개념, 설치방법, 사용하기
1. TensorRT 란? 2. TensorRT 설치하기 3. 여러 프레임워크에서 TensorRT 사용하기 1. TensorRT 란? TensorRT는 학습된 딥러닝 모델을 최적화하여 NVIDIA GPU 상에서의 추론 속도를 수배 ~ 수십배 까지 향상시켜 딥러닝 서비스를 개선하는데 도움을 줄 수 있는 모델 최적화 엔진이다. 흔히들 우리가 접하는 Caffe, Pytorch, TensorFlow, PaddlePaddle 등의 딥러닝 프레임워크를 통해 짜여진 딥러닝 모델을 TensorRT를 통해 모델을 최적화하여 TESLA T4 , JETSON TX2, TESLA V100 등의 NVIDIA GPU 플랫폼에 아름답게 싣는 것이다. 또한, TensorRT는 NVIDIA GPU 연산에 적합한 최적화 기법들을 이용하..
2020.04.21