dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.05k stars 1.89k forks source link

Error load Model (Generated from 64 bit ) From 32 bit #2283

Closed DevLob-zz closed 5 years ago

DevLob-zz commented 5 years ago

System information

Issue

Please paste or attach the code or logs or traces that would be helpful to diagnose the issue you are reporting.

Generating model from 64 bit process

` public void BuildNormalTrainEvaluateAndSaveModel() { //Set a random seed for repeatable/deterministic results across multiple trainings. var mlContext = new MLContext(seed: 1);

        #region "STEP 1: Common data loading configuration"
        IDataView trainingDataView = GetNormalDataSet(mlContext);
        #endregion
        #region "STEP 2: Common data process configuration with pipeline data transformations"
        var dataProcessPipeline1 = mlContext.Transforms.Text.FeaturizeText(new List<string> { "tagText", "firstWord", "fontColor" }, "Features");

        var dataProcessPipeline = mlContext.Transforms.Concatenate("Features", "fontSize",
                                                                                   "isBold",
                                                                                   "isItalic",
                                                                                   "isUnderLine",
                                                                                   "containsDot",
                                                                                   "containsQuestionMark",
                                                                                   "isAllCaps"
                                                                                    );
        //var dataProcessPipeline2 = mlContext.Transforms.Text.FeaturizeText(new List<string> { "Label" }, "Features");
        dataProcessPipeline.Append(dataProcessPipeline1);
        //mlContext.Transforms.CustomMapping()
        #endregion
        #region  "STEP 3: Set the training algorithm, then create and config the modelBuilder"                            
        var modelBuilder = new ModelBuilder<NormalTagsModelFeatures, NormalTagsPrediction>(mlContext, dataProcessPipeline);
        // We apply our selected Trainer 
        //modelBuilder.AddEstimator(dataProcessPipeline1);
        //modelBuilder.AddEstimator(new Dictionarizer("Label"));
        //modelBuilder.AddEstimator(dataProcessPipeline2);

        var pipeline = mlContext.Transforms.Conversion.MapValueToKey("Label")
            .Append(dataProcessPipeline1)
            .Append(mlContext.MulticlassClassification.Trainers.StochasticDualCoordinateAscent(labelColumn: "Label", featureColumn: "Features"))
            .Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

        //var trainer = mlContext.MulticlassClassification.Trainers.StochasticDualCoordinateAscent(labelColumn: "Label", featureColumn: "Features");
        //modelBuilder.AddTrainer(trainer);
        modelBuilder.AddTrainer(pipeline);
        #endregion
        #region "STEP 4: Train the model fitting to the DataSet"
        //The pipeline is trained on the dataset that has been loaded and transformed.
        //Console.WriteLine("=============== Training the model ===============");

        modelBuilder.Train(trainingDataView);
        #endregion
        #region "STEP 5: Evaluate the model and show accuracy stats"
        //Console.WriteLine("===== Evaluating Model's accuracy with Test data =====");
        //var metrics = modelBuilder.EvaluateMultiClassClassificationModel(trainingDataView, "Label");
        //Common.ConsoleHelper.PrintMultiClassClassificationMetrics(trainer.ToString(), metrics);
        #endregion
        #region "STEP 6: Save/persist the trained model to a .ZIP file
        //Console.WriteLine("=============== Saving the model to a file ===============");
        string fullFilePath = GetModelPath("Norm");

Norm_131931638095612677_544677f3-3124-4979-aae8-0a6142ab4c67.Zip

        modelBuilder.SaveModelAsFile(fullFilePath);
        #endregion
    }

`

Load Model From 32 bit proccess

public void LoadNormalTagsModel(string modelPath)
        {
            var mlContext = new MLContext(seed: 0);
            ITransformer trainedModel;
//Here is the Exception line
            using (var stream = new FileStream(modelPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                trainedModel = mlContext.Model.Load(stream);
            }
            var predEngine = trainedModel.CreatePredictionEngine<NormalTagsModelFeatures, NormalTagsPrediction>(mlContext);

        }

i attached the generated model ,

how can i overcome this scenario please advice

History 👍 https://github.com/dotnet/machinelearning-samples/issues/216

DevLob-zz commented 5 years ago

Norm_131931638095612677_544677f3-3124-4979-aae8-0a6142ab4c67.Zip

Ivanidzo4ka commented 5 years ago

ConsoleApp12.zip

Here is my solution with x86 platform project. It works fine with current latest stable nuget (0.9) image

eerhardt commented 5 years ago

@DevLob-zz - what version of Microsoft.ML nuget package are you using?

DevLob-zz commented 5 years ago

@DevLob-zz - what version of Microsoft.ML nuget package are you using?

i tested it on 0.8 and then migrate my code to 0.9 and same error type

DevLob-zz commented 5 years ago

Yes thanks l cleaned some dll's then rebuild and issue was solved may be as i installed 0.9 the unistall and reinstall 0.8 then again reinstall 0.8

thanks

DevLob-zz commented 5 years ago

i think it's worked now

may be the issue due to conflict of some dll between 0.8 and 0.9 i cleaned all dll's and rebuild again and seem to be worked thanks