public abstract Input ( Floatarray v, int i ) : void | ||
v | Floatarray | |
i | int | |
return | void |
public override void Input(Floatarray v, int i) { _ds.Input(v, _samples[i]); }
public override void Input(Floatarray v, int i) { _ds.Input(v, i); }
public virtual TrainInfo TrainBatch(IDataset ds, IDataset ts, int epochs) { TrainInfo trInfo = new TrainInfo(); bool first = true; Floatarray v = new Floatarray(); // Send Train Dataset to Lenet for (int i = 0; i < ds.nSamples(); i++) { ds.Input(v, i); if (v.Rank() == 1) v.Reshape(csize, csize, 0, 0); StdInput linput = new StdInput(v); try { if (first) { first = false; //StartRedirectStdout(); // start redirect cout to string buffer BeginTrainEpoch(HrLenet, linput.Height, linput.Width, ds.nSamples(), ts.nSamples()); // init train } if (C2i.ContainsKey(ds.Cls(i))) AddSampleToTrainOfEpoch(HrLenet, linput.GetDataBuffer(), linput.Length, C2i[ds.Cls(i)]); else Global.Debugf("error", "class '{0}' is not contained in the char list", (char)ds.Cls(i)); } catch (Exception e) { GetStdout(sbout); // get train messages if (sbout.Length > 0) Global.Debugf("error", sbout.ToString() + "\r\nException in AddSampleToTrainOfEpoch"); throw new Exception("Exception in AddSampleToTrainOfEpoch\r\n" + e.Message); } } // Send Test Dataset to Lenet for (int i = 0; i < ts.nSamples(); i++) { ts.Input(v, i); if (v.Rank() == 1) v.Reshape(csize, csize, 0, 0); StdInput linput = new StdInput(v); try { if (C2i.ContainsKey(ts.Cls(i))) AddSampleToTestOfEpoch(HrLenet, linput.GetDataBuffer(), linput.Length, C2i[ts.Cls(i)]); } catch (Exception e) { GetStdout(sbout); // get train messages if (sbout.Length > 0) Global.Debugf("error", sbout.ToString() + "\r\nException in AddSampleToTestOfEpoch"); throw new Exception("Exception in AddSampleToTestOfEpoch\r\n" + e.Message); } } // debug save mnist //SaveTrainMnist(HrLenet, "debug-images-idx3-ubyte", "debug-labels-idx1-ubyte"); // do train epochs for (int epoch = 0; epoch < epochs; epoch++) { trInfo = new TrainInfo(); try { DateTime startDate = DateTime.Now; EndAndRunTrainEpoch(HrLenet, ref trInfo); // do train one epoch // show train info Global.Debugf("info", String.Format("|{0,7}| Energy:{1:0.#####} Correct:{2:0.00#%} Errors:{3:0.00#%} Count:{4} ", trInfo.age, trInfo.energy, (trInfo.correct / (float)trInfo.size), (trInfo.error / (float)trInfo.size), trInfo.size) ); Global.Debugf("info", String.Format(" TEST Energy={0:0.#####} Correct={1:0.00#%} Errors={2:0.00#%} Count={3} ", trInfo.tenergy, (trInfo.tcorrect / (float)trInfo.tsize), (trInfo.terror / (float)trInfo.tsize), trInfo.tsize)); TimeSpan spanTrain = DateTime.Now - startDate; Global.Debugf("info", String.Format(" training time: {0} minutes, {1} seconds", (int)spanTrain.TotalMinutes, spanTrain.Seconds)); // get dll stdout messages GetStdout(sbout); if (sbout.Length > 0) Console.Write(sbout.ToString()); } catch (Exception e) { GetStdout(sbout); // get train messages if (sbout.Length > 0) Global.Debugf("error", sbout.ToString() + "\r\nException in EndAndRunTrainEpoch"); throw new Exception("Exception in EndAndRunTrainEpoch\r\n" + e.Message); } } return trInfo; }
protected virtual void Train(IDataset ds) { Floatarray v = new Floatarray(); for (int i = 0; i < ds.nSamples(); i++) { ds.Input(v, i); Add(v, ds.Cls(i)); } }
public TrainInfo TestDense(IDataset ts) { TrainInfo trInfo = new TrainInfo(); bool first = true; Floatarray v = new Floatarray(); // Send Test Dataset to Lenet for (int i = 0; i < ts.nSamples(); i++) { ts.Input(v, i); if (v.Rank() == 1) v.Reshape(csize, csize, 0, 0); StdInput linput = new StdInput(v); if (first) { first = false; BeginTestEpoch(HrLenet, linput.Height, linput.Width, ts.nSamples()); // init test } try { if (C2i.ContainsKey(ts.Cls(i))) AddSampleToTestOfEpoch(HrLenet, linput.GetDataBuffer(), linput.Length, C2i[ts.Cls(i)]); } catch (Exception e) { GetStdout(sbout); // get train messages if (sbout.Length > 0) Global.Debugf("error", sbout.ToString() + "\r\nException in AddSampleToTestOfEpoch"); throw new Exception("Exception in AddSampleToTestOfEpoch\r\n" + e.Message); } } // do test one epoch try { EndAndRunTestEpoch(HrLenet, ref trInfo); } catch (Exception e) { GetStdout(sbout); // get test messages if (sbout.Length > 0) Global.Debugf("error", sbout.ToString() + "\r\nException in EndAndRunTestEpoch"); throw new Exception("Exception in EndAndRunTestEpoch\r\n" + e.Message); } return trInfo; }