Instantly share code, notes, and snippets.

View tf-serving-request.py
from grpc.beta import implementations
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2
from tensorflow.python.framework import tensor_util
import tensorflow as tf
import cv2
import numpy as np
host = '1.2.3.4'
port = 8500
View tensorflow_model_analysis.py
import tensorflow as tf
import argparse
def profile(graph, cmd):
run_meta = tf.RunMetadata()
writer = tf.summary.FileWriter("./graph", graph)
writer.close()
opts = tf.profiler.ProfileOptionBuilder.float_operation()
View tensorflow_gen_saved_model.py
import tensorflow as tf
import argparse
import os
parser = argparse.ArgumentParser(description='Generate a saved model.')
parser.add_argument('--export_model_dir', type=str, default='./saved_model/the_model', help='export model directory')
parser.add_argument('--model_version', type=int, default=1, help='model version')
parser.add_argument('--model', type=str, default='the_model.pb', help='model pb file')
parser.add_argument("--input_tensor", default="input:0", help="input tensor", type=str)
parser.add_argument("--output_tensor", default="output:0", help="output tensor", type=str)
View matplotlib-3d-subplots.txt
# from https://stackoverflow.com/questions/30755249/hierarchy-in-matplotlib
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
subplot_args = {'projection':'3d'}
fig, ax = plt.subplots(subplot_kw=subplot_args)
View tensorflow-model-profiling.txt
run_meta = tf.RunMetadata()
with tf.Session(config=config) as sess:
opts = tf.profiler.ProfileOptionBuilder.float_operation()
flops = tf.profiler.profile(sess.graph, run_meta=run_meta, cmd='op', options=opts)
opts = tf.profiler.ProfileOptionBuilder.trainable_variables_parameter()
params = tf.profiler.profile(sess.graph, run_meta=run_meta, cmd='op', options=opts)
print("ops {:,} --- params {:,}".format(flops.total_float_ops, params.total_parameters))
View python-argparse-example.txt
import argparse
import os
parser = argparse.ArgumentParser(description='Generate a saved model.')
parser.add_argument('--export_model_dir', type=str, default='./saved_model/dense-lite', help='export model directory')
parser.add_argument('--model_version', type=int, default=1, help='model version')
parser.add_argument('--model', type=str, default='dense.pb', help='model pb file')
parser.add_argument("--input_tensor", default="image:0", help="input tensor", type=str)
parser.add_argument("--output_tensor", default="Openpose/concat_stage7:0", help="output tensor", type=str)
args = parser.parse_args()
View mac-os-build-misc.txt
use "-undefined dynamic_lookup" instead of "-lpython"
use "-Xpreprocessor -fopenmp -lomp" instead of "-fopenmp"
flags to be added for lpython: "-L/usr/local/opt/libomp/lib -I/usr/include/python2.7" ?
get numpy include dir: np.get_include()