require('@tensorflow/tfjs-node');
var tf = require('@tensorflow/tfjs');
tf.setBackend('tensorflow');
// Tiny TFJS train / predict example.
function myFirstTfjs() {
// Create a simple model.
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));
// Prepare the model for training: Specify the loss and the optimizer.
model.compile({
loss: 'meanSquaredError',
optimizer: 'sgd'
});
// Generate some synthetic data for training. (y = 2x - 1)
const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1]);
const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]);
// Train the model using the data.
model.fit(xs, ys, {epochs: 500});
// Use the model to do inference on a data point the model hasn't seen.
// Should print approximately 39.
var predict=
model.predict(tf.tensor2d([20], [1, 1]));
console.log( "PREDICT\n", predict );
}
myFirstTfjs();
Since latest update I get this strange error:
ip-192-168-22-127:getting_started loretoparisi$ node index.js
document is not defined
2018-05-22 12:17:45.705023: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2 AVX AVX2 FMA
document is not defined
cpu backend was already registered
/Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/common.js:31
throw e;
^
Error: Argument 'a' passed to 'matMul' must be a Tensor, but got object.
--
You received this message because you are subscribed to the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+uns...@tensorflow.org.
Visit this group at https://groups.google.com/a/tensorflow.org/group/tfjs/.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/de2901dc-af72-4de1-8097-0fa35df1ca97%40tensorflow.org.
// Train the model using the data.
model.fit(xs, ys, {epochs: 500})
.then( res => {
// Use the model to do inference on a data point the model hasn't seen.
// Should print approximately 39.
var predict=
model.predict(tf.tensor2d([20], [1, 1]));
console.log( "PREDICT\n", predict );
})
.catch(error => {
console.error(error);
})
mbploreto:getting_started loretoparisi$ node index.js
document is not defined
2018-05-24 09:22:33.845516: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2 AVX AVX2 FMA
document is not defined
cpu backend was already registered
(node:83127) Warning: N-API is an experimental feature and could change at any time.
Error: Argument 'indices' passed to 'gather' must be a Tensor, but got object.
at assert (/Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/util.js:57:15)
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/b9f41808-1695-4fcb-b2ee-e1aa342c9a51%40tensorflow.org.
// Generate some synthetic data for training. (y = 2x - 1)
const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1], 'int32');
const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1], 'int32');
The former one has to do with class notation, latter with tensor. You could check if something like this works.
// Tiny TFJS train / predict example.
function myFirstTfjs() {
// Create a simple model.
const model = tf.sequential();
model.add(tf.layers.dense({ units: 1, inputShape: [1] }));
// Prepare the model for training: Specify the loss and the optimizer.
model.compile({
loss: 'meanSquaredError',
optimizer: 'sgd'
});
// Generate some synthetic data for training. (y = 2x - 1)
const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1], 'int32');
const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1], 'int32');
// Train the model using the data.
model.fit(xs, ys, { epochs: 500 })
.then(res => {
// Use the model to do inference on a data point the model hasn't seen.
// Should print approximately 39.
var predict =
model.predict(tf.tensor2d([20], [1, 1], 'int32'));
console.log("PREDICT\n", predict);
})
.catch(error => {
console.error(error);
})
}
// tiny_train_predict.js
require('@tensorflow/tfjs-node');
var tf = require('@tensorflow/tfjs');tf.setBackend('tensorflow');
inputType = 'int32'
// Tiny TFJS train / predict example. function myFirstTfjs() { // Create a simple model. const model = tf.sequential(); model.add(tf.layers.dense({ units: 1, inputShape: [1] })); // Prepare the model for training: Specify the loss and the optimizer. model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' }); // Generate some synthetic data for training. (y = 2x - 1)
const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1], inputType); const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1], inputType);
// Train the model using the data. model.fit(xs, ys, { epochs: 500 })
.then(res => {
// Use the model to do inference on a data point the model hasn't seen. // Should print approximately 39. var predict =
model.predict(tf.tensor2d([20], [1, 1], inputType)); console.log("PREDICT\n", predict.dataSync());
}) .catch(error => { console.error(error); })}
console.log("hello world");myFirstTfjs();
{ "name": "parisi", "version": "1.0.0", "description": "debugging argument error", "main": "index.js", "license": "MIT", "dependencies": { "@tensorflow/tfjs": "^0.11.6", "@tensorflow/tfjs-node": "^0.1.7" }}
$ node tiny_train_predict.js2018-06-12 10:26:22.982041: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVXhello world(node:230386) Warning: N-API is an experimental feature and could change at any time.PREDICT Float32Array [ 38.95066452026367 ]
require('@tensorflow/tfjs-node');
var tf = require('@tensorflow/tfjs');tf.setBackend('tensorflow');
function myFirstTfjs() {
const model = tf.sequential(); model.add(tf.layers.dense({ units: 1, inputShape: [1] }));
model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' }); // Generate some synthetic data for training. (y = 2x - 1) const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1]); const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]); // Train the model using the data. model.fit(xs, ys, { epochs: 500 })
.then(res => { p10 = model.predict(tf.tensor2d([5.5], [1, 1])) pExp10 = tf.exp(p10); console.log("2*5.5 - 1 SHOULD BE CLOSE TO 10"); console.log(p10.dataSync()); console.log("exp(10) SHOULD BE CLOSE TO 22026"); console.log(pExp10.dataSync());
}) .catch(error => { console.error(error); })}
console.log("hello world");myFirstTfjs();
$ node tiny_train_predict.js2018-06-12 11:00:27.261473: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVXhello world(node:242759) Warning: N-API is an experimental feature and could change at any time.2*5.5 - 1 SHOULD BE CLOSE TO 10Float32Array [ 9.994277954101562 ]exp(10) SHOULD BE CLOSE TO 22026Float32Array [ 21900.7890625 ]
:getting_started loretoparisi$ node index.js
2018-06-12 17:09:45.567768: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2 AVX AVX2 FMA
cpu backend was already registered
(node:4915) Warning: N-API is an experimental feature and could change at any time.
Error: No data provided for "dense_Dense1_input". Need data for each key in: dense_Dense1_input
at new ValueError (/Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs-layers/dist/errors.js:36:28)
at standardizeInputData (/Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:115:23)
at Model.standardizeUserData (/Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:628:13)
at Model.<anonymous> (/Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:910:49)
at step (/Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:48:23)
at Object.next (/Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:29:53)
at /Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:23:71
at new Promise (<anonymous>)
at __awaiter (/Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:19:12)
at Model.fit (/Users/loretoparisi/Documents/Projects/AI/tensorflow-node-examples/getting_started/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:903:16)
--
You received this message because you are subscribed to a topic in the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/a/tensorflow.org/d/topic/tfjs/aeeX1U7TDuI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tfjs+unsubscribe@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/492d984b-452d-4167-8c73-59e4abd5c649%40tensorflow.org.
Stan Bileschi Ph.D. | | SWE | | bile...@google.com | | 617-230-8081 |
To unsubscribe from this group and all its topics, send an email to tfjs+uns...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/492d984b-452d-4167-8c73-59e4abd5c649%40tensorflow.org.