Git Product home page Git Product logo

Comments (2)

PKUZHOU avatar PKUZHOU commented on August 26, 2024

可以的,tensorRT可以从文件加载模型

from mtcnn_facedetection_tensorrt.

MirrorYuChen avatar MirrorYuChen commented on August 26, 2024

我按照tensorRT-inference里面的代码将您程序中baseEngine.cpp改成如下形式:
`void baseEngine::caffeToGIEModel(const std::string &deployFile, // name for caffe prototxt
const std::string &modelFile, // name for model
const std::vectorstd::string &outputs, // network outputs
unsigned int maxBatchSize, // batch size - NB must be at least as large as the batch we want to run with)
IHostMemory *&gieModelStream) // output buffer for the GIE model
{
stringstream gieStream;
gieStream.seekg(0, gieStream.beg);

char cache_file[512];
sprintf(cache_file, "%s.engine", modelFile.c_str());
std::ifstream cache(cache_file);
if (!cache) {
    // create the builder
    IBuilder *builder = createInferBuilder(gLogger);

    // parse the caffe model to populate the network, then set the outputs
    INetworkDefinition *network = builder->createNetwork();
    ICaffeParser *parser = createCaffeParser();

    const IBlobNameToTensor *blobNameToTensor = parser->parse(deployFile.c_str(),
                                                            modelFile.c_str(),
                                                            *network,
                                                            nvinfer1::DataType::kHALF);
    // specify which tensors are outputs
    for (auto &s : outputs)
        network->markOutput(*blobNameToTensor->find(s.c_str()));

    // Build the engine
    builder->setMaxBatchSize(maxBatchSize);
    builder->setMaxWorkspaceSize(1 << 25);
    builder->setHalf2Mode(true);

    // cuda engie
    ICudaEngine*engine = builder->buildCudaEngine(*network);
    assert(engine);
    nvinfer1::IHostMemory* serMem = engine->serialize();
    gieStream.write((const char*)serMem->data(), serMem->size());

    // we don't need the network any more, and we can destroy the parser
    network->destroy();
    parser->destroy();
    builder->destroy();

    std::ofstream outFile;
	outFile.open(cache_file);
	outFile << gieStream.rdbuf();
	outFile.close();
	gieStream.seekg(0, gieStream.beg);    
} else {
    printf("loading network profile from engine cache... %s\n", cache_file);
    gieStream << cache.rdbuf();
	cache.close();
}
nvinfer1::IRuntime* infer = nvinfer1::createInferRuntime(gLogger);
gieStream.seekg(0, std::ios::end);
const int modelSize = gieStream.tellg();
gieStream.seekg(0, std::ios::beg);
void* modelMem = malloc(modelSize);
gieStream.read((char*)modelMem, modelSize);
nvinfer1::ICudaEngine* engine = infer->deserializeCudaEngine(modelMem, modelSize, NULL);
free(modelMem);
assert(engine);
context = engine->createExecutionContext();    

}

`
代码能够编译通过,运行也能产生中间文件,但是没有输出结果,大佬有时间能指导一下怎么改一下吗?

from mtcnn_facedetection_tensorrt.

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.