@@ -68,11 +68,11 @@ static std::vector<Tensor> load_mnist_images(std::string path){
6868
6969 std::vector<Tensor> images;
7070 for (int i = 0 ; i < num_images; i++) {
71- std::vector<float > buffer (rows * cols);
71+ std::vector<uint8_t > buffer (rows * cols);
7272 file.read (reinterpret_cast <char *>(buffer.data ()), rows * cols);
73-
73+ std::vector< float > float_buffer (buffer. begin (), buffer. end ());
7474 // @@ temporary
75- images.push_back (Tensor ({rows * cols, 1 }, buffer ) / 255.0 );
75+ images.push_back (Tensor ({rows * cols, 1 }, float_buffer ) / 255.0 );
7676 }
7777 file.close ();
7878 return images;
@@ -85,12 +85,12 @@ MNISTDataset::MNISTDataset(std::string labels_path, std::string images_path){
8585}
8686
8787
88- size_t MNISTDataset::size (){
89- return 0 ;
90- }
91- std::pair<Tensor, int > MNISTDataset::get_item (size_t index){
92-
88+ int MNISTDataset::size () const {
89+ return 101 ;
9390}
91+ // std::pair<Tensor, int> MNISTDataset::get_item(int index) const{
92+ // return nullptr;
93+ // }
9494
9595static char pixel_to_char (float pixel_value) {
9696 if (pixel_value > 0 .8f ) return ' #' ; // Dark pixel
@@ -100,16 +100,17 @@ static char pixel_to_char(float pixel_value) {
100100 else return ' ' ; // Very light pixel (almost white)
101101}
102102
103- void TensorSANN ::print_mnist_index (int index){
104- auto image = images[index].data ;
103+ void MNISTDataset ::print_mnist_index (int index){
104+ auto image = images[index].data () ;
105105 int label = labels[index];
106106 std::cout << " Index: " << index << " Label: " << label << std::endl;
107107
108108 for (int i = 0 ; i < MINIST_IMG_DIM; i++) {
109109 for (int j = 0 ; j < MINIST_IMG_DIM; j++) {
110- printf (" %c " , pixel_to_char (image[i * MINIST_IMG_DIM + j]));
110+ std::cout << pixel_to_char (image[i * MINIST_IMG_DIM + j]);
111+ // std::cout << (iemage[i * MINIST_IMG_DIM + j]);
111112 }
112- printf ( " \n " ) ;
113+ std::cout<< std::endl ;
113114 }
114115
115116}
0 commit comments