public bool Save(MnistDataLabelReader lr, MnistDataImageReader ir, string filePath) { try { FileStream fs = new FileStream(filePath, FileMode.Create); StreamWriter sw = new StreamWriter(fs); for (var i = 0; i < lr.ItemCount; ++i) { string line = lr.Items[i].ToString() + " "; for (var j = 0; j < ir.Items[i].Length; ++j) { line += j.ToString() + ":" + ir.Items[i][j].ToString() + " "; } sw.WriteLine(line); } sw.Flush(); sw.Close(); fs.Close(); } catch (Exception) { return(false); } return(true); }
private static void TransData(string prefix) { MnistDataLabelReader lr = new MnistDataLabelReader(); bool b1 = lr.ParseData(MnistDataPath + prefix + "-labels.idx1-ubyte"); MnistDataImageReader ir = new MnistDataImageReader(); bool b2 = ir.ParseData(MnistDataPath + prefix + "-images.idx3-ubyte"); if (b1 && b2 && lr.ItemCount == ir.ItemCount) { MnistDataWriter dw = new MnistDataWriter(); dw.Save(lr, ir, MnistDataPath + prefix + ".txt"); } }