private void DoCompletion(object sender, DoWorkEventArgs e)
        {
            ShapeModelInference inference = new ShapeModelInference();
            inference.SetBeliefs(this.shapeModel);
            inference.MaskCompletionIterationCount = 300;
            inference.IterationsBetweenCallbacks = 5;
            inference.MaskCompletionProgress += OnMaskCompletionProgressChange;

            Mask completedMask = inference.CompleteMasks(new[] { this.maskToComplete }, new[] { (bool[,])e.Argument })[0];
            e.Result = GetCertainCompletedMask(completedMask);
        }
Exemple #2
0
        private static void Main()
        {
            Rand.Restart(666);

            //AngleScaleTest();
            //return;

            const int shapePartCount = 8;
            const int traitCount = 5;
            const double observationNoiseProb = 0.01;
            const int trainingSetSize = 30;
            const int imageRepeatCount = 1;
            const string modelNamePrefx = "horses";
            //const string trainTestImagePath = "../../../Data/Caltech101/AnnotationsConverted/Motorbikes_16";
            //const string trainTestImagePath = "../../../Data/horses/scale_invariance";
            const string trainTestImagePath = "../../../Data/horses/clean";

            bool[][,] trainingLabels = ImageHelpers.LoadImagesAsSameSizeMasks(trainTestImagePath, trainingSetSize, trainingSetSize, 0);
            trainingLabels = RepeatImages(trainingLabels, imageRepeatCount);

            // Save training set
            for (int i = 0; i < trainingLabels.Length; ++i)
            {
                ImageHelpers.ArrayToBitmap(trainingLabels[i], b => b ? Color.Red : Color.Green).Save(string.Format("training_labels_{0}.png", i));
            }

            ShapeModelInference inference = new ShapeModelInference();
            inference.TrainingIterationCount = 10000;
            inference.IterationsBetweenCallbacks = 1;

            inference.SetPriorBeliefs(trainingLabels[0].GetLength(0), trainingLabels[0].GetLength(1), traitCount, shapePartCount, observationNoiseProb);
            inference.ShapeModelLearningProgress += OnShapeModelLearningProgress;
            ShapeModel model = inference.LearnModel(trainingLabels).Item1;

            model.Save(string.Format("./{0}_{1}_traits_{2}_images_{3}_parts.bin", modelNamePrefx, traitCount, trainingSetSize, shapePartCount));
        }
        private void DoFitting(object sender, DoWorkEventArgs e)
        {
            ShapeModelInference inference = new ShapeModelInference();
            inference.SetBeliefs(this.shapeModel);
            inference.TrainingIterationCount = 1000;
            inference.IterationsBetweenCallbacks = 5;
            inference.ShapeModelLearningProgress += OnShapeFittingProgressChange;

            e.Result = inference.LearnModel(new[] { this.maskToComplete }, false);
        }