-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
107 lines (92 loc) · 3.27 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Interface;
using Microsoft.ML;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Media.Imaging;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public string pathImage { get; set; }
public string pathModel { get; set; }
protected MLContext mlContext;
protected DataViewSchema schema;
protected ITransformer model;
protected PredictionEngine<ModelInput, ModelOutput> engine;
public MainWindow()
{
InitializeComponent();
mlContext = new MLContext();
}
public List<string> Logic_Predict(string path)
{
ModelOutput transformation = engine.Predict(new ModelInput() { Label = "sample", ImageSource = path });
double score = transformation.Score[0] * 100;
score = Math.Round(score, 2);
List<string> result = new List<string>() { transformation.Prediction, score.ToString() };
return result;
}
private void MenuItem_Click_Image(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == true)
{
try
{
pathImage = ofd.FileName;
img1.Source = new BitmapImage(new Uri(pathImage));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void MenuItem_Click_Exit(object sender, RoutedEventArgs e)
{
this.Close();
}
private void MenuItem_Click_Info(object sender, RoutedEventArgs e)
{
InfoWindow infoWindow = new InfoWindow();
infoWindow.Show();
}
private void Button_Click_Predict(object sender, RoutedEventArgs e)
{
List<string> res = Logic_Predict(pathImage);
if (res[0] == "Parazite")
{
txtblcResult.Text = res[0];
txtblcProcent.Text = res[1] + "%";
txtblcResult.Foreground = System.Windows.Media.Brushes.Red;
}
else
{
txtblcResult.Text = "Uninfected";
txtblcProcent.Text = res[1] + "%";
txtblcResult.Foreground = System.Windows.Media.Brushes.Green;
}
}
// добавление модели
private void MenuItem_Click_AddModel(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = ".ZIP|*.zip";
if (ofd.ShowDialog() == true)
{
pathModel = ofd.FileName;
flag_Model.Background = System.Windows.Media.Brushes.Green;
MessageBox.Show("Model added.");
}
FileStream file = File.OpenRead(pathModel); // выбираем путь
model = mlContext.Model.Load(file, out schema);
engine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(model);
}
}
}