Skip to content

Instantly share code, notes, and snippets.

View zaidalyafeai's full-sized avatar
:octocat:
Working from home

Zaid Alyafeai zaidalyafeai

:octocat:
Working from home
View GitHub Profile
const mobilenet = await tf.loadLayersModel(
'https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json');
//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;
var pred = mobilenet.predict(tf.zeros([1, 224, 224, 3]));
pred.argMax().print();
//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;
const layer = mobilenet.getLayer('conv_pw_13_relu');
mobilenet = tf.model({inputs: mobilenet.inputs, outputs: layer.output});
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({
const activation = mobilenet.predict(input);
const predictions = trainableModel.predict(activation);
//this outputs a layer of size [null, 7, 7, 256]
const layerOutput = layer.output.shape;
const tensor = tf.scalar(2);