static void CNN(List <DenseVector[]> Data)//畳み込みニューラルネットワーク { //MNISTの読み込み MNistImageLoader imgLoader = MNistImageLoader.Load("train-images.idx3-ubyte"); MNistLabelLoader lLoader = MNistLabelLoader.Load("train-labels.idx1-ubyte"); //////////データ用意 Random rnd = new Random(); List <DenseVector[]> xds = new List <DenseVector[]>(); for (int i = 0; i < 10000000; i++) { xds.Add(new DenseVector[2] { new DenseVector(1), new DenseVector(1) }); double a = rnd.NextDouble(); xds[i][0][0] = a; xds[i][1][0] = 5 * a * a; } List <DenseVector[]> Tests = new List <DenseVector[]>(); for (int i = 0; i < 100; i++) { Tests.Add(new DenseVector[2] { new DenseVector(1), new DenseVector(1) }); double a = rnd.NextDouble(); Tests[i][0][0] = a; Tests[i][1][0] = a * a; } //////////データ用意終 UseNN UseCNN = new UseNN(); UseCNN.Add(new int[] { imgLoader.numberOfRows *imgLoader.numberOfColumns, 100, 100, 100, 100, 100, 100, 20, 20, 9 } , new int[] { 0, 1, 2, 1, 2, 1, 2, 0, 0, 0 }); }
static void Main(string[] args) { //MNISTの読み込み MNistImageLoader imgLoader = MNistImageLoader.Load("train-images.idx3-ubyte"); MNistLabelLoader lLoader = MNistLabelLoader.Load("train-labels.idx1-ubyte"); Console.WriteLine(imgLoader.numberOfImages); Console.WriteLine(lLoader.numberOfItems); int n = 3375; byte[] image = imgLoader.bitmapList[n]; byte label = lLoader.labelList[n]; for (int i = 0; i < imgLoader.numberOfRows; i++) { for (int j = 0; j < imgLoader.numberOfColumns; j++) { if (image[i * imgLoader.numberOfRows + j] >= 255) { Console.Write("#"); } else { Console.Write(" "); } } Console.WriteLine(); } Console.WriteLine(label); Console.ReadLine(); }
public static MNistLabelLoader Load(string path) { if (File.Exists(path) == false) { return(null); } FileStream stream = new FileStream(path, FileMode.Open); BinaryReaderBE reader = new BinaryReaderBE(stream); MNistLabelLoader loader = new MNistLabelLoader(); loader.magicNumber = reader.ReadInt32(); loader.numberOfItems = reader.ReadInt32(); loader.labelList = reader.ReadBytes(loader.numberOfItems); reader.Close(); return(loader); }