-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
102 lines (94 loc) · 4.16 KB
/
Program.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
internal class Program
{
public static void Main()
{
//Creates a list to store networks and their names
List<NeuralNetwork> networks = new List<NeuralNetwork>();
List<string> networkNames = new List<string>();
//TODO: Change to prompt user for file paths
string labelsFilePath = "/home/catten/Desktop/MNIST_Train_Database/train-labels.idx1-ubyte";
string imagesFilePath = "/home/catten/Desktop/MNIST_Train_Database/train-images.idx3-ubyte";
string filePathToStoreIn = "/home/catten/Desktop/network.txt";
byte[] labels = MNISTFileHandler.GetLabels(labelsFilePath);
byte[,,] images = MNISTFileHandler.GetImages(imagesFilePath);
NeuralNetwork? nullableNetwork;
NeuralNetwork network;
Console.Clear();
Commands.ShowCommands();
while(true)
{
string command = Prompts.PromptUntilConditionMet("\nEnter: ", "\nNot a command, enter again: ", Checks.IsOption, "");
switch(command)
{
case "show":
Commands.ShowNetworks(networks);
break;
case "train":
nullableNetwork = GetNetwork(networks, networkNames, "Enter a network to train: ");
if(nullableNetwork == null) continue;
network = nullableNetwork;
Commands.Train(network, labels, images);
break;
case "test":
nullableNetwork = GetNetwork(networks, networkNames, "Enter a network to test: ");
if(nullableNetwork == null) continue;
network = nullableNetwork;
Commands.Test(network, labels, images);
break;
case "error":
nullableNetwork = GetNetwork(networks, networkNames, "Enter a network to get the error of: ");
if(nullableNetwork == null) continue;
network = nullableNetwork;
Commands.PrintError(network, labels, images);
break;
case "store":
nullableNetwork = GetNetwork(networks, networkNames, "Enter a network to store: ");
if(nullableNetwork == null) continue;
network = nullableNetwork;
Commands.Store(network, filePathToStoreIn);
break;
case "make":
Commands.Make(networks, networkNames);
break;
case "delete":
nullableNetwork = GetNetwork(networks, networkNames, "Enter a network you want to delete: ");
if(nullableNetwork == null) continue;
network = nullableNetwork;
Commands.Delete(networks, networkNames, network);
break;
case "peek":
nullableNetwork = GetNetwork(networks, networkNames, "Enter a network you want to peek into: ");
if(nullableNetwork == null) continue;
network = nullableNetwork;
Commands.Peek(network);
break;
case "clear":
Console.Clear();
break;
case "help":
Commands.ShowCommands();
break;
}
}
}
public static NeuralNetwork? GetNetwork(List<NeuralNetwork> networks, List<string> networkNames, string startingMessage)
{
if(networks.Count == 0)
{
Console.WriteLine("Network list empty");
return null;
}
//Get the name of the network
string name = Prompts.PromptUntilConditionMet(startingMessage, "Network wasn't in the saved networks list\nEnter again: ", Checks.NetworkListContainsName, "", networkNames);
if(name == "exit") return null;
//Find the network in the list and return it
for(int i = 0; i < networks.Count; i++)
{
if(networks[i].name == name)
{
return networks[i];
}
}
return null;
}
}