Skip to content

Instantly share code, notes, and snippets.

View caisq's full-sized avatar

Shanqing Cai caisq

View GitHub Profile
@caisq
caisq / iris_fit_dataset.ipynb
Last active March 9, 2019 21:01
Simple example of TensorFlow.js in IJavaScript Notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@caisq
caisq / breaking_API_changes.md
Last active April 23, 2019 12:57
Breaking API Changes and New APIs in TensorFlow.js 1.0 Through Examples

1. Model-loading function name changes

Rationale: Indicate type of model being loaded more explicitly in code.

For models converted from Keras and models saved from TensorFlow.js itself:

// Before: 
await tf.loadModel('http://server/model.json');
@caisq
caisq / custom-layers-in-tensorflow-js-stateful-configurable-and-serializable.markdown
Last active August 12, 2024 09:02
Custom Layers in TensorFlow.js (Stateful, Configurable, and Serializable)
@caisq
caisq / keras_mobilenet_to_tfjs.py
Created October 27, 2018 17:00
Convert Keras MobileNet Application intothe TensorFlow.js Format
import keras
import tensorflowjs as tfjs
model = keras.applications.mobilenet.MobileNet(alpha=0.25)
tfjs.converters.save_keras_model(model, '/tmp/mobilnet_0.25')
const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node-gpu');
(async function() {
const inputShape = [43, 232, 1];
const numClasses = 10;
const model = tf.sequential();
model.add(tf.layers.conv2d({
filters: 8, kernelSize: [2, 8],
import time
import tensorflow as tf
tf.enable_eager_execution()
# with tf.device('gpu:0'):
def model(xs):
ys = tf.keras.layers.Conv2D(8, [2, 8], activation='relu')(xs)
ys = tf.keras.layers.MaxPool2D([2, 2], strides=[2, 2])(ys)
@caisq
caisq / gist:fc8419c7a867bbc759d07b67169e7d35
Created September 5, 2018 18:53
TFJS-node ProgbarCallback
// To see the callback live, uncomment the following lines for and try the
// code out with ts-node.
// (async function() {
// const model = tfl.sequential({layers: [
// tfl.layers.dense({units: 100, inputShape: [20], activation: 'relu'}),
// tfl.layers.dense({units: 1})
// ]});
// model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
// const xs = tfc.ones([500, 20]);