As I delve into my machine learning project, I find myself faced with the challenge of deploying my algorithm using Angular. While I have successfully uploaded the pretrained model and managed to import data from a CSV file, I am now struggling with properly transforming this data into the required tensor format. My LSTM Neural Network model relies on timewindows of 60 accelerometer data points (x-axis, y-axis, z-axis) to predict human activities, necessitating tensors in the format [any, 60,3]. Below is an excerpt of the code I have developed so far:
Loading the model here
async loadModel() {
this.model = await tf.loadLayersModel('assets/tfjs_model/model.json');
};
Currently, I have set up a placeholder using the tf.ones() function for testing purposes to confirm the functionality of my predictions (which are accurate!)
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 section of the code focuses on loading 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;
}
Here is the CSVRecord class
export class CSVRecord {
public timestep: any;
public xAxis: any;
public yAxis: any;
public zAxis: any;
}