Skip to content

Commit

Permalink
Merge pull request microsoft#28 from NonStatic2014/bohu/check_result
Browse files Browse the repository at this point in the history
Some Bug fixes and clean up
  • Loading branch information
NonStatic2014 authored Apr 6, 2019
2 parents 8f1988f + 579cc3c commit d6811ec
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 68 deletions.
2 changes: 0 additions & 2 deletions cmake/onnxruntime_hosting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ project(onnxruntime_hosting)
# Generate .h and .cc files from protobuf file
add_library(hosting_proto
${ONNXRUNTIME_ROOT}/hosting/protobuf/predict.proto
${ONNXRUNTIME_ROOT}/hosting/protobuf/model_metadata.proto
${ONNXRUNTIME_ROOT}/hosting/protobuf/model_status.proto
${ONNXRUNTIME_ROOT}/hosting/protobuf/error_code.proto)
target_include_directories(hosting_proto PUBLIC $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES> "${CMAKE_CURRENT_BINARY_DIR}/.." ${CMAKE_CURRENT_BINARY_DIR}/onnx)
target_compile_definitions(hosting_proto PUBLIC $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_COMPILE_DEFINITIONS>)
Expand Down
18 changes: 15 additions & 3 deletions onnxruntime/hosting/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@ int main(int argc, char* argv[]) {
auto logger = env->GetAppLogger();
LOGS(logger, VERBOSE) << "Logging manager initialized.";
LOGS(logger, VERBOSE) << "Model path: " << config.model_path;

auto status = env->GetSession()->Load(config.model_path);
LOGS(logger, VERBOSE) << "Load Model Status: " << status.Code() << " ---- Error: [" << status.ErrorMessage() << "]";
LOGS(logger, VERBOSE) << "Session Initialized: " << env->GetSession()->Initialize();
if (!status.IsOK()) {
LOGS(logger, FATAL) << "Load Model Failed: " << status.Code() << " ---- Error: [" << status.ErrorMessage() << "]";
exit(EXIT_FAILURE);
} else {
LOGS(logger, VERBOSE) << "Load Model Successfully!";
}

auto const boost_address = boost::asio::ip::make_address(config.address);
status = env->GetSession()->Initialize();
if (!status.IsOK()) {
LOGS(logger, FATAL) << "Session Initialization Failed:" << status.Code() << " ---- Error: [" << status.ErrorMessage() << "]";
exit(EXIT_FAILURE);
} else {
LOGS(logger, VERBOSE) << "Initialize Session Successfully!";
}

auto const boost_address = boost::asio::ip::make_address(config.address);
hosting::App app{};

app.RegisterStartup(
Expand Down
17 changes: 0 additions & 17 deletions onnxruntime/hosting/protobuf/model_metadata.proto

This file was deleted.

29 changes: 0 additions & 29 deletions onnxruntime/hosting/protobuf/model_status.proto

This file was deleted.

39 changes: 22 additions & 17 deletions onnxruntime/hosting/server_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@

#include <thread>
#include <fstream>
#include <unordered_map>

#include "boost/program_options.hpp"

#include "core/common/logging/logging.h"

namespace onnxruntime {
namespace hosting {

enum class Result { ExitSuccess = 1,
ExitFailure,
ContinueSuccess };

namespace po = boost::program_options;

enum class Result {
ExitSuccess = 1,
ExitFailure,
ContinueSuccess
};

static std::unordered_map<std::string, onnxruntime::logging::Severity> supported_log_levels{
{"verbose", onnxruntime::logging::Severity::kVERBOSE},
{"info", onnxruntime::logging::Severity::kINFO},
{"warning", onnxruntime::logging::Severity::kWARNING},
{"error", onnxruntime::logging::Severity::kERROR},
{"fatal", onnxruntime::logging::Severity::kFATAL}};

// Wrapper around Boost program_options and should provide all the functionality for options parsing
// Provides sane default values
class ServerConfiguration {
Expand Down Expand Up @@ -61,8 +70,13 @@ class ServerConfiguration {
return Result::ExitFailure;
}

logging_level = GetSeverity(logging_level_str);
return ValidateOptions();
Result result = ValidateOptions();

if (result == Result::ContinueSuccess) {
logging_level = supported_log_levels[logging_level_str];
}

return result;
}

private:
Expand All @@ -73,7 +87,7 @@ class ServerConfiguration {
// Print help and return if there is a bad value
Result ValidateOptions() {
if (vm.count("logging_level") &&
(!(logging_level_str == "verbose" || logging_level_str == "info") || logging_level_str == "warning" || logging_level_str == "error" || logging_level_str == "fatal")) {
supported_log_levels.find(logging_level_str) == supported_log_levels.end()) {
PrintHelp(std::cerr, "logging_level must be one of verbose, info, warning, error, or fatal");
return Result::ExitFailure;
} else if (num_http_threads <= 0) {
Expand All @@ -95,15 +109,6 @@ class ServerConfiguration {
return vm.count("help") || vm.count("h");
}

onnxruntime::logging::Severity GetSeverity(const std::string& level) const {
if (level == "verbose") return onnxruntime::logging::Severity::kVERBOSE;
if (level == "info") return onnxruntime::logging::Severity::kINFO;
if (level == "warning") return onnxruntime::logging::Severity::kWARNING;
if (level == "error") return onnxruntime::logging::Severity::kERROR;
if (level == "fatal") return onnxruntime::logging::Severity::kFATAL;
return onnxruntime::logging::Severity::kVERBOSE;
}

// Prints a helpful message (param: what) to the user and then the program options
// Example: config.PrintHelp(std::cout, "Non-negative values not allowed")
// Which will print that message and then all publicly available options
Expand Down

0 comments on commit d6811ec

Please sign in to comment.