Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use schema from trained model instead of inferring it again from type when creating prediction engine. #347

Closed
zeahmed opened this issue Jun 11, 2018 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@zeahmed
Copy link
Contributor

zeahmed commented Jun 11, 2018

System information

  • Windows/Linux/MacOS:
  • .NET Version: 2.1.200:

Issue

  • Defining custom schema using TextLoaderArguments in TextLoader?
  • Training failed when creating prediction engine?
  • Expect that CreateBatchPredictionEngine should use schema from trained model instead of inferring schema again from input type?

Source code / logs

public class IrisData
{
    public float Label;

    public float[] Features;
}

public class IrisPrediction
{
    [ColumnName("Score")]
    public float[] PredictedLabels;
}
        
public void SampleTest()
{
    string dataPath = GetDataPath("iris.txt");

    var pipeline = new LearningPipeline(seed: 1, conc: 1);

    pipeline.Add(new TextLoader(dataPath)
    {
        Arguments = new TextLoaderArguments
        {
            Separator = new[] { '\t' },
            HasHeader = true,
            Column = new[]
            {
                new TextLoaderColumn()
                {
                    Name = "Label",
                    Source = new [] { new TextLoaderRange(0) },
                    Type = Runtime.Data.DataKind.Num
                },

                new TextLoaderColumn()
                {
                    Name = "Features",
                    Source = new [] { new TextLoaderRange(1,4) },
                    Type = Runtime.Data.DataKind.Num
                }
            }
        }
    });

    pipeline.Add(new StochasticDualCoordinateAscentClassifier()
    {
        NormalizeFeatures = NormalizeOption.No
    });

    PredictionModel<IrisData, IrisPrediction> model = pipeline.Train<IrisData, IrisPrediction>();

    IrisPrediction prediction = model.Predict(new IrisData()
    {
        Features = new[] { 3.3f, 1.6f, 0.2f, 5.1f }
    });

    Assert.Equal(1, prediction.PredictedLabels[0], 2);
    Assert.Equal(0, prediction.PredictedLabels[1], 2);
    Assert.Equal(0, prediction.PredictedLabels[2], 2);
}
@shauheen shauheen added the bug Something isn't working label Jun 13, 2018
@shauheen shauheen added this to the 0618 milestone Jun 13, 2018
@TomFinley
Copy link
Contributor

Hi @zeahmed , is related to the issue in #216 , and other issues opened about not being able to properly save the loader models in entry-point land?

@zeahmed
Copy link
Contributor Author

zeahmed commented Jun 18, 2018

@TomFinley, not directly related to #216 in a sense that any changes made to #216 will not directly contribute to solve it.

The problem here is that during training in this particular example, the schema is explicitly provided in TextLoader. However, the BatchPredictionEngine uses input type (IrisData) to infer schema and it fails there.

@thebitllc
Copy link

I have the same issue, I have written a custom loader with a custom schema and it fails in the
CreateBatchPredictionEngine. CreateBatchPredictionEngine infers the schema from the type using SchemaDefinition.Create(userType). My schema is generated using different logic.

@shauheen shauheen modified the milestones: 0618, 0718 Jul 5, 2018
@shauheen shauheen removed this from the 0718 milestone Aug 4, 2018
@shauheen shauheen added this to the 0918 milestone Aug 30, 2018
@Zruty0 Zruty0 self-assigned this Aug 31, 2018
@shauheen shauheen removed this from the 0918 milestone Sep 25, 2018
@shauheen
Copy link
Contributor

@Zruty0 is this still valid?

@Zruty0
Copy link
Contributor

Zruty0 commented Sep 25, 2018

It is still valid.

@codemzs
Copy link
Member

codemzs commented Jun 30, 2019

Not valid anymore, the new API and the prediction allows you pass in schema that you can get when you do loadModel.

@codemzs codemzs closed this as completed Jun 30, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Mar 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants