Code Monkey home page Code Monkey logo

Comments (2)

DefTruth avatar DefTruth commented on May 17, 2024

cache反序列化问题已经修复。另外经排查,用户的测试代码中指针的用法会导致无法预测,需要进行修改。

#include "fastdeploy/vision.h"

void TrtInfer(const std::string& model_file, const std::string& image_file) {
	struct fastdeploy::RuntimeOption roi_option;
	fastdeploy::vision::detection::YOLOv7End2EndTRT* model;

	roi_option.UseGpu();
	roi_option.UseTrtBackend();
	roi_option.SetTrtInputShape("images", { 1, 3, 640, 640 });
	roi_option.EnableTrtFP16();
	roi_option.SetTrtCacheFile("yolo_end2end.cache");
    
	// model =
	// 	&fastdeploy::vision::detection::YOLOv7End2EndTRT(model_file, "", roi_option);
        //  这行指针赋值代码用法修改成以下这句
	model = new fastdeploy::vision::detection::YOLOv7End2EndTRT(model_file, "", roi_option);
	if (!model->Initialized()) {
		std::cerr << "Failed to initialize." << std::endl;
		return;
	}
	auto im = cv::imread(image_file);
	fastdeploy::vision::DetectionResult res;
	if (!model->Predict(&im, &res)) {
		std::cerr << "Failed to predict." << std::endl;
		return;
	}
	std::cout << res.Str() << std::endl;
        delete model;
}

int main() {
      TrtInfer("yolov7-end2end-trt-nms.onnx", "000000014439.jpg");
      return 0;
}

首次运行会保存cache文件,log如下

[INFO] fastdeploy/backends/tensorrt/trt_backend.cc(416)::fastdeploy::TrtBackend::BuildTrtEngine Start to building TensorRT Engine...
[INFO] fastdeploy/backends/tensorrt/trt_backend.cc(488)::fastdeploy::TrtBackend::BuildTrtEngine TensorRT Engine is built succussfully.
[INFO] fastdeploy/backends/tensorrt/trt_backend.cc(490)::fastdeploy::TrtBackend::BuildTrtEngine Serialize TensorRTEngine to local file yolo_end2end.cache.
[INFO] fastdeploy/backends/tensorrt/trt_backend.cc(501)::fastdeploy::TrtBackend::BuildTrtEngine TensorRTEngine is serialized to local file yolo_end2end.cache, we can load this model from the seralized engine directly next time.
[INFO] fastdeploy/runtime.cc(289)::fastdeploy::Runtime::Init    Runtime initialized with Backend::TRT in Device::GPU.

第二次及之后运行,直接从cache中加载,加快初始化

[INFO] fastdeploy/backends/tensorrt/trt_backend.cc(541)::fastdeploy::TrtBackend::CreateTrtEngineFromOnnx        Detect serialized TensorRT Engine file in yolo_end2end.cache, will load it directly.
[INFO] fastdeploy/backends/tensorrt/trt_backend.cc(106)::fastdeploy::TrtBackend::LoadTrtCache   Build TensorRT Engine from cache file: yolo_end2end.cache with shape range information as below,
[INFO] fastdeploy/backends/tensorrt/trt_backend.cc(109)::fastdeploy::TrtBackend::LoadTrtCache   Input name: images, shape=[1, 3, 640, 640], min=[1, 3, 640, 640], max=[1, 3, 640, 640]
[INFO] fastdeploy/runtime.cc(289)::fastdeploy::Runtime::Init    Runtime initialized with Backend::TRT in Device::GPU.

from fastdeploy.

WXL-steven avatar WXL-steven commented on May 17, 2024

image
我遇到了相似的错误,问题似乎依旧存在?

此外,检查了trt_backend.cc文件,之前的pull #274 已被合并。
image

from fastdeploy.

Related Issues (20)

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.