Skip to content

Load tensorflow model created by python error while 'Visual Studio Tools for AI' well #2513

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

Closed
slmgong opened this issue Feb 12, 2019 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@slmgong
Copy link

slmgong commented Feb 12, 2019

System information

  • OS version/distro:
    windows 10
    ml.net v0.10.0

  • .NET Version (eg., dotnet --info):
    dotcore v2.1

Issue

  • What did you do?
  • What happened?
  • What did you expect?

Source code / logs

I have a tensorflow model, when I use Visual Studio Tools for AI, it auto generator code like this

`

private static List<long> serving_defaultFeaturesShapeForSingleInput = new List<long> { 1, 6, 8 };
private static List<string> serving_defaultInputNames = new List<string> { "features" };
private static List<string> serving_defaultOutputNames = new List<string> { "predictions" };
etc...
/// <summary>
/// Runs inference on abc model for a single input data.
/// </summary>
/// <param name="features">From signature: input 1 with tensor name features; Shape of the input: { 1, 6, 8 }</param>
public IEnumerable<float> Serving_default(IEnumerable<float> features)
{
    List<Tensor> result = manager.RunModel(
        modelName,
        int.MaxValue,
        serving_defaultInputNames,
        new List<Tensor> { new Tensor(features.ToList(), serving_defaultFeaturesShapeForSingleInput) },
        serving_defaultOutputNames
    );
    List<float> r0 = new List<float>();
    result[0].CopyTo(r0);
    return r0;
}     

`
and everything goes well, I run this instance and got a return.

when I use the ML.Net v0.10.0 try a test the same tensorflow model :

`

public class TensorData
{
[VectorType(1, 4, 6)]
[ColumnName("lstm_1_input")]
public float[] input { get; set; }
}

etc.....

var pipeline = mlContext.Transforms.ScoreTensorFlowModel(
   tensorModel, new[] { "lstm_1_input" }, new[] { "lstm_1_input" });
var data = GetTensorData();
var idv = mlContext.Data.ReadFromEnumerable(data);
var trainedModel = pipeline.Fit(idv);
var predicted = trainedModel.Transform(idv);

`

it throw a exception:

System.InvalidOperationException:“Input shape mismatch: Input 'lstm_1_input' has shape [1, 4, 6], but input data is Vec<R4, 1, 4, 6>.”

1、 how to caputure the inputColumnNames/outputColumnNames from a exists model , when Visual Studio Tools for AI use different input/output names ?
2、how to construct a shape [1, 4, 6], when I change input type as float[,,] ,> it throw a

System.InvalidOperationException:“Variable length input columns not supported”.

so how I can correctly use the tensorflow model ? please give a example, thanks much.

@Ivanidzo4ka Ivanidzo4ka added the question Further information is requested label Feb 21, 2019
@Ivanidzo4ka
Copy link
Contributor

I believe this should be closed by this PR:
#2475
It just didn't get into 0.10 nuget.
Any chance you can test our daily nugets?

@zeahmed
Copy link
Contributor

zeahmed commented Feb 23, 2019

Yes #2475 should fix the problem you are facing. Regarding inspecting the input you can follow the example here.

var modelInfo = TensorFlowUtils.LoadTensorFlowModel(mlContext, modelLocation);

After loading the model with LoadTensorFlowModel, you can query the input schema using GetInputSchema method. It should give you all the input variables in the tf graph with all the necessary information i.e. nodes with optype Placeholder.

@zeahmed
Copy link
Contributor

zeahmed commented May 22, 2019

I am closing it. Please reopen it if necessary.

@zeahmed zeahmed closed this as completed May 22, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants