I'm working on a machine learning project and I'm trying to deploy my algorithm with angular. I have already uploaded the pretrained model correctly and I managed to upload data from a csv, but now I have problems to properly transform the data I have to the correct format of tensors. My model is a LSTM Neural Network that expects timewindows with the length of 60 of accelerometer data (x-axis, y-axis and z-axis) to predict human activities so tensors of the format [any, 60,3] Down below you can find the important part of my code that I have up to now
Loading the model here
async loadModel() {
this.model = await tf.loadLayersModel('assets/tfjs_model/model.json');
};
Right now I have a placeholder with the tf.ones() function to simply test, if my prediction works (it does work!!)
async predictProcess() {
const output = this.model.predict([tf.ones([10, 60, 3])]) as any;
this.predictions = Array.from(output.dataSync());
console.log(this.predictions);
};
This is the part of the code, where I load the data
getDataRecordsArrayFromCSVFile(csvRecordsArray: any, headerLength: any) {
let dataArr = [];
for (let i = 0; i < csvRecordsArray.length; i++) {
let data = (<string>csvRecordsArray[i]).split(',');
// FOR EACH ROW IN CSV FILE IF THE NUMBER OF COLUMNS
// ARE SAME AS NUMBER OF HEADER COLUMNS THEN PARSE THE DATA
if (data.length == headerLength) {
let csvRecord: CSVRecord = new CSVRecord();
// csvRecord.timestep = Number(data[0].trim());
csvRecord.xAxis = Number(data[1].trim());
csvRecord.yAxis = Number(data[2].trim());
csvRecord.zAxis = Number(data[3].trim());
dataArr.push(csvRecord);
}
}
return dataArr;
}
This is the CSVRecord class
export class CSVRecord {
public timestep: any;
public xAxis: any;
public yAxis: any;
public zAxis: any;
}