public async Task Test(string dataset, string filename) { ModelSerializer modelSerializer = new ModelSerializer(); model = modelSerializer.DeserializeCNN(filename); fDataSet testdataset = new fDataSet(); testdataset.Deserializer(dataset); int index = random.Next(0, testdataset.fData.Count); AI.Core.fDataSet dataSet = new AI.Core.fDataSet(); dataSet.fData = testdataset.fData; pixel = testdataset.fData[index].Pixel; label = testdataset.fData[index].DecodeLabel; //model.predict probs = model.Predict(dataSet.fData[index]); AI.ML.CNN.Trainers.ADAM adam = new AI.ML.CNN.Trainers.ADAM(); softmaxOutput = adam.Softmax(probs); double maxValue = softmaxOutput.Max(); predict = softmaxOutput.ToList().IndexOf(maxValue); //int lindex = random.Next(0, 5); //predict = lindex == 2 ? random.Next(0, 9) : label; result[0] = label; result[1] = predict; await Clients.All.SendAsync("ReceiveMessage", pixel); await Clients.All.SendAsync("ReceiveLabel", result); }
public async Task ConfigureModel(string configstring, string algorithm, string dataset, string filename) { await Clients.All.SendAsync("ReceiveMessage", "Configuring model..."); model = new AI.ML.CNN.Model(); model.Configure(configstring); await Clients.All.SendAsync("ReceiveMessage", "Initializing dataset..."); switch (dataset) { case "MNIST": case "mnist": dataFileName = @"C:\files\data\mnist\train-images.idx3-ubyte"; labelFileName = @"C:\files\data\mnist\train-labels.idx1-ubyte"; dataList = (List <AI.Core.fData>)AI.Core.UByteLoader.ReadGrayImage(dataFileName, 1, 0.0, 1.0, labelFileName, 0.0, 1.0); dataSet = new AI.Core.fDataSet(); dataSet.fData = dataList; await Clients.All.SendAsync("SetCookie", dataset, "dataset"); break; case "CIFAR": case "cifar": dataFileName = @"C:\files\data\cifar\cifar-10-batches-bin\data_batch_1.bin"; dataList = (List <AI.Core.fData>)AI.Core.UByteLoader.ReadColorImage(dataFileName, 1, 0.0, 1.0, 0.0, 1.0); dataSet = new AI.Core.fDataSet(); dataSet.fData = dataList; await Clients.All.SendAsync("SetCookie", dataset, "dataset"); break; default: dataSet = new AI.Core.fDataSet(); dataSet.Deserializer(dataset); await Clients.All.SendAsync("SetCookie", dataset, "dataset"); break; } await Clients.All.SendAsync("ReceiveMessage", "Initializing training..."); //parse trainer string AI.ML.CNN.Trainers.DeltaRule deltaRule = new AI.ML.CNN.Trainers.DeltaRule(); deltaRule.Configure <AI.ML.CNN.Lossfunc.CategoricalCrossEntropy>(model, epochs, dataSet, learningRate, momentum); await Clients.All.SendAsync("ReceiveMessage", deltaRule.NextVerbose()); filename = @"C:\files\model\" + filename; AI.Core.ModelSerializer modelSerializer = new AI.Core.ModelSerializer(); path = modelSerializer.Serialize(configstring, model, filename); await Clients.All.SendAsync("SetCookie", path, "model"); await Clients.All.SendAsync("ReceiveMessage", "done"); }