NNFS
Neural network library from scratch
Loading...
Searching...
No Matches
mnist.cpp File Reference
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <random>
#include <filesystem>
#include <stdlib.h>
#include <unistd.h>
#include <Eigen/Core>
#include <curl/curl.h>
#include <zlib.h>
Include dependency graph for mnist.cpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool file_exists (const std::string &filename)
 Check if file exists.
 
void download_file (const std::string &url, const std::string &path)
 Download file from URL and save to local path.
 
bool unzip_file (const std::string &gz_path, const std::string &out_path)
 Unzip gz file and save to local path.
 
Eigen::MatrixXd read_mnist_images (const std::string &filename)
 Read a MNIST image file.
 
Eigen::MatrixXd read_mnist_labels (const std::string &filename)
 Read a MNIST label file.
 
std::tuple< Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd > fetch_mnist (const std::string &data_dir)
 Fetch MNIST dataset and save to local directory if it doesn't exist.
 

Variables

const std::string BASE_URL = "http://yann.lecun.com/exdb/mnist/"
 

Function Documentation

◆ download_file()

void download_file ( const std::string &  url,
const std::string &  path 
)

Download file from URL and save to local path.

Parameters
urlURL of file to download
pathLocal path to save downloaded file

◆ fetch_mnist()

std::tuple< Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd > fetch_mnist ( const std::string &  data_dir)

Fetch MNIST dataset and save to local directory if it doesn't exist.

Parameters
data_dirLocal directory to save MNIST dataset in
Returns
A tuple containing the training and test sets

◆ file_exists()

bool file_exists ( const std::string &  filename)

Check if file exists.

Parameters
filenameName of file to check
Returns
True if file exists, false otherwise

◆ read_mnist_images()

Eigen::MatrixXd read_mnist_images ( const std::string &  filename)

Read a MNIST image file.

Parameters
filenameName of the file to read
Returns
A matrix containing the images

◆ read_mnist_labels()

Eigen::MatrixXd read_mnist_labels ( const std::string &  filename)

Read a MNIST label file.

Parameters
filenameName of the file to read
Returns
A matrix containing the labels

◆ unzip_file()

bool unzip_file ( const std::string &  gz_path,
const std::string &  out_path 
)

Unzip gz file and save to local path.

Parameters
gz_pathLocal path of gz file to unzip
out_pathLocal path to save unzipped file
Returns
True if unzipping was successful, false otherwise

Variable Documentation

◆ BASE_URL

const std::string BASE_URL = "http://yann.lecun.com/exdb/mnist/"