question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VectorType attribute with dynamic dimension

See original GitHub issue

The VectorType attribute can be added to an array-valued field when the length of the array is known at compile time, e.g.,

        public class Data
        {
            [ColumnName("Features")]
            [VectorType(2)]
            public float[] Features;

            [ColumnName("Label")]
            public bool Label;
        }

However, what if the length of the array is only known at run time?

For example, given IEnumerable<Data> data where the length of the Features array is given by int numFeatures, I need to be able to pass numFeatures to CollectionDataSource.Create(data) somehow, and remove the static 2 argument to the VectorType attribute on the Features field.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
drake7707commented, May 16, 2019

@Anaschouihdi

Create a schema definition and pass it as the 2nd parameter in the LoadFromEnumerable method:

var schemaDef = SchemaDefinition.Create(typeof(Data));
schemaDef["Features"].ColumnType = new VectorDataViewType(NumberDataViewType.Single, 5);
var trainingDataView = mlContext.Data.LoadFromEnumerable(dataArray, schemaDef);
2reactions
drake7707commented, May 16, 2019

One thing I forgot to mention is that you’ll also need to pass the same schema definition as an additional parameter inputSchemaDefinition in the prediction engine:

var predEngine = mlContext.Model.CreatePredictionEngine<IrisData, IrisPrediction>(trainedModel, inputSchemaDefinition: schemaDef);
Read more comments on GitHub >

github_iconTop Results From Across the Web

VectorType attribute with dynamic dimension ML.NET
I am working on training and evaluation in ML.NET. The data comes from a .csv file. According to the requirements, there may be...
Read more >
VectorTypeAttribute Constructor (Microsoft.ML.Data)
Parameters. Dimensions of array. All values should be non-negative. A zero value indicates that the vector type is considered to have unknown length...
Read more >
Quick reference guide
RowsAtCompileTime and ColsAtCompileTime are the number of rows and columns of the matrix as known at compile-time or Dynamic . Options can be...
Read more >
How to Initialize Vector in C++ [6 Different Ways]
Syntax. The syntax to declare a vector in C++ is: vector <type> vector_name(size). Description of the syntax. Keyword “ ...
Read more >
Matrix< Scalar_, Rows_, Cols_, Options_, MaxRows_, ...
Dynamic -size means that the numbers of rows or columns are not necessarily known at compile-time. In this case they are runtime variables,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found