コード例 #1
0
 private void OnShapeFittingProgressChange(object sender, ShapeModelLearningProgressEventArgs e)
 {
     ShapeModelInference inferenceEngine = (ShapeModelInference)sender;
     double progress = 100.0 * e.IterationsCompleted / inferenceEngine.MaskCompletionIterationCount;
     this.Dispatcher.Invoke(
         () =>
         {
             this.completionProgressBar.Value = progress;
             this.completedMaskViewer.Source = WpfImageHelpers.BitmapToBitmapSource(GetFittingMask(e.ShapeModel, e.FittingInfo));
         });
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: hr0nix/BayesianShapePrior
        static void OnShapeModelLearningProgress(object sender, ShapeModelLearningProgressEventArgs e)
        {
            e.ShapeModel.Save(string.Format("model_progress_{0}.bin", e.IterationsCompleted));

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("After iteration {0}:", e.IterationsCompleted);
            Console.WriteLine();
            Console.ResetColor();

            for (int i = 0; i < e.FittingInfo.ShapeTraits.Count; ++i)
            {
                Console.Write("Trait means {0}:", i);
                for (int j = 0; j < e.FittingInfo.ShapeTraits[i].Count; ++j)
                {
                    Console.Write("  {0:0.000} (var={1:0.000})", e.FittingInfo.ShapeTraits[i][j].GetMean(), e.FittingInfo.ShapeTraits[i][j].GetVariance());
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            Console.WriteLine("Scale trait weights:");
            for (int i = 0; i < e.ShapeModel.ShapePartCount; ++i)
            {
                Console.WriteLine("Shape part {0}", i);

                Console.Write("X:");
                for (int j = 0; j < e.ShapeModel.TraitCount; ++j)
                {
                    Console.Write("  {0:0.0000} (std={1:0.0000})", e.ShapeModel.ShapePartLogScaleWeights[i][0][j].GetMean(), Math.Sqrt(e.ShapeModel.ShapePartLogScaleWeights[i][0][j].GetVariance()));
                }
                Console.WriteLine();

                Console.Write("Y:");
                for (int j = 0; j < e.ShapeModel.TraitCount; ++j)
                {
                    Console.Write("  {0:0.0000} (std={1:0.0000})", e.ShapeModel.ShapePartLogScaleWeights[i][1][j].GetMean(), Math.Sqrt(e.ShapeModel.ShapePartLogScaleWeights[i][1][j].GetVariance()));
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            Console.WriteLine("Angle trait weights:");
            for (int i = 0; i < e.ShapeModel.ShapePartCount; ++i)
            {
                Console.Write("Shape part {0}:", i);
                for (int j = 0; j < e.ShapeModel.TraitCount; ++j)
                {
                    Console.Write("  {0:0.0000} (std={1:0.0000})", e.ShapeModel.ShapePartAngleWeights[i][j].GetMean(), Math.Sqrt(e.ShapeModel.ShapePartAngleWeights[i][j].GetVariance()));
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            Console.WriteLine("Global log-scales: ");
            for (int i = 0; i < e.FittingInfo.GlobalLogScales.Count; ++i)
            {
                Console.WriteLine("Image {0}: {1:0.0000} (std={2:0.0000})", i, e.FittingInfo.GlobalLogScales[i].GetMean(), Math.Sqrt(e.FittingInfo.GlobalLogScales[i].GetVariance()));
            }
            Console.WriteLine();

            for (int imageIndex = 0; imageIndex < e.FittingInfo.ShapePartLocations.Count; ++imageIndex)
            {
                string fileName = string.Format("shape_{0:000}_{1:00}.png", e.IterationsCompleted, imageIndex);
                Vector[] meanLocations = Util.ArrayInit(e.FittingInfo.ShapePartLocations[imageIndex].Count, i => Vector.FromArray(Util.ArrayInit(2, j => e.FittingInfo.ShapePartLocations[imageIndex][i][j].GetMean())));
                PositiveDefiniteMatrix[] meanOrientations = Util.ArrayInit(e.FittingInfo.ShapePartOrientations[imageIndex].Count, j => e.FittingInfo.ShapePartOrientations[imageIndex][j].GetMean());
                ImageHelpers.DrawShape(e.ShapeModel.GridWidth, e.ShapeModel.GridHeight, meanLocations, meanOrientations).Save(fileName);

                string sampleFileName = string.Format("shape_{0:000}_{1:00}_sample.png", e.IterationsCompleted, imageIndex);
                double[] meanTraits = Util.ArrayInit(e.ShapeModel.TraitCount, i => e.FittingInfo.ShapeTraits[imageIndex][i].GetMean());
                ShapeModelSample sample = e.ShapeModel.Sample(new[] { meanTraits }, false, true)[0];
                ImageHelpers.DrawShape(e.ShapeModel.GridWidth, e.ShapeModel.GridHeight, sample.ShapePartLocations, sample.ShapePartOrientations).Save(sampleFileName);
            }

            //ShapeModelSample[] samples = e.ShapeModel.Sample(10, false, false, true);
            //for (int sampleIndex = 0; sampleIndex < samples.Length; ++sampleIndex)
            //{
            //    string sampleFileName = string.Format("labels_centered_sample_{0:000}_{1:00}.png", e.IterationsCompleted, sampleIndex);
            //    ImageHelpers.ArrayToBitmap(samples[sampleIndex].Labels, l => l ? Color.Red : Color.Green).Save(sampleFileName);
            //}
        }