Skip to content

Instantly share code, notes, and snippets.

Avatar

Asim Shankar asimshankar

View GitHub Profile
@asimshankar
asimshankar / README.md
Last active Oct 28, 2020
Training TensorFlow models in C
View README.md

Training TensorFlow models in C

Python is the primary language in which TensorFlow models are typically developed and trained. TensorFlow does have bindings for other programming languages. These bindings have the low-level primitives that are required to build a more complete API, however, lack much of the higher-level API richness of the Python bindings, particularly for defining the model structure.

This gist demonstrates taking a model (a TensorFlow graph) created by a Python program and running the training loop in a C program.

The model

@asimshankar
asimshankar / README.md
Last active Jul 21, 2020
Training TensorFlow models in C++
View README.md

Training TensorFlow models in C++

Python is the primary language in which TensorFlow models are typically developed and trained. TensorFlow does have bindings for other programming languages. These bindings have the low-level primitives that are required to build a more complete API, however, lack much of the higher-level API richness of the Python bindings, particularly for defining the model structure.

This file demonstrates taking a model (a TensorFlow graph) created by a Python program and running the training loop in C++.

@asimshankar
asimshankar / export.py
Created Jun 20, 2017
Keras Models --> TensorFlow SavedModel format
View export.py
# Mostly copied from https://keras.io/applications/#usage-examples-for-image-classification-models
# Changing it to use InceptionV3 instead of ResNet50
from keras.applications.inception_v3 import InceptionV3, preprocess_input, decode_predictions
from keras.preprocessing import image
import numpy as np
model = InceptionV3()
img_path = 'elephant.jpg'
@asimshankar
asimshankar / export.py
Created Jun 14, 2017
Keras Model to TF SavedModel format
View export.py
export_path = "./tf"
builder = tf.saved_model.builder.SavedModelBuilder(export_path)
signature = tf.saved_model.signature_def_utils.predict_signature_def(
inputs={"input": mod.input},
outputs={"output": mod.output})
with K.get_session() as sess:
builder.add_meta_graph_and_variables(sess=sess,
tags=[tag_constants.SERVING],
@asimshankar
asimshankar / model.py
Last active Nov 15, 2019
TensorFlow: Saving and restoring variables in Go
View model.py
import tensorflow as tf
# Construct the graph
x = tf.Variable(1, name='x')
y = tf.Variable(2, name='y')
sum = tf.assign_add(x, y, name='sum')
# Add operations to save and restore checkpoints
saver = tf.train.Saver()
View keybase.md

Keybase proof

I hereby claim:

  • I am asimshankar on github.
  • I am asimshankar (https://keybase.io/asimshankar) on keybase.
  • I have a public key whose fingerprint is 5EB2 02EC 3AE5 51CB BCBA B808 4FFA CDA8 6927 0665

To claim this, I am signing this object:

You can’t perform that action at this time.