static void Main(string[] args) { NumericsTest test = new NumericsTest(); test.Test(); var log4_net_config = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "log4net.config"); XmlConfigurator.Configure(new FileInfo(log4_net_config)); int batch_size = 32; uint w = 60; uint h = 20; float learning_rate = 1e-4f; float weight_decay = 1e-4f; ReadData rdtrain = new ReadData("data\\train\\", batch_size); ReadData rdval = new ReadData("data\\val\\", batch_size); //var first = rdtrain.First(); Context ctx = new Context(DeviceType.KGpu, 0); //NDArray dataArray = new NDArray(new Shape((uint)batchSize, 3, W, H), ctx, false); //NDArray labelArray = new NDArray(new Shape((uint)batchSize,4), ctx, false); //Symbol data1 = Symbol.Variable("data1"); //Symbol data2 = Symbol.Variable("data2"); var pnet = get_ocrnet(batch_size); Speedometer speed = new Speedometer(batch_size, 50); CustomMetric custom_metric = new CustomMetric((l, p) => Accuracy(l, p, batch_size)); Optimizer optimizer = new CcSgd(momentum: 0.9f, learning_rate: 0.001f, wd: 0.00001f, rescale_grad: 1.0f / batch_size); FeedForward model = new FeedForward(pnet, new List <Context> { ctx }, num_epoch: 10, optimizer: optimizer, initializer: new Xavier(factor_type: FactorType.In, magnitude: 2.34f) ); model.Fit(rdtrain, rdval, custom_metric, batch_end_callback: new List <Action <mxnet.csharp.util.BatchEndParam> > { speed.Call }); Console.WriteLine(""); }
private static void TrainTest() { int batch_size = 32; ReadData rdtrain = new ReadData("data\\train\\", batch_size); ReadData rdval = new ReadData("data\\val\\", batch_size); Context ctx = new Context(DeviceType.KGpu, 0); var pnet = get_ocrnet(batch_size); Speedometer speed = new Speedometer(batch_size, 50); DoCheckpoint doCheckpoint = new DoCheckpoint("checkpoint\\cnn"); CustomMetric customMetric = new CustomMetric((l, p) => Accuracy(l, p, batch_size), "Accuracy"); Optimizer optimizer = new CcSgd(momentum: 0.9f, learningRate: 0.001f, wd: 0.00001f, rescaleGrad: 1.0f / batch_size); FeedForward model = new FeedForward(pnet, new List <Context> { ctx }, numEpoch: 1, optimizer: optimizer, initializer: new Xavier(factorType: FactorType.In, magnitude: 2.34f) ); model.Fit(rdtrain, rdval, customMetric, batchEndCallback: new List <BatchEndDelegate> { speed.Call }, epochEndCallback: new List <EpochEndDelegate> { doCheckpoint.Call }); model.Save("checkpoint\\cnn"); ReadData rdpredict = new ReadData("data\\train\\", batch_size, true); var testOut = model.Predict(rdpredict, 1); Console.WriteLine(""); }