Skip to content

Conversation

@zeahmed
Copy link
Contributor

@zeahmed zeahmed commented Oct 9, 2018

This PR fixes #1157 where loaded TFSession is wrapped into TensorFlowModelInfo class.
In addition to that, the TensorFlowModelInfo provides following methods to query schema

  • GetModelSchema(): Get all the information in the model as ISchema object.
  • GetInputSchema(): Get only input related information from the model as ISchema object. It is useful for the case when the graph is very large and user cannot locate inputs in such a large graphs.

Please see the modified test for more insights.

using Microsoft.ML.Runtime;
using Microsoft.ML.Runtime.Data;

namespace Microsoft.ML.Transforms.TensorFlow
Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably put it into same namespace as tensorflow transform, i.e. Microsoft.ML.Transforms.

Also requires update in documentation.
Would be nice to explain user in which case he need to use simple constructor and in which this Context object. #Closed

{
/// <summary>
/// This class holds the information related to TensorFLow model and session.
/// It provides a convenient way to query model schema
Copy link
Contributor

@Zruty0 Zruty0 Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chema [](start = 53, length = 5)

please use correct punctuation #Closed

/// </summary>
public class TensorFlowModelContext
{
internal TFSession Session { get; private set; }
Copy link
Contributor

@Zruty0 Zruty0 Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private set; [](start = 42, length = 12)

use just { get; } for read-only properties #Closed

internal TFSession Session { get; private set; }
public string ModelPath { get; private set; }

private readonly IHostEnvironment _host;
Copy link
Contributor

@Zruty0 Zruty0 Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_host [](start = 42, length = 5)

either rename to _env or register an IHost #Closed

}

/// <summary>
/// Get <see cref="ISchema"/> for only those nodes which are marked "PlaceHolder" in the TensorFlow model.
Copy link
Contributor

@Zruty0 Zruty0 Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PlaceHolder [](start = 77, length = 11)

is it PlaceHolder or Placeholder ? #Closed

/// - Get complete schema by calling <see cref="GetModelSchema()"/>
/// - Get schema related to model input by calling <see cref="GetInputSchema()"/>
/// </summary>
public class TensorFlowModelContext
Copy link
Contributor

@Zruty0 Zruty0 Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TensorFlowModelContext [](start = 17, length = 22)

can we think of a better name than Context ? We are trying to limit ML.NET to just one context, called MLContext #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something along the lines of 'handle', or I don't know, Info ?


In reply to: 223784755 [](ancestors = 223784755)

{
var imageHeight = 32;
var imageWidth = 32;
var tensorFlowContext = TensorFlowUtils.LoadTensorFlowModel(env, model_location);
Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tensorFlowContext [](start = 20, length = 17)

tensorFlowModel maybe? Since name of the class in not Context anymore #Closed

private sealed class Reconciler : EstimatorReconciler
{
private readonly string _modelFile;
private readonly TensorFlowModelInfo _tensorFlowModelContext;
Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_tensorFlowModelContext [](start = 49, length = 23)

_tensorFlowModelInfo maybe? #Closed

Copy link
Contributor

@Zruty0 Zruty0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

public Reconciler(string modelFile)
{
Contracts.AssertNonEmpty(modelFile);
_modelFile = modelFile;
Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_modelFile [](start = 16, length = 10)

I would probably get rid of _modelFile and just use _tensorFlowModelContext since you can create it from modelFile anyway.
Less complicated I think from code standpoint #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...I tried and think that its better to keep it as-is. The reason is because TensorFlowUtils.LoadTensorFlowModel requires IHostEnvironment which is not available until Reconcile method is hit.
Let me know if you are thinking of some other solution?


In reply to: 223836239 [](ancestors = 223836239)

namespace Microsoft.ML.Transforms.TensorFlow
{
/// <summary>
/// This class holds the information related to TensorFLow model and session.
Copy link
Member

@abgoswam abgoswam Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L [](start = 59, length = 1)

nit: typo #Resolved

Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@zeahmed zeahmed changed the title Exposed TensorFLow session as TensorFlowModelContext class Exposed TensorFLow session as TensorFlowModelInfo class Oct 9, 2018
@zeahmed zeahmed merged commit 8ca1c93 into dotnet:master Oct 9, 2018
@ghost ghost locked as resolved and limited conversation to collaborators Mar 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manage TensorFlow model loading so that it is not loaded twice; first for schema then for use in TFTransform.

4 participants