0

For my anguar project I'm trying to upload a csv file from my assets folder with tf.data.csv, but the file is not being recognized by the code meaning, that the created Object is empty. Is it even possible to upload a csv via tf.data.csv() from assets? And if yes, how? :)

async loadData(){
  const csvUrl = 'assets/tfjs_model/lsm6dsm.csv' as string;
    const csvDataset = tf.data.csv(csvUrl, 
    {
      hasHeader:false, 
      columnNames:["timestamp", "x-axis","y-axis","z-axis"],
    }
    ) as any;
    console.log(csvDataset);
    return csvDataset
  }

Here is what is being printed in the console:

base: e {size: null, input: e}

columnConfigs: undefined

columnNamesValidated: false

configuredColumnsOnly: undefined

delimWhitespace: false

delimiter: ","

fullColumnNames: (4) ["timestamp", "x-axis", "y-axis", "z-axis"]

hasHeader: false

input: e {url: "assets/tfjs_model/lsm6dsm.csv", fileOptions: {…}}

size: null

proto: t

0

1 Answer 1

1

Yes of course this is possible. I don't know if you CSV has column headers with "" if so try this

async function example(){

// Import from CSV
const dataSet = tf.data.csv('https://raw.githubusercontent.com/JuliaStats/RDatasets.jl/master/doc/datasets.csv');

// Extract x and y values to plot
const pointsDataSet = dataSet.map(record => ({
    x: record["\"Rows\""],
    y: record["\"Columns\""]
}));

const points = await pointsDataSet.toArray();

console.log(points);
}

example();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.