-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Onnx2NeoML executable Signed-off-by: Boris Zimka <boris.zimka@abbyy.com> * Change Onnx2NeoML binary dir to default Signed-off-by: Boris Zimka <boris.zimka@abbyy.com> * Change Onnx2NeoML project name Signed-off-by: Boris Zimka <boris.zimka@abbyy.com> * Explicitly define Onnx2NeoML Help as static Signed-off-by: Boris Zimka <boris.zimka@abbyy.com> * Replace constexpr with const Signed-off-by: Boris Zimka <boris.zimka@abbyy.com> * Turn off Onnx2NeoML for mobile Signed-off-by: Boris Zimka <boris.zimka@abbyy.com> * Fix code review Signed-off-by: Boris Zimka <boris.zimka@abbyy.com> Co-authored-by: Boris Zimka <boris.zimka@abbyy.com> Co-authored-by: Valeriy Fedyunin <valery.fedyunin@abbyy.com>
- Loading branch information
1 parent
77dfc6c
commit 2d0e109
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 3.11 FATAL_ERROR) | ||
|
||
project( Onnx2NeoML LANGUAGES CXX) | ||
|
||
include(Version) | ||
include(Settings) | ||
include(GNUInstallDirs) | ||
|
||
set_global_variables() | ||
|
||
add_executable(Onnx2NeoML Onnx2NeoML.cpp) | ||
|
||
target_link_libraries(Onnx2NeoML PRIVATE NeoML NeoOnnx NeoMathEngine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* Copyright © 2017-2020 ABBYY Production LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--------------------------------------------------------------------------------------------------------------*/ | ||
#include <string> | ||
#include <NeoOnnx/NeoOnnx.h> | ||
#include <NeoMathEngine/NeoMathEngine.h> | ||
#include <NeoML/Random.h> | ||
#include <iostream> | ||
|
||
using namespace NeoML; | ||
|
||
int ConvertOnnx2NeoML( const char* inputOnnxFilename, const char* outputDnnArchiveFileName ) | ||
{ | ||
CArray<const char*> inputs; | ||
CArray<const char*> outputs; | ||
IMathEngine& mathEng = GetDefaultCpuMathEngine(); | ||
CRandom random( 0x123 ); | ||
CDnn net( random, mathEng ); | ||
try { | ||
NeoOnnx::LoadFromOnnx( inputOnnxFilename, net, inputs, outputs ); | ||
{ | ||
CArchiveFile file( outputDnnArchiveFileName, CArchive::store ); | ||
CArchive archive( &file, CArchive::SD_Storing ); | ||
archive.Serialize( net ); | ||
} | ||
return 0; | ||
} catch( std::exception& exc ) { | ||
std::cout << "Exception" << std::endl; | ||
std::cout << exc.what() << std::endl; | ||
return 1; | ||
} | ||
}; | ||
static const char* Help = | ||
"Usage:\n$ Onnx2NeoML <path to some existing model.onnx> <path to new saved model.dnnarchive>\n" | ||
"Use this tool to convert your ONNX model " | ||
"into the archived NeoML::CDnn. To be converted your model " | ||
"must use only supported NeoOnnx operators."; | ||
|
||
|
||
int main( int argc, char* argv[] ) | ||
{ | ||
if( argc == 1 ) { | ||
std::cout << Help << std::endl; | ||
return 0; | ||
}; | ||
if( argc != 3 ) { | ||
std::cout << "Error, expected 2 args, got " << argc - 1 << std::endl; | ||
std::cout << Help << std::endl; | ||
return 1; | ||
} | ||
const char* inpath = argv[1]; | ||
const char* outpath = argv[2]; | ||
return ConvertOnnx2NeoML( inpath, outpath ); | ||
} |