I'm trying to pass in an array of strings and integers as training data, with a single boolean (0 or 1) as the label. However, after creating the training array and passing it to Tensorflow's fitDataset function, it complains that there are 0 tensors found.
csvTransform2 =
((val: any) => {
const {xs, ys} = val
console.log(xs)
const values = Object.values(xs) as any[]
return {xs: values, ys: ys.winner};
})
async predict () {
// Train a simple model:
let trainingData = tf.data.csv('file://file.csv', {columnConfigs: {winner: {isLabel: true}}})
const numOfColumns = (await trainingData.columnNames()).length - 1;
let newTrainingData = trainingData.map(this.csvTransform2);
const model = tf.sequential();
model.add(tf.layers.dense({units: 64, activation: 'relu', inputShape: [numOfColumns]}));
model.add(tf.layers.dense({units: 32, activation: 'relu'}));
model.add(tf.layers.dense({units: 8, activation: 'relu'}));
model.add(tf.layers.dense({units: 1, activation: 'softmax'}));
model.compile({
optimizer: 'sgd',
loss: 'sparseCategoricalCrossentropy',
metrics: ['accuracy']
});
model.fitDataset(newTrainingData, {
epochs: 10,
callbacks: {
onEpochEnd: async (epoch, logs) => {
console.log(epoch + ':' + logs.loss);
}
}
});
}
The full error is
ValueError: Error when checking model : the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see 1 Tensor(s), but instead got 0 Tensors(s).