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 mobilenet = await tf.loadLayersModel( | |
'https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json'); |
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
//The input size is [null, 224, 224, 3] | |
const input_s = mobilenet.inputs[0].shape; | |
//The output size is [null, 1000] | |
const output_s = mobilenet.outputs[0].shape; | |
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
var pred = mobilenet.predict(tf.zeros([1, 224, 224, 3])); | |
pred.argMax().print(); |
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
//The number of layers in the model '88' | |
const len = mobilenet.layers.length; | |
//this outputs the name of the 3rd layer 'conv1_relu' | |
const name3 = mobilenet.layers[3].name; |
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 layer = mobilenet.getLayer('conv_pw_13_relu'); |
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
mobilenet = tf.model({inputs: mobilenet.inputs, outputs: layer.output}); |
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
trainableModel = tf.sequential({ | |
layers: [ | |
tf.layers.flatten({inputShape: [7, 7, 256]}), | |
tf.layers.dense({ | |
units: 100, | |
activation: 'relu', | |
kernelInitializer: 'varianceScaling', | |
useBias: true | |
}), | |
tf.layers.dense({ |
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 activation = mobilenet.predict(input); | |
const predictions = trainableModel.predict(activation); |
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
//this outputs a layer of size [null, 7, 7, 256] | |
const layerOutput = layer.output.shape; |
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 tensor = tf.scalar(2); |