public void DoPredict() { int batch_size = 16; Context ctx = new Context(DeviceType.KCpu, 0); Optimizer optimizer = new CcSgd(momentum: 0.9f, learningRate: 0.001f, wd: 0.00001f, rescaleGrad: 1.0f / batch_size); var modelload = FeedForward.Load("checkpoint\\tag", ctx: ctx, numEpoch: 1, optimizer: optimizer, initializer: new Xavier(factorType: FactorType.In, magnitude: 2.34f)); }
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)); var model = FeedForward.Load("checkpoint\\cnn"); ReadData rdpredict = new ReadData("data\\train\\", 32, true); var testOut = model.Predict(rdpredict, 1); TrainTest(); }
private static void TrainTest() { int batch_size = 32; var pnet = get_ocrnet(batch_size); //var modelloadtest = FeedForward.Load("checkpoint\\cnn"); ReadData rdtrain = new ReadData("data\\train\\", batch_size); ReadData rdval = new ReadData("data\\val\\", batch_size); Context ctx = new Context(DeviceType.KGpu, 0); 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.01f, wd: 0.00001f, rescaleGrad: 1.0f / batch_size); FeedForward model = null; try { var modelload = FeedForward.Load("checkpoint\\cnn", ctx: ctx, numEpoch: 1, optimizer: optimizer, initializer: new Xavier(factorType: FactorType.In, magnitude: 2.34f)); model = new FeedForward(pnet, new List <Context> { ctx }, numEpoch: 1000, optimizer: optimizer, initializer: new Xavier(factorType: FactorType.In, magnitude: 2.34f), argParams: modelload.ArgParams, auxParams: modelload.AuxParams ); } catch (Exception) { // ignored } if (model == null) { 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(""); }