ONE - On-device Neural Engine
Loading...
Searching...
No Matches
EncodeCommand.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "EncodeCommand.hpp"
18#include "Support.hpp"
19
20#include <onnx/onnx.pb.h>
21
22#include <google/protobuf/io/coded_stream.h>
23#include <google/protobuf/io/zero_copy_stream_impl.h>
24#include <google/protobuf/text_format.h>
25
26int EncodeCommand::run(int argc, const char *const *argv) const
27{
28 onnx::ModelProto model;
29
30 Cmdline cmdline(argc, argv);
31
32 auto ui = make_ui(cmdline);
33
34 google::protobuf::io::IstreamInputStream is{ui->in()};
35
36 if (!google::protobuf::TextFormat::Parse(&is, &model))
37 {
38 std::cerr << "ERROR: Failed to parse text" << std::endl;
39 return 255;
40 }
41
42 google::protobuf::io::OstreamOutputStream os{ui->out()};
43 google::protobuf::io::CodedOutputStream coded_os{&os};
44
45 if (!model.SerializeToCodedStream(&coded_os))
46 {
47 std::cerr << "ERROR: Failed to serialize a ONNX model" << std::endl;
48 return 255;
49 }
50
51 return 0;
52}
Definition View.h:23
std::unique_ptr< UI > make_ui(const Cmdline &cmdargs)
Definition Support.cpp:61
int run(int argc, const char *const *argv) const override