machinelearning
machinelearning copied to clipboard
0x80004005 during CreatePredictionEngine
System information
- **OS Win 10
- **.NET Version Dot Net 6.0
Issue
Exception and System Hang
- What did you do? I am getting Prediction from the model generated for Image classification
- What happened? System Hangs
- What did you expect? Should predict the result
Source code / logs
Code
var context = new MLContext(seed: 0); var model = context.Model.Load(_modelPath, out DataViewSchema schema); PredictionEngine<Input, Output> _predicto = context.Model.CreatePredictionEngine<Input, Output>(model);
Exception Log
Constructor Details: Error during class instantiationINNERMESSAGE System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidOperationException: Error during class instantiation
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidOperationException: Error during class instantiation
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.FormatException: Tensorflow exception triggered while loading model.
---> System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at Tensorflow.c_api.TF_GraphImportGraphDef(IntPtr graph, SafeBufferHandle graph_def, SafeImportGraphDefOptionsHandle options, SafeStatusHandle status)
at Tensorflow.Graph.Import(Byte[] bytes, String prefix)
at Microsoft.ML.TensorFlow.TensorFlowUtils.LoadTFSession(IExceptionContext ectx, Byte[] modelBytes, String modelFile)
--- End of inner exception stack trace ---
at Microsoft.ML.TensorFlow.TensorFlowUtils.LoadTFSession(IExceptionContext ectx, Byte[] modelBytes, String modelFile)
at Microsoft.ML.Vision.ImageClassificationModelParameters..ctor(IHostEnvironment env, ModelLoadContext ctx)
at Microsoft.ML.Vision.ImageClassificationModelParameters.Create(IHostEnvironment env, ModelLoadContext ctx)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs) --- End of inner exception stack trace --- at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs) at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes](IHostEnvironment env, Type signatureType, TRes& result, String name, String options, Object[] extra) at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes,TSig](IHostEnvironment env, TRes& result, String name, String options, Object[] extra) at Microsoft.ML.ModelLoadContext.TryLoadModelCore[TRes,TSig](IHostEnvironment env, TRes& result, Object[] extra) at Microsoft.ML.ModelLoadContext.TryLoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, String name, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, String name, Object[] extra) at Microsoft.ML.Data.MulticlassPredictionTransformer.Create(IHostEnvironment env, ModelLoadContext ctx) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs)
--- End of inner exception stack trace ---
at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs)
at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes](IHostEnvironment env, Type signatureType, TRes& result, String name, String options, Object[] extra)
at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes,TSig](IHostEnvironment env, TRes& result, String name, String options, Object[] extra)
at Microsoft.ML.ModelLoadContext.TryLoadModelCore[TRes,TSig](IHostEnvironment env, TRes& result, Object[] extra)
at Microsoft.ML.ModelLoadContext.TryLoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, String name, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, String name, Object[] extra)
at Microsoft.ML.Data.TransformerChain1..ctor(IHostEnvironment env, ModelLoadContext ctx) at Microsoft.ML.Data.TransformerChain.Create(IHostEnvironment env, ModelLoadContext ctx) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs)
After running this by @luisquintanilla, nothing immediately stands out to us about why your source code might be causing this error. Can you tell us a little bit more about the model you are inputting? How did you train it?
This issue has been marked needs-author-action and may be missing some important information.
After running this by @luisquintanilla, nothing immediately stands out to us about why your source code might be causing this error. Can you tell us a little bit more about the model you are inputting? How did you train it?
Training Code var context = new MLContext(seed: 0); var input = LoadLabeledImagesFromPath(imageFolderPath); var data = context.Data.LoadFromEnumerable(input); data = context.Data.ShuffleRows(data);
var images = context.Transforms.Conversion.MapValueToKey(inputColumnName: nameof(Input.Label), outputColumnName: _keyColumnName).Append(context.Transforms.LoadRawImageBytes(inputColumnName: nameof(Input.ImagePath), outputColumnName: nameof(Input.Image), imageFolder: _imagePath)) .Fit(data).Transform(data);
var trainTestData = context.Data.TrainTestSplit(images, testFraction: 0.2, seed: 1); var trainData = trainTestData.TrainSet; var testData = trainTestData.TestSet;
// Create an image-classification pipeline and train the model
var options = new ImageClassificationTrainer.Options() { FeatureColumnName = nameof(Input.Image), LabelColumnName = _keyColumnName, ValidationSet = testData, Arch = ImageClassificationTrainer.Architecture.ResnetV2101, // Pretrained DNN MetricsCallback = (metrics) => Console.WriteLine(metrics), TestOnTrainSet = false };
var pipeline = context.MulticlassClassification.Trainers.ImageClassification(options) .Append(context.Transforms.Conversion.MapKeyToValue(_predictedLabelColumnName));
var model = pipeline.Fit(trainData);
var predictions = model.Transform(testData); var metrics = context.MulticlassClassification.Evaluate(predictions, labelColumnName: _keyColumnName, predictedLabelColumnName: _predictedLabelColumnName); context.Model.Save(model, trainData.Schema, somePath);