Skip to content

Tensorflow.RuntimeError: 'Current graph is not default graph. Default Graph Key #4568

@BillMcCrary

Description

@BillMcCrary

We would like to be able to load multiple models from disk on startup, then infer against them without having to reload from disk each pass.

If I try to keep 2 models in memory at the same time, I get an error if not calling against the last one initialized from disk.

i.e. this works - only including code needed to generate the error:

            MLContext context = new MLContext();

            TensorFlowModel model1 = context.Model.LoadTensorFlowModel("Model1");

            TensorFlowEstimator estimator1 = model1.ScoreTensorFlowModel("serving_default_input_1", "StatefulPartitionedCall");

            TensorFlowModel model2 = context.Model.LoadTensorFlowModel("Model2");

            TensorFlowEstimator estimator2 = model2.ScoreTensorFlowModel("serving_default_input_1", "StatefulPartitionedCall");

but this throws an error like "Tensorflow.RuntimeError: 'Current graph is not default graph":

            MLContext context = new MLContext();

            TensorFlowModel model1 = context.Model.LoadTensorFlowModel("Model1");

            TensorFlowModel model2 = context.Model.LoadTensorFlowModel("Model2");
            
            TensorFlowEstimator estimator1 = model1.ScoreTensorFlowModel("serving_default_input_1", "StatefulPartitionedCall");

            TensorFlowEstimator estimator2 = model2.ScoreTensorFlowModel("serving_default_input_1", "StatefulPartitionedCall");

I guess we could roll our own process to load from disk to stream 1x, then call context.Model.Load() but that still smells wrong - we're still initializing the model over and over just avoiding disk calls. Is this a bug or are we doing something wrong?

Metadata

Metadata

Labels

P1Priority of the issue for triage purpose: Needs to be fixed soon.bugSomething isn't workingloadsaveBugs related loading and saving data or models

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions