I have created a tensorflow.js model that predicts outputs in multiples of two. For example, if the input is 16, the prediction should be 32. However, even after providing the input data and labels accordingly, the output printed is [[1],] after prediction.print().
Code: -
const data = tf.tensor([2,4,6,8,10,12,14,16,18,20,22,24,26,28,30])
const label = tf.tensor([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
const model = tf.sequential()
model.add(tf.layers.dense({inputShape : [1], units : 32, activation : 'relu'}))
model.add(tf.layers.dense({ units : 1, activation : 'softmax'}))
model.compile({
optimizer:'sgd',
loss:'meanSquaredError',
metrics:['accuracy']
})
function onBatchEnd (batch,logs){
// console.log(logs.acc)
}
model.fit(data,label,{
epochs: 50,
batchSize : 4,
callbacks:{onBatchEnd}
}).then(info =>{
console.log(info.history.acc);
const prediction = model.predict(tf.tensor([16]))
prediction.print()
})
Output from Prediction.print(): [[1],]
Please explain the meaning of inputShape. How do I determine which inputShape to provide? For example, if my tensor is [[1,2],[3,4],[5,6]], what would the inputShape be for this? Also, could you provide some resources to study activation functions such as relu and softmax? Additionally, why does the output layer unit need to be one (1) only? If I specify any other value, it results in an error. (Explanation not clear)