-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.cs
62 lines (55 loc) · 1.75 KB
/
Form1.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cat_DetectorML.Model;
namespace Cat_Detector
{
public partial class catDogDetector : Form
{
public catDogDetector()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void loadImageBtn_Click(object sender, EventArgs e)
{
using (OpenFileDialog pictureSelector = new OpenFileDialog())
{
pictureSelector.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
pictureSelector.ShowDialog();
imagePathTb.Text=pictureSelector.FileName;
}
pictureHolder.ImageLocation = imagePathTb.Text;
}
private void predictBtn_Click(object sender, EventArgs e)
{
try
{
var input = new ModelInput();
input.ImageSource = imagePathTb.Text;
ModelOutput result = ConsumeModel.Predict(input);
float score = (result.Score[0] > result.Score[1] ? result.Score[0] : result.Score[1]);
if (score<.8)
{
statusRtb.Text = $"Neither Cat nor Dog";
}
else
{
statusRtb.Text =$"Predicted result: {result.Prediction} with a score {score}";
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}