--
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/3cd8fa6e-e01a-445b-bed3-133e15cc006e%40tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/8ea78dc5-30e6-44b8-b316-b0067dbf77f3%40tensorflow.org.
Hi Alex. I’m looking to do the exact same thing. Were you able to find any Keras examples that might help?
--
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/7395983a-c695-4d4b-a0b2-68b233d4ab09%40tensorflow.org.
In the meantime Ill try translating this Keras tutorial > https://machinelearningmastery.com/multivariate-time-series-forecasting-lstms-keras/
var data = tf.tensor2d([1, 2, 3, 4, 5, 6], [6, 1]);
var y = tf.tensor2d([1, 2, 3, 4, 5, 6], [6, 1]);
y.print()
const learningRate = 0.0001;
const optimizer = tf.train.sgd(learningRate);
const model = tf.sequential();
model.add(
tf.layers.lstm({
units: 1,
inputShape: [6, 1],
recurrentInitializer: 'glorotNormal'
})
);
model.compile({ loss: "meanSquaredError", optimizer: optimizer });
console.log('training');
await model.fit(data, y, { epochs: 200 }).then(() => {
// // Use the model to do inference on a data point the model hasnt
// // seen before:
// //console.log('Prediction:');
//
// //model.predict(tf.tensor2d([6], [1, 1])).print();
});
Input shape: 3D tensor with shape (batch_size, timesteps, input_dim
async function predictfuture(){
////////////////////////
// create fake data
///////////////////////
var xs = tf.tensor3d([
[[1],[1],[0]],
[[1],[1],[0]],
[[1],[1],[0]],
[[1],[1],[0]],
[[1],[1],[0]],
[[1],[1],[0]]
]);
xs.print();
var ys = tf.tensor3d([
[[1],[1],[0]],
[[1],[1],[0]],
[[1],[1],[0]],
[[1],[1],[0]],
[[1],[1],[0]],
[[1],[1],[0]]
]);
ys.print();
////////////////////////
// create model w/ layers api
///////////////////////
console.log('Creating Model...');
/*
model design:
i(xs) h o(ys)
batch_size -> * * * -> batch_size
timesteps -> * * * -> timesteps
input_dim -> * * * -> input_dim
*/
const model = tf.sequential();
//hidden layer
const hidden = tf.layers.lstm({
units: 3,
activation: 'sigmoid',
inputShape: [3 , 1]
});
model.add(hidden);
//output layer
const output = tf.layers.lstm({
units: 3,
activation: 'sigmoid',
inputShape: [3] //optional
});
model.add(output);
//compile
const sgdoptimizer = tf.train.sgd(0.1)
model.compile({
optimizer: sgdoptimizer,
loss: tf.losses.meanSquaredError
});
////////////////////////
// train & predict
///////////////////////
console.log('Training Model...');
await model.fit(xs, ys, { epochs: 200 }).then(() => {
console.log('Training Complete!');
console.log('Creating Prediction...');
const inputs = tf.tensor2d( [[1],[1],[0]] );
let outputs = model.predict(inputs);
outputs.print();
});
}
predictfuture();