dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.05k stars 1.88k forks source link

Error inferring columns with AutoML in Blazor WASM #7249

Open YoungYuFlex opened 1 month ago

YoungYuFlex commented 1 month ago

I am trying to use AutoML in Blazor WASM and I am receiving this error message no matter what data source file I am using:  Unable to split the file provided into multiple, consistent columns. Readable formats include delimited files such as CSV/TSV. Check for a consistent number of columns and proper escaping and quoting.

I tried different csv/tsv files and same error everytime. I also tried basically same code and same data file running in a console application and it worked fine. And I also tried downloading the file after uploading it, and examined it in vscode, nothing seemed to be wrong, no issue for linebreaking...

This is my code and the error is popping when trying to infercolumns...

public async Task LoadFiles(InputFileChangeEventArgs e)
{
    var file = e.File;
    var fileName = file.Name;

    // Saving file
    await using FileStream fs = new(fileName, FileMode.Create);
    await file.OpenReadStream(1024*1024*1024).CopyToAsync(fs);

    // Initialize MLContext
    MLContext ctx = new MLContext();

    // Define data path
    var dataPath = Path.GetFullPath(fileName);

    // Infer column information
    ColumnInferenceResults columnInference = ctx.Auto().InferColumns(
        dataPath,
        labelColumnIndex: 0,
        hasHeader: true,
        // separatorChar: ',',
        groupColumns: false,
        allowQuoting: true,
        trimWhitespace: true
    );
}
LittleLittleCloud commented 1 month ago

Sharing a snapshot of the saved file would be helpful... In the meantime, Are you sure the file got actually saved to disk after reading from stream and before infering column?