Giter VIP home page Giter VIP logo

yolov7-in-cpp's Introduction

소개

실시간 Object Detection 모델인 YOLOv7을 ONNX C++ 사용 튜토리얼을 참고하여 윈도우 어플리케이션에서 사용 가능하게 만들어보고 나중에 참고하려고 만들었습니다.

reference :


Step1 - 환경구성

  • YOLOv7 공식 레포지토리를 clone하고 requirements.txt를 설치합니다.

Step2 - 데이터셋 준비

  • data 폴더에 "train", "val" 폴더를 생성후 이미지와 라벨 파일을 넣어줍니다.

Step3 - Config 파일 수정

  • "coco.yaml" 파일을 열고 아래와 같이 수정합니다.
  1. 'train: data/train'
  2. 'val: data/val'
  3. 'nc:1' (no of classes), 데이터셋에 알맞게 수정합니다.
  4. names:[‘Package’] 데이터셋에 알맞게 수정합니다.
  • yolov7/cfg/training 경로에 있는 "yolov7.yaml" 파일을 열고 nc 를 Step3에서 설정한 nc와 동일하게 수정합니다.

Step4 - pretrained wights 파일 다운로드

  • yolov7.pt 파일을 yolov7 폴더로 이동합니다.

Step5 - Train

from google.colab import drive
drive.mount('/content/drive')
!pip install -r drive/MyDrive/yolov7/requirements.txt
!pip install -r drive/MyDrive/yolov7/requirements_gpu.txt

!python train.py --workers 1 --device 0 --batch-size 16 --epochs 100 --img 640 640 --hyp data/hyp.scratch.  custom.yaml --name yolov7-custom --weights yolov7.pt
  • colab에서 실행하였습니다.
  • 모델 테스트는 생략합니다

Step6 - ONNX로 Export

  • export.py로 생성된 .pt파일을 .onnx로 변환합니다.
python export.py --weights yolov7-tiny.pt --grid --end2end --simplify --include-nms \
        --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640

Step7 - C++ 프로그래밍

  • OpenCVONNX Runtime을 설치합니다.
  • 모델을 GPU로 돌리려는 경우 CUDA Libraries도 필요합니다.
  • LoadDnnModel 클래스(계속 수정) :
//LoadDnnModel.h
using Array = std::vector<float>;
using Shape = std::vector<int64_t>;
class LoadDnnModel
{
public:
	LoadDnnModel();
	~LoadDnnModel();
	void LoadOnnx();
	pair<Array, Shape> process_image(Ort::Session* session, Array& array, Shape shape);
	tuple<Array, Shape, cv::Mat> Read_Image(const string& path, int size);
	void drawPred(float conf, int left, int top, int right, int bottom, cv::Mat& frame, int classid);
	void display_image(cv::Mat image, const Array& output, const Shape& shape);

private:
	bool use_cuda = false;
	int image_size = 640; 
	string model_path = "weights\\best.onnx";
	string image_path = "";
	Ort::Env env;
	Ort::Session* session_;
	Ort::Value input_tensor_{ nullptr };
};
  • classes의 이름도 설정해야 합니다.
//LoadDnnModel.cpp
const char* class_names[] = { "packages" };

Step8 - Inference Output

yolov7-in-cpp's People

Contributors

yongjunbyun avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.