Skip to content

Commit

Permalink
Merge pull request #4 from eidelen/master
Browse files Browse the repository at this point in the history
CMake integration and example
  • Loading branch information
wichtounet committed Aug 2, 2017
2 parents ec0e2ee + 58787c3 commit 6bb5922
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions MNISTConfig.cmake
@@ -0,0 +1,9 @@
# Config file for the MNIST package
# It defines the following variables
# MNIST_INCLUDE_DIR - include directory of MNIST
# MNIST_DATA_DIR - directory of the actual MNIST data
# MNIST_FOUND - MNIST is available

set(MNIST_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include)
set(MNIST_DATA_DIR ${CMAKE_CURRENT_LIST_DIR})
set(MNIST_FOUND TRUE)
18 changes: 18 additions & 0 deletions example/CMakeLists.txt
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.0)

PROJECT(mnist_example)

# .. -> hint, that the mnist package is one directory level above.
# When using just "find_package(MNIST REQUIRED)", "MNIST_DIR"
# cmake variable has to be set correctly.
find_package(MNIST PATHS ..)
if(NOT MNIST_FOUND)
message(FATAL_ERROR "MNIST loader could not be found. It is available under https://github.com/wichtounet/mnist")
endif(NOT MNIST_FOUND)

include_directories(${MNIST_INCLUDE_DIR})
add_executable(mnist_example main.cpp)
target_compile_features(mnist_example PRIVATE cxx_range_for)

# Pass MNIST data directory to main.cpp
target_compile_definitions(mnist_example PRIVATE MNIST_DATA_LOCATION="${MNIST_DATA_DIR}")
25 changes: 25 additions & 0 deletions example/main.cpp
@@ -0,0 +1,25 @@
//=======================================================================
// Copyright (c) 2017 Adrian Schneider
// Distributed under the terms of the MIT License.
// (See accompanying file LICENSE or copy at
// http://opensource.org/licenses/MIT)
//=======================================================================

#include <iostream>
#include "mnist/mnist_reader.hpp"

int main(int argc, char* argv[]) {
// MNIST_DATA_LOCATION set by MNIST cmake config
std::cout << "MNIST data directory: " << MNIST_DATA_LOCATION << std::endl;

// Load MNIST data
mnist::MNIST_dataset<std::vector, std::vector<uint8_t>, uint8_t> dataset =
mnist::read_dataset<std::vector, std::vector, uint8_t, uint8_t>(MNIST_DATA_LOCATION);

std::cout << "Nbr of training images = " << dataset.training_images.size() << std::endl;
std::cout << "Nbr of training labels = " << dataset.training_labels.size() << std::endl;
std::cout << "Nbr of test images = " << dataset.test_images.size() << std::endl;
std::cout << "Nbr of test labels = " << dataset.test_labels.size() << std::endl;

return 0;
}

0 comments on commit 6bb5922

Please sign in to comment.