Spaces:
Sleeping
Sleeping
File size: 993 Bytes
dc2106c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
// Copyright (c) ONNX Project Contributors
/*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <filesystem>
#include <fstream>
#include <string>
#include "onnx/checker.h"
#include "onnx/common/path.h"
namespace ONNX_NAMESPACE {
template <typename T>
void LoadProtoFromPath(const std::string proto_path, T& proto) {
std::filesystem::path proto_u8_path = std::filesystem::u8path(proto_path);
std::fstream proto_stream(proto_u8_path, std::ios::in | std::ios::binary);
if (!proto_stream.good()) {
fail_check("Unable to open proto file: ", proto_path, ". Please check if it is a valid proto. ");
}
std::string data{std::istreambuf_iterator<char>{proto_stream}, std::istreambuf_iterator<char>{}};
if (!ParseProtoFromBytes(&proto, data.c_str(), data.size())) {
fail_check(
"Unable to parse proto from file: ", proto_path, ". Please check if it is a valid protobuf file of proto. ");
}
}
} // namespace ONNX_NAMESPACE
|