diff --git a/winml/test/common/protobufHelpers.cpp b/winml/test/common/protobufHelpers.cpp index 9fb5fd19c6..3838cfa78e 100644 --- a/winml/test/common/protobufHelpers.cpp +++ b/winml/test/common/protobufHelpers.cpp @@ -11,11 +11,6 @@ #include "core/common/logging/sinks/clog_sink.h" #include "protobufHelpers.h" -#pragma warning(push) -#pragma warning(disable : 4100) -#include "onnx/onnx-ml.pb.h" -#pragma warning(pop) - #include using namespace wss; @@ -44,8 +39,8 @@ void FdClose(int fd) { } } -// Copy and pasted from LOTUS as is. temporary code to load tensors from protobufs -bool LoadTensorFromPb(onnx::TensorProto& tensor, std::wstring filePath) { +// Load Onnx TensorProto from Protobuf File +bool ProtobufHelpers::LoadOnnxTensorFromProtobufFile(onnx::TensorProto& tensor, std::wstring filePath) { // setup a string converter using convert_type = std::codecvt_utf8; std::wstring_convert converter; @@ -124,7 +119,7 @@ ITensor ProtobufHelpers::LoadTensorFromProtobufFile( bool isFp16) { // load from the file path into the onnx format onnx::TensorProto tensorProto; - if (LoadTensorFromPb(tensorProto, filePath)) { + if (LoadOnnxTensorFromProtobufFile(tensorProto, filePath)) { std::vector tensorShape = std::vector(tensorProto.dims().begin(), tensorProto.dims().end()); int64_t initialValue = 1; int64_t elementCount = std::accumulate(tensorShape.begin(), tensorShape.end(), initialValue, std::multiplies()); @@ -156,7 +151,7 @@ TensorFloat16Bit ProtobufHelpers::LoadTensorFloat16FromProtobufFile( const std::wstring& filePath) { // load from the file path into the onnx format onnx::TensorProto tensorProto; - if (LoadTensorFromPb(tensorProto, filePath)) { + if (LoadOnnxTensorFromProtobufFile(tensorProto, filePath)) { if (tensorProto.has_data_type()) { if(onnx::TensorProto::DataType::TensorProto_DataType_FLOAT16 != tensorProto.data_type()) { throw winrt::hresult_invalid_argument(L"TensorProto datatype isn't of type Float16."); diff --git a/winml/test/common/protobufHelpers.h b/winml/test/common/protobufHelpers.h index 2f51b8f547..fbc9aa6c2d 100644 --- a/winml/test/common/protobufHelpers.h +++ b/winml/test/common/protobufHelpers.h @@ -5,7 +5,10 @@ #include "std.h" #include "winrt_headers.h" - +#pragma warning(push) +#pragma warning(disable : 4100) +#include "onnx/onnx-ml.pb.h" +#pragma warning(pop) namespace ProtobufHelpers { // LoadTensorFromProtobufFile take a path to a FP32 data file and loads it into a 32bit array or @@ -18,4 +21,7 @@ namespace ProtobufHelpers winml::TensorKind kind, const std::vector& shape, uint32_t num_elements = 1); + + // Populates TensorProto with tensor from protobuf file + bool LoadOnnxTensorFromProtobufFile(onnx::TensorProto& tensor, std::wstring filePath); }