MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / run

Function run

abalone-node/train.js:33–55  ·  view source on GitHub ↗

* Train a model with dataset, then save the model to a local folder.

(epochs, batchSize, savePath)

Source from the content-addressed store, hash-verified

31 * Train a model with dataset, then save the model to a local folder.
32 */
33async function run(epochs, batchSize, savePath) {
34 const datasetObj = await createDataset('file://' + csvPath);
35 const model = createModel([datasetObj.numOfColumns]);
36 // The dataset has 4177 rows. Split them into 2 groups, one for training and
37 // one for validation. Take about 3500 rows as train dataset, and the rest as
38 // validation dataset.
39 const trainBatches = Math.floor(3500 / batchSize);
40 const dataset = datasetObj.dataset.shuffle(1000).batch(batchSize);
41 const trainDataset = dataset.take(trainBatches);
42 const validationDataset = dataset.skip(trainBatches);
43
44 await model.fitDataset(
45 trainDataset, {epochs: epochs, validationData: validationDataset});
46
47 await model.save(savePath);
48
49 const loadedModel = await tf.loadLayersModel(savePath + '/model.json');
50 const result = loadedModel.predict(
51 tf.tensor2d([[0, 0.625, 0.495, 0.165, 1.262, 0.507, 0.318, 0.39]]));
52 console.log(
53 'The actual test abalone age is 10, the inference result from the model is ' +
54 result.dataSync());
55}
56
57const parser = new argparse.ArgumentParser(
58 {description: 'TensorFlow.js-Node Abalone Example.', addHelp: true});

Callers 1

train.jsFile · 0.70

Calls 3

createDatasetFunction · 0.85
createModelFunction · 0.70
predictMethod · 0.45

Tested by

no test coverage detected