-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from eidelen/master
CMake integration and example
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |