GithubHelp home page GithubHelp logo

trt_classification's Introduction

TensorRT example for image classification / single-channel segmentation

Prerequisites

  • cuda
  • cudnn
  • TensorRT
  • OpenCV

Usage

An example main function is as follows (suppose husky.jpg and resnet34.engine is placed in data folder).

int main(int argc, char** argv) {
  cv::Mat image = cv::imread("data/husky.jpg");
  cv::cvtColor(image, image, cv::COLOR_BGR2RGB);
  Inferencer* inferencer = new ClsInferencer("data/resnet34.engine");
  // -------------------------------------
  // // To use onnx model
  // Inferencer* inferencer = new ClsInferencer("data/resnet34.onnx", max_batch_size);
  // 
  // // To export TensorRT engine from onnx
  // inferencer->SerialzeModel("data/resnet34_dest.engine");
  // 
  // -------------------------------------
  std::vector<cv::Mat> images;
  for (size_t i = 0; i < 32; ++i) {
    images.push_back(image);
  }
  std::vector<std::vector<float>> probs;

  auto current = clock();
  inferencer->DoInference(images, probs);
  std::cout << "Time elapsed inferencing (in ms): " << (clock() - current) / 1000.0 << std::endl;

  for (auto &prob : probs) {
    float max_prob = 0.;
    int argmax = 0;
    for (size_t i = 0; i < prob.size(); ++i)
      if (max_prob < prob[i]) {
        max_prob = prob[i];
        argmax = i;
      }
    std::cout << "Image is of class " << argmax << std::endl;
  }
  delete inferencer;
  return 0;
}

trt_classification's People

Contributors

frannecki avatar luciddream217 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.