Public
Edited
Oct 12, 2023
Insert cell
Insert cell
cocoSsd = await import("https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd@2.2.3/+esm")
Insert cell
tf = await import("https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.11.0/+esm")
Insert cell
loadModel = async () => {
const model = await cocoSsd.load();
return model;
};
Insert cell
modifyModel = (model) => {
const newModel = tf.model({
inputs: model.inputs,
outputs: model.layers[model.layers.length - 2].output
});
return newModel;
};

Insert cell
compileModel = (model) => {
model.compile({
optimizer: tf.train.adam(),
loss: 'categoricalCrossentropy',
metrics: ['accuracy']
});
};

Insert cell
trainModel = async (model, trainData, valData) => {
await model.fit(trainData, {
epochs: 10,
validationData: valData
});
};
Insert cell
run = async () => {
const model = await loadModel();
const modifiedModel = modifyModel(model);
compileModel(modifiedModel);
// Assume trainData and valData are prepared beforehand
// await trainModel(modifiedModel, trainData, valData);
};
Insert cell
model = await loadModel();
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more