ATLAS Offline Software
Loading...
Searching...
No Matches
EvaluateUtils.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3#include "EvaluateUtils.h"
4
5#include <fstream>
6#include <arpa/inet.h>
7
8namespace EvaluateUtils {
9 //*******************************************************************
10 // for reading MNIST images
11 std::vector<std::vector<std::vector<float>>> read_mnist_pixel_notFlat(const std::string &full_path)
12 {
13 std::vector<std::vector<std::vector<float>>> input_tensor_values;
14 input_tensor_values.resize(10000, std::vector<std::vector<float> >(28,std::vector<float>(28)));
15 std::ifstream file (full_path.c_str(), std::ios::binary);
16 int magic_number=0;
17 int number_of_images=0;
18 int n_rows=0;
19 int n_cols=0;
20 file.read(reinterpret_cast<char*>(&magic_number),sizeof(magic_number));
21 magic_number= ntohl(magic_number);
22 file.read(reinterpret_cast<char*>(&number_of_images),sizeof(number_of_images));
23 number_of_images= ntohl(number_of_images);
24 file.read(reinterpret_cast<char*>(&n_rows),sizeof(n_rows));
25 n_rows= ntohl(n_rows);
26 file.read(reinterpret_cast<char*>(&n_cols),sizeof(n_cols));
27 n_cols= ntohl(n_cols);
28 for(int i=0;i<number_of_images;++i)
29 {
30 for(int r=0;r<n_rows;++r)
31 {
32 for(int c=0;c<n_cols;++c)
33 {
34 unsigned char temp=0;
35 file.read((char*)&temp,sizeof(temp));
36 input_tensor_values[i][r][c]= float(temp)/255;
37 }
38 }
39 }
40 return input_tensor_values;
41 }
42}
int r
Definition globals.cxx:22
std::vector< std::vector< std::vector< float > > > read_mnist_pixel_notFlat(const std::string &full_path)
TFile * file