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 virtual Trainer Configure <T>(Model model, int?epochs, fDataSet dataSet, double?learningRate, double?momentum) where T : CNN.Loss, new() { base.Configure(model, epochs, dataSet); // 0. assert learningRate and momentum if ((learningRate == null) || (momentum == null)) { throw new Exception(); } this.learningRate = learningRate; this.momentum = momentum; this.lossfunc = new T(); return(this); }
partial void test_ai_uByteLoaderToolStripMenuItem_Click(object sender, EventArgs e) { //string dataFileName = @"C:\Users\ogban\Documents\mnist\train-images.idx3-ubyte"; //string labelFileName = @"C:\Users\ogban\Documents\mnist\train-labels.idx1-ubyte"; //string log = ""; //IList<fData> dataList = AI.Core.UByteLoader.ReadGrayImage(dataFileName, null, -2.0, 2.0, labelFileName, -1.0, 1.0); //fDataSet dataSet = new fDataSet(); //dataSet.fData = dataList; //Random random = new Random(); //int rand = 0; //for (int i=0; i<20; i++) //{ // rand = random.Next(0, 60000); // log += dataList[rand].ToImageString(); // log += dataList[rand].DecodeLabel.ToString(); //} string dataFileName = @"C:\Users\ogban\Documents\mnist\cifar\cifar-10-batches-bin\data_batch_1.bin"; string[] classes = new string[] { "airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck" }; string log = ""; IList <fData> dataList = AI.Core.UByteLoader.ReadColorImage(dataFileName, 1, -2.0, 2.0, -1.0, 1.0); fDataSet dataSet = new fDataSet(); dataSet.fData = dataList; int size = (int)System.Math.Sqrt(dataSet.fData[0].Pixel.Length / 3); int[] pixel = null; pixel = dataSet.fData[0].Pixel; log += classes[dataSet.fData[0].DecodeLabel]; Mat matImg = new Mat(size, size, DepthType.Cv8U, 3); Image <Bgr, Byte> img = matImg.ToImage <Bgr, Byte>(); Image <Bgr, Byte> image = setColorPixels(img, size, pixel); int[] input_size = new int[] { 256, 256 }; int[] resizedPixel = Resize_Color(image, input_size); //Random random = new Random(); //int rand = 0; //for (int i = 0; i < 20; i++) //{ // rand = random.Next(0, 60000); // log += dataList[rand].ToImageString(); // log += dataList[rand].DecodeLabel.ToString(); //} richTextBox.Text = log; }