Skip to content

Instantly share code, notes, and snippets.

View guschmue's full-sized avatar

Guenther Schmuelling guschmue

  • Microsoft
  • Sunnyvale
View GitHub Profile
# 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
@guschmue
guschmue / onnx-allnodes-are-outputs.py
Last active March 6, 2024 03:48
diff onnx models node by node
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
@guschmue
guschmue / to_onnx.py
Last active September 25, 2020 23:13
tf.keras to onnx
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@guschmue
guschmue / mobilenetv1-to-onnx.sh
Created April 10, 2019 15:40
mobilenetv1-to-onnx
#!/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"
@guschmue
guschmue / simple_scalar_test.py
Created May 8, 2017 18:14
simple_scalar_test.py
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")
@guschmue
guschmue / tf_user_ops.cmake
Last active September 13, 2019 16:11
example how to build a user_op for windows
# 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
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)
# 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