Skip to content

System.MissingMethodException: 'Method not found: 'Tensorflow.Tensor Tensorflow.tensorflow.truncated_normal' #4678

@Sinfulelf

Description

@Sinfulelf

System information

  • OS version/distro:
    Window 10 build-17134
  • .NET Version (eg., dotnet --info):
    NetCore 3.1

Issue

Method not found: 'Tensorflow.Tensor Tensorflow.tensorflow.truncated_normal(Int32[], Single, Single, Tensorflow.TF_DataType, System.Nullable`1, System.String)'.

        static void Main(string[] args)
        {
            var workspaceRelativePath = @"C:\Test_dev\ML_Main_Test\workspace";
            var assetsRelativePath = @"C:\Test_dev\ML_Main_Test\assets";

            MLContext mlContext = new MLContext();

            IEnumerable<ImageData> images = LoadImagesFromDirectory(folder: assetsRelativePath, useFolderNameAsLabel: true);

            var test = images.First();

            IDataView imageData = mlContext.Data.LoadFromEnumerable(images);

            IDataView shuffledData = mlContext.Data.ShuffleRows(imageData);

            var preprocessingPipeline = mlContext.Transforms.Conversion.MapValueToKey(
                                    inputColumnName: "Label",
                                    outputColumnName: "LabelAsKey")
                                .Append(mlContext.Transforms.LoadRawImageBytes(
                                    outputColumnName: "Image",
                                    imageFolder: assetsRelativePath,
                                    inputColumnName: "ImagePath"));

            IDataView preProcessedData = preprocessingPipeline.Fit(shuffledData)
                                            .Transform(shuffledData);

            TrainTestData trainSplit = mlContext.Data.TrainTestSplit(data: preProcessedData, testFraction: 0.2);
            TrainTestData validationTestSplit = mlContext.Data.TrainTestSplit(trainSplit.TestSet);

            IDataView trainSet = trainSplit.TrainSet;
            IDataView validationSet = validationTestSplit.TrainSet;
            IDataView testSet = validationTestSplit.TestSet;

            var classifierOptions = new ImageClassificationTrainer.Options()
            {
                FeatureColumnName = "Image",
                LabelColumnName = "LabelAsKey",
                ValidationSet = validationSet,
                Arch = ImageClassificationTrainer.Architecture.ResnetV2101,
                MetricsCallback = Console.WriteLine,
                TestOnTrainSet = false,
                ReuseTrainSetBottleneckCachedValues = true,
                ReuseValidationSetBottleneckCachedValues = true,
                WorkspacePath = workspaceRelativePath
            };
            var trainingPipeline = mlContext.MulticlassClassification.Trainers.ImageClassification(classifierOptions)
                                    .Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

            ITransformer trainedModel = trainingPipeline.Fit(trainSet);

            mlContext.Model.Save(trainedModel, preProcessedData.Schema, "model.zip");

            ClassifySingleImage(mlContext, testSet, trainedModel);
        }

Metadata

Metadata

Assignees

Labels

P0Priority of the issue for triage purpose: IMPORTANT, needs to be fixed right away.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions