Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging.h:309 onnxruntime::logging::LoggingManager::DefaultLogger Attempt to use DefaultLogger but none has been registered. #20064

Open
Positronx opened this issue Mar 25, 2024 · 2 comments
Labels
stale issues that have not been addressed in a while; categorized by a bot

Comments

@Positronx
Copy link

Positronx commented Mar 25, 2024

Describe the issue

My goal is to load an onnx::ModelProto into an onnxruntime::Model. To use the method onnxruntime::Mode::Load I need a Logger. I tried to create a LoggingManager manually but the method didn't seem to work. Then, I used test/unittest_main/test_main.cc code to create an ort_env that is used to create a DefaultLoggingManager. However, I encountered the exception mentioned in the title.

To reproduce

#include "core/graph/model.h"
#include "core/session/onnxruntime_cxx_api.h"
#include "test/util/include/test_environment.h"
#include "core/session/environment.h"
#include <iostream>
#include <fstream>

std::unique_ptr<std::istream> LoadModelStream(const std::string& model_path) {
    auto input = std::make_unique<std::ifstream>(model_path, std::ios::binary);
    if (!input->is_open()) {
        std::cerr << "Failed to open the file: " << model_path << std::endl;
        return nullptr;
    }

    return input;
}
std::unique_ptr<Ort::Env> ort_env;
using namespace onnxruntime;
int main()
{
    OrtThreadingOptions tpo;
    ort_env.reset(new Ort::Env(&tpo, ORT_LOGGING_LEVEL_WARNING, "Default"));

    const std::string base_model_path = R"(.\BaseModel\base_mlp_model.onnx)";   
    auto base_model_stream = LoadModelStream(base_model_path);

    auto& loggingManager = test::DefaultLoggingManager();
    
    try
    {
        auto logger_ptr = std::make_unique<logging::Logger>(loggingManager.DefaultLogger());
    }
    catch (const std::exception& e)
    {
        std::cout << e.what() << std::endl;
        return EXIT_FAILURE;
    }
    auto logger_ptr = std::make_unique<logging::Logger>(loggingManager.DefaultLogger());

    logger_ptr->SetSeverity(logging::Severity::kINFO);
    ONNX_NAMESPACE::ModelProto model_proto;
    std::shared_ptr<Model> model;
    ORT_THROW_IF_ERROR(Model::Load(*base_model_stream, &model_proto));

    try
    {
        ORT_THROW_IF_ERROR(Model::Load(model_proto, model,
            nullptr,
            *logger_ptr));
    }
    catch (const std::exception& e)
    {
        std::cout << e.what() << std::endl;
        return EXIT_FAILURE;
    }

    ort_env.reset();
}

When I run the code above, I run into the following exception in the first try catch clause :
logging.h:309 onnxruntime::logging::LoggingManager::DefaultLogger Attempt to use DefaultLogger but none has been registered.

Urgency

No response

Platform

Windows

OS Version

10

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

1.17.1

ONNX Runtime API

C++

Architecture

X64

Execution Provider

Default CPU, CUDA

Execution Provider Library Version

No response

@github-actions github-actions bot added ep:CUDA issues related to the CUDA execution provider platform:mobile issues related to ONNX Runtime mobile; typically submitted using template platform:windows issues related to the Windows platform labels Mar 25, 2024
@sophies927 sophies927 removed ep:CUDA issues related to the CUDA execution provider platform:windows issues related to the Windows platform platform:mobile issues related to ONNX Runtime mobile; typically submitted using template labels Mar 28, 2024
@zhufuguo
Copy link

auto env = new Ort::Env(&tpo, ORT_LOGGING_LEVEL_WARNING, "Default");

keep this variable in memory until your program finish will solve the problem.

Copy link
Contributor

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

3 participants