發表文章

目前顯示的是有「AI」標籤的文章

熱影像物件偵測 (Object Detection on Thermal Image) - 3 使用TensorRT C++ Win10 - 寫TensorRT C++

圖片
上篇 文章 我們測試了onnx格式的model,確認這個model是可以使用的。接下來就要在 TensorRT 上寫C++ 程式執行。 一、安裝tensorRT 可以參考我之前寫 安裝tensorRT的文章 ,依照步驟安裝。 二、複製tensorRT sample 程式修改 我使用 samples\sampleOnnxMNIST 做修改,因為都是讀入onnx格式的model。 將 sampleOnnxMNIST 資料夾複製一份出來,一樣放在 samples 資料夾下,修改檔名叫做sampleOnnxThermalObjDetection,由於model input output 格式跟sample的不一樣,所以要稍微修改。 三、專案屬性加入opencv設定 我們需要讀入圖片,以及對圖片的處理。 這裡我借用openvino裡的opencv來用。 1.開啟專案的屬性頁面,在"其他 Include 目錄"裡添加 opencv include 路徑: 2.在"其他程式庫目錄"裡添加 opencv lib 路徑: 3.在"其他相依性"裡添加 opencv 使用到的 lib 檔名: 四、修改程式碼 開啟 sampleOnnxMNIST.cpp 檔案做修改 1. include opencv #include <opencv2/core.hpp> #include <opencv2/highgui.hpp> #include <opencv2/imgcodecs.hpp> #include <opencv2/imgproc.hpp> 2.修改 model input output name: 將 initializeSampleParams() 修改成以下,之後要將model及image放在 samples/sampleOnnxThermalObjDetection/ 路徑之下。 samplesCommon::OnnxSampl...

熱影像物件偵測 (Object Detection on Thermal Image)- 2 使用TensorRT C++ Win10 - 測試onnx model

圖片
上篇 文章 我們得到了onnx格式的model,先做個測試確認這個model是可以使用的,需要在onnx framework下執行這個model,這邊使用到python onnx runtime。 一、下載onnx runtime 可以在 https://www.onnxruntime.ai/ 下載你需要的版本。 我下載的是GPU版,在python環境下輸入: pip install onnxruntime-gpu 二、寫執行程式 1.import import cv2> import numpy as np import onnxruntime as ort import onnxruntime.backend 2.讀入 onnx model modelName = 'weights/export.onnx' sess = ort.InferenceSession(modelName) 3.顯示讀入model的相關資訊 print("device", ort.get_device()) print("in count", len(sess.get_inputs())) print("out count", len(sess.get_outputs())) input_name = sess.get_inputs()[0].name print("input name", input_name) input_shape = sess.get_inputs()[0].shape print("input shape", input_shape) input_type = sess.get_inputs()[0].type print("input type", input_type) output_name0 = sess.get_outputs()[0].name print("output0 name", output_name0) output_shape0 = sess.get_outputs()[0].shape pr...

熱影像物件偵測 (Object Detection on Thermal Image) - 1 使用TensorRT C++ Win10 - 測試model及匯出onnx model

圖片
最近疫情的關係熱影像攝影機的應用瞬間發展很快,所以想說有能不能以熱影像畫面為基礎,作物件辨識。在網路上尋找到 這篇文章 ,使用yolov3-spp模型架構訓練,model細節及介紹請看原文,這裡主要是要說明我怎麼將他的model轉換成tensorRT可以執行的部分。想研究如果用c++執行這個model能不能更快一些。 一、clone github 1.clone  github專案 下來 2.Download pre-trained weights 我下載下來的 pre-trained weights 長這樣,根本不知道要使用哪個才對,如果有人嘗試其他的可以留言跟我說喔。 二、測試程式可以執行 專案根目錄裡有個detect.py,這是我們開始的主程式,我嘗試出以下組合是可以使用的。 類別名稱檔:data/coco.data model_config:cfg/yolov3-spp.cfg model:weights/yolov3-spp.weights 如果在data資料夾裡沒有找到 coco.data、coco.names檔案的話請解壓縮labels.zip 帶入所需的參數執行: --data <類別名稱檔> --cfg <model_config> --weights <model> --source <要辨識的圖片資料夾或影片檔> python detect.py --data data/coco.data --cfg cfg/yolov3-spp.cfg --weights weights/weights/yolov3-spp.weights --source data/samples 這是他deteset裡面的一張圖的便是結果: 三、執行速度 我使用的系統環境是: CPU:i7-10700 GPU:GTX1660 SUPER CUDA:10.2 python:3.6.8 pytorch:1.8.1 onnx:1.8.0 每一張處理時間是:0.02秒左右 四、model匯出成onnx格式 1.切換匯出onnx model模式 在mod...