This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load a graph model from a URL | |
const model = await tf.loadGraphModel(MODEL_URL) | |
// create a tensor from an image | |
const inputTensor = tf.browser.fromPixels(imageNode) | |
// run prediction | |
const prediction = model.predict(inputTensor) | |
// process output/prediction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a tensor from an image - tensorflow.js 1.0.0 | |
// https://js.tensorflow.org/api/1.0.0/#browser.fromPixels | |
const imageTensor = tf.browser.fromPixels(imageElement) | |
// insert a dimension into the tensor's shape | |
const preprocessedInput = imageTensor.expandDims() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tensorflow.js 1.0.0 | |
const MODEL_URL = '/model/model.json' | |
// https://js.tensorflow.org/api/1.0.0/#loadGraphModel | |
const model = await tf.loadGraphModel(MODEL_URL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let midiOutputs | |
let midiInputs | |
// check MIDI support/availability | |
if (navigator.requestMIDIAccess) { | |
navigator.requestMIDIAccess().then(function (access) { | |
// get output devices | |
midiOutputs = Array.from(access.outputs.values()) | |
// get input devices |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// instantiate audio context | |
let audioCtx = new (window.AudioContext || window.webkitAudioContext)() | |
// create gain node (volume) | |
let gainNode = audioCtx.createGain() | |
// create oscillator | |
let oscillator = audioCtx.createOscillator() | |
// connect audio nodes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const colorMapUrl = '/assets/color-map.json' | |
// load the color-map file | |
const response = await fetch(colorMapUrl) | |
const colorMap = await response.json() | |
// get image width, height from output | |
const imageWidth = prediction.shape[2] | |
const imageHeight = prediction.shape[1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// generates output prediction | |
const prediction = model.predict(preprocessedInput) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a tensor from an image - tensorflow.js 0.15.1 | |
// https://js.tensorflow.org/api/0.15.1/#fromPixels | |
const imageTensor = tf.fromPixels(imageElement) | |
// insert a dimension into the tensor's shape | |
const preprocessedInput = imageTensor.expandDims() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- load TensorFlow.js --> | |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.python.tools import strip_unused_lib | |
from tensorflow.python.framework import dtypes | |
import tensorflow as tf | |
# set the appropriate input and output nodes | |
input_node_names = ['decode/DecodeJpeg'] | |
output_node_names = ['softmax'] | |
# set the appropriate path to the frozen graph and directory to output stripped graph | |
frozen_graph_path = '/Users/va/models/frozen_graph.pb' |
NewerOlder