@@ -649,31 +649,29 @@ bool ModelImporter::parseFromFile(const char* onnxModelFile, int32_t verbosity)
649649{
650650 GOOGLE_PROTOBUF_VERIFY_VERSION;
651651 ::ONNX_NAMESPACE::ModelProto onnx_model;
652+ auto * ctx = &_importer_ctx;
652653
653654 const bool is_binary = ParseFromFile_WAR (&onnx_model, onnxModelFile);
654655 if (!is_binary && !ParseFromTextFile (&onnx_model, onnxModelFile))
655656 {
656- cerr << " Failed to parse ONNX model from file: " << onnxModelFile << endl ;
657+ LOG_ERROR ( " Failed to parse ONNX model from file: " << onnxModelFile) ;
657658 return false ;
658659 }
659660
660661 // Keep track of the absolute path to the ONNX file.
661662 _importer_ctx.setOnnxFileLocation (onnxModelFile);
662663
663- if (verbosity >= static_cast <int32_t >(nvinfer1::ILogger::Severity::kWARNING ))
664- {
665- const int64_t opset_version = (onnx_model.opset_import ().size () ? onnx_model.opset_import (0 ).version () : 0 );
666- cout << " ----------------------------------------------------------------" << endl;
667- cout << " Input filename: " << onnxModelFile << endl;
668- cout << " ONNX IR version: " << onnx_ir_version_string (onnx_model.ir_version ()) << endl;
669- cout << " Opset version: " << opset_version << endl;
670- cout << " Producer name: " << onnx_model.producer_name () << endl;
671- cout << " Producer version: " << onnx_model.producer_version () << endl;
672- cout << " Domain: " << onnx_model.domain () << endl;
673- cout << " Model version: " << onnx_model.model_version () << endl;
674- cout << " Doc string: " << onnx_model.doc_string () << endl;
675- cout << " ----------------------------------------------------------------" << endl;
676- }
664+ const int64_t opset_version = (onnx_model.opset_import ().size () ? onnx_model.opset_import (0 ).version () : 0 );
665+ LOG_INFO (" ----------------------------------------------------------------" );
666+ LOG_INFO (" Input filename: " << onnxModelFile);
667+ LOG_INFO (" ONNX IR version: " << onnx_ir_version_string (onnx_model.ir_version ()));
668+ LOG_INFO (" Opset version: " << opset_version);
669+ LOG_INFO (" Producer name: " << onnx_model.producer_name ());
670+ LOG_INFO (" Producer version: " << onnx_model.producer_version ());
671+ LOG_INFO (" Domain: " << onnx_model.domain ());
672+ LOG_INFO (" Model version: " << onnx_model.model_version ());
673+ LOG_INFO (" Doc string: " << onnx_model.doc_string ());
674+ LOG_INFO (" ----------------------------------------------------------------" );
677675
678676 { // ...Read input file, parse it
679677 std::ifstream onnx_file (onnxModelFile, std::ios::binary | std::ios::ate);
@@ -682,7 +680,7 @@ bool ModelImporter::parseFromFile(const char* onnxModelFile, int32_t verbosity)
682680 std::vector<char > onnx_buf (file_size);
683681 if (!onnx_file.read (onnx_buf.data (), onnx_buf.size ()))
684682 {
685- cerr << " ERROR: Failed to read from file: " << onnxModelFile << endl ;
683+ LOG_ERROR ( " Failed to read from file: " << onnxModelFile) ;
686684 return false ;
687685 }
688686 if (!parse (onnx_buf.data (), onnx_buf.size ()))
@@ -694,29 +692,16 @@ bool ModelImporter::parseFromFile(const char* onnxModelFile, int32_t verbosity)
694692 if (error->node () != -1 )
695693 {
696694 ::ONNX_NAMESPACE::NodeProto const & node = onnx_model.graph ().node (error->node ());
697- cerr << " While parsing node number " << error->node () << " [" << node.op_type ();
698- if (node.output ().size () && verbosity >= static_cast <int32_t >(nvinfer1::ILogger::Severity::kVERBOSE ))
699- {
700- cerr << " -> \" " << node.output (0 ) << " \" " ;
701- }
702- cerr << " ]:" << endl;
703- if (verbosity >= static_cast <int32_t >(nvinfer1::ILogger::Severity::kVERBOSE ))
704- {
705- cout << " --- Begin node ---" << endl;
706- cout << node << endl;
707- cout << " --- End node ---" << endl;
708- }
695+ LOG_ERROR (" While parsing node number " << error->node () << " [" << node.op_type () << " -> \" " << node.output (0 ) << " \" " << " ]:" );
696+ LOG_ERROR (" --- Begin node ---" );
697+ LOG_ERROR (pretty_print_onnx_to_string (node));
698+ LOG_ERROR (" --- End node ---" );
709699 }
710- cerr << " ERROR: " << error->file () << " :" << error->line () << " In function " << error->func () << " :\n "
711- << " [" << static_cast <int >(error->code ()) << " ] " << error->desc () << endl ;
700+ LOG_ERROR ( " ERROR: " << error->file () << " :" << error->line () << " In function " << error->func () << " :\n "
701+ << " [" << static_cast <int >(error->code ()) << " ] " << error->desc ()) ;
712702 }
713703 return false ;
714704 }
715-
716- if (verbosity >= static_cast <int32_t >(nvinfer1::ILogger::Severity::kVERBOSE ))
717- {
718- cout << " ----- Parsing of ONNX model " << onnxModelFile << " is Done ---- " << endl;
719- }
720705 } // ...End Reading input file, parsing it
721706 return true ;
722707}
0 commit comments