Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            images = MNISTImages.Load(imgsPath);
            labels = MNISTLabels.Load(labelsPath);

            for (int i = 0; i < images.Images.Count; i++)
            {
                Bitmap bitmap     = new Bitmap(images.Row, images.Column);
                byte[] imageBytes = images.Images[i];

                for (int j = 0; j < imageBytes.Length; j++)
                {
                    int y     = j / 28;
                    int x     = j % 28;
                    int color = imageBytes[j];
                    bitmap.SetPixel(x, y, Color.FromArgb(color, color, color));
                }

                img.Add(bitmap);
            }

            _timer.Start();
        }
Exemple #2
0
        private List <Matrix> LoadMNIST()
        {
            List <Matrix> matrices = new List <Matrix>();

            MNISTImages train_images = MNISTImages.Load(train_imgs_path, TrainDataCount);

            Matrix x_train = new Matrix(TrainDataCount, 784);

            int x_train_row = x_train.X;
            int y_train_col = x_train.Y;

            Parallel.For(0, x_train_row, i =>
            {
                for (int j = 0; j < y_train_col; j++)
                {
                    x_train[i, j] = train_images.Images[i][j] / 255.0;
                }
            });



            MNISTLabels train_labels = MNISTLabels.Load(train_labels_path, TrainDataCount);

            Matrix t_train = new Matrix(TrainDataCount, 10);

            //转成one-hot
            for (int i = 0; i < t_train.X; i++)
            {
                t_train[i, train_labels.Labels[i]] = 1;
            }


            MNISTImages test_images = MNISTImages.Load(test_imgs_path, TestDataCount);

            Matrix x_test = new Matrix(TestDataCount, 784);

            int x_test_row = x_test.X;
            int y_test_col = x_test.Y;


            Parallel.For(0, x_test_row, i =>
            {
                for (int j = 0; j < y_test_col; j++)
                {
                    x_test[i, j] = test_images.Images[i][j] / 255.0;
                }
            });


            MNISTLabels test_labels = MNISTLabels.Load(test_labels_path, TestDataCount);

            Matrix t_test = new Matrix(TestDataCount, 10);

            for (int i = 0; i < t_test.X; i++)
            {
                t_test[i, test_labels.Labels[i]] = 1;
            }

            matrices.Add(x_train);
            matrices.Add(t_train);
            matrices.Add(x_test);
            matrices.Add(t_test);

            Console.WriteLine("MNIST 加载完成");

            return(matrices);
        }