This moved to here: https://github.com/onnx/tensorflow-onnx/blob/master/tutorials/BertTutorial.ipynb
This file contains hidden or 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
# Copyright (c) Microsoft Corporation. All rights reserved. | |
# Licensed under the MIT license. | |
"""Test examples.""" | |
import os | |
import subprocess | |
import unittest | |
import tensorflow as tf | |
import numpy as np |
This file contains hidden or 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
from __future__ import division | |
from __future__ import print_function | |
from __future__ import unicode_literals | |
import argparse | |
import logging | |
import traceback | |
import numpy as np | |
import onnx |
This file contains hidden or 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
import tf2onnx | |
from tensorflow.python.keras.saving import saving_utils as _saving_utils | |
def to_onnx(model, output=None): | |
function = _saving_utils.trace_model_call(model) | |
concrete_func = function.get_concrete_function() | |
input_names = [input_tensor.name for input_tensor in concrete_func.inputs | |
if input_tensor.dtype != tf.dtypes.resource] | |
output_names = [output_tensor.name for output_tensor in concrete_func.outputs |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
#!/bin/bash | |
# convert mobilenet to onnx | |
python -c "import tf2onnx" > /dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
echo "We use tensorflow-onnx to convert tensorflow to onnx." | |
echo "See https://github.com/onnx/tensorflow-onnx for details." | |
echo "Install with:" | |
echo "pip install tf2onnx" |
This file contains hidden or 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
import os | |
import time | |
import tensorflow as tf | |
out_dir = os.path.abspath(os.path.join(os.path.curdir, "runs", str(int(time.time())))) | |
if not os.path.exists(out_dir): | |
os.mkdir(out_dir) | |
x = tf.placeholder(tf.float32, name="x") |
This file contains hidden or 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
# example how to build a user_op for windows | |
# | |
# 1. save this file as tensorflow/contrib/cmake/tf_user_ops.cmake | |
# 2. append "include(tf_user_ops.cmake)" to CMakeLists.txt | |
# 3. call cmake (see tensorflow/contrib/cmake/README.md), ie: | |
# cmake %cmake_dir% -A x64 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DPYTHON_EXECUTABLE=%PY%\python.exe | |
# -DPYTHON_LIBRARIES=%PY%\libs\python35.lib -DSWIG_EXECUTABLE=c:\local\swigwin-3.0.10\swig.exe | |
# -Dtensorflow_BUILD_PYTHON_TESTS=ON | |
# 4. you need to build the source tree once to generate all header files needed, ie: | |
# MSBuild /p:Configuration=RelWithDebInfo tf_python_build_pip_package.vcxproj |
This file contains hidden or 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
cmake_minimum_required(VERSION 3.5) | |
project(user_ops C CXX) | |
set(CMAKE_CXX_STANDARD 14) | |
set (tensorflow_SOURCE_DIR "c:/src/tensorflow.guschmue") | |
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | |
add_definitions(/I${tensorflow_SOURCE_DIR} /I${tensorflow_SOURCE_DIR}/cmake_build) | |
add_definitions(-DEIGEN_AVOID_STL_ARRAY) |
This file contains hidden or 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
# install cmake 3.6 from here: https://cmake.org/files/v3.6/cmake-3.6.3.zip | |
# install swig 3.0.10 | |
# install anconda3 | |
# install visual studio >= 2015.update3 | |
# | |
set PreferredToolArchitecture=x64 | |
set rel=RelWithDebInfo | |
set cmake_dir=%cd%\tensorflow\contrib\cmake |
NewerOlder