Skip to content

Instantly share code, notes, and snippets.

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:

@asimshankar
asimshankar / model.py
Last active October 10, 2021 12:45
TensorFlow: Saving and restoring variables in Go
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()
@asimshankar
asimshankar / export.py
Created June 14, 2017 00:33
Keras Model to TF SavedModel format
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 / export.py
Created June 20, 2017 00:17
Keras Models --> TensorFlow SavedModel format
# 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 / README.md
Created November 17, 2017 20:03
TensorFlow Custom Datasets
@asimshankar
asimshankar / README.md
Last active January 28, 2024 17:24
Training TensorFlow models in C++

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 / README.md
Last active April 13, 2024 15:50
Training TensorFlow models in C

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