* Move STB internally, comment functions if not Signed-off-by: Omar Shrit <omar@avontech.fr> * Comment for now STB including macros Signed-off-by: Omar Shrit <omar@avontech.fr> * Modify CMake and tests accordingly Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix the license and update the date. Signed-off-by: Omar Shrit <omar@avontech.fr> * Move STB to its own directory Signed-off-by: Omar Shrit <omar@avontech.fr> * Adding the functrions of image resize and crop Signed-off-by: Omar Shrit <omar@avontech.fr> * Update the API not finished yet Signed-off-by: Omar Shrit <omar@avontech.fr> * Start adding tests Signed-off-by: Omar Shrit <omar@avontech.fr> * Add flowers images for test Signed-off-by: Omar Shrit <omar@avontech.fr> * Bring image from the coco dataset Signed-off-by: Omar Shrit <omar@avontech.fr> * Include all of STB header in this file Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix STB configs Signed-off-by: Omar Shrit <omar@avontech.fr> * Clean CMakeLists and look for stb_resize Signed-off-by: Omar Shrit <omar@avontech.fr> * Make it compile with STB integrated Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix stb path Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix the endif at the end of the file Signed-off-by: Omar Shrit <omar@avontech.fr> * Update LICENSE.txt Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update CMakeLists.txt Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/config.hpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Adding the function and test, not finished Signed-off-by: Omar Shrit <omar@avontech.fr> * Remove crop from this PR, and add tests Signed-off-by: Omar Shrit <omar@avontech.fr> * Update LICENSE.txt Co-authored-by: Dirk Eddelbuettel <edd@debian.org> * Update CMakeLists.txt Co-authored-by: Dirk Eddelbuettel <edd@debian.org> * merge master Signed-off-by: Omar Shrit <omar@avontech.fr> * Add @rcutin suggestion for stb Signed-off-by: Omar Shrit <omar@avontech.fr> * Improve the logic to include edge cases Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix the bundle that if we are using system stb Signed-off-by: Omar Shrit <omar@avontech.fr> * Make it possible to disable the entire build with STB Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix the else if condition Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix the else condition Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix the tests accordindly Signed-off-by: Omar Shrit <omar@avontech.fr> * Add dummpy functions and complete the Resize function Signed-off-by: Omar Shrit <omar@avontech.fr> * Reorder to see if this fix the problem Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix the resize for a set of images Signed-off-by: Omar Shrit <omar@avontech.fr> * Add STATIC for resize and write Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix all the problem with this function Signed-off-by: Omar Shrit <omar@avontech.fr> * Be able to resize N images easily Signed-off-by: Omar Shrit <omar@shrit.fr> * Add the tests, already passing Signed-off-by: Omar Shrit <omar@shrit.fr> * Use sheep instead of Umbrella Signed-off-by: Omar Shrit <omar@shrit.fr> * Fix STB directory Signed-off-by: Omar Shrit <omar@shrit.fr> * Fix Cmake and docs Signed-off-by: Omar Shrit <omar@shrit.fr> * Apply comments from @rcurtin Signed-off-by: Omar Shrit <omar@shrit.fr> * Integrate @rcurtin comments Signed-off-by: Omar Shrit <omar@shrit.fr> * Fix tests and remove generated images Signed-off-by: Omar Shrit <omar@shrit.fr> * Add docs Signed-off-by: Omar Shrit <omar@shrit.fr> * Update the API with new resize version Signed-off-by: Omar Shrit <omar@shrit.fr> * Fix to resize2 Signed-off-by: Omar Shrit <omar@shrit.fr> * Adding resize2 Signed-off-by: Omar Shrit <omar@shrit.fr> * Add the necessary fix to avoid linker errors Signed-off-by: Omar Shrit <omar@avontech.fr> * Add configs to allow correct repacking Signed-off-by: Omar Shrit <omar@shrit.fr> * Redo the ResizeImages function Signed-off-by: Omar Shrit <omar@shrit.fr> * Pack the images as tzr.bz2 Signed-off-by: Omar Shrit <omar@shrit.fr> * Fix the function calls and create an internal one Signed-off-by: Omar Shrit <omar@avontech.fr> * Make the message shorter to have under 80 chars Signed-off-by: Omar Shrit <omar@avontech.fr> * Solve linter errors Signed-off-by: Omar Shrit <omar@avontech.fr> * Solve linter error Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix linter issues Signed-off-by: Omar Shrit <omar@avontech.fr> * Update doc/user/load_save.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/tests/image_test.cpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/core/data/image_resize_crop.hpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/core/data/image_resize_crop.hpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update doc/user/load_save.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update doc/user/load_save.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/tests/image_test.cpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/tests/image_test.cpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/tests/image_test.cpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/tests/image_test.cpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/core/data/image_resize_crop.hpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Apply @rcurtin comments Signed-off-by: Omar Shrit <omar@avontech.fr> * Add an example usage of these two functions Signed-off-by: Omar Shrit <omar@avontech.fr> * Apply @rcurtin comments Signed-off-by: Omar Shrit <omar@avontech.fr> * Re-organize directories for STB Signed-off-by: Omar Shrit <omar@avontech.fr> * Apply rcurtin comments Signed-off-by: Omar Shrit <omar@avontech.fr> * Merge two resize functions into one Signed-off-by: Omar Shrit <omar@avontech.fr> * Get rid of MLPACK_DISABLE_STB Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix forgetting docs Signed-off-by: Omar Shrit <omar@avontech.fr> * Update CMake/FindStbImage.cmake Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update CMake/FindStbImage.cmake Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update doc/user/install.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update doc/user/compile.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/core/data/image_resize_crop.hpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update doc/user/load_save.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update doc/user/load_save.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update doc/user/load_save.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update doc/user/load_save.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/core/data/image_resize_crop.hpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/core/data/image_resize_crop.hpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update src/mlpack/core/data/image_resize_crop.hpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update doc/user/load_save.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Apply comments from @rcurtin Signed-off-by: Omar Shrit <omar@avontech.fr> * Adding the test to test if it is identical Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix image tests Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix the example Signed-off-by: Omar Shrit <omar@avontech.fr> * Add the link and the patch to download the images Signed-off-by: Omar Shrit <omar@avontech.fr> * Fix the script and make all of them green Signed-off-by: Omar Shrit <omar@avontech.fr> * Remove wget not needed Signed-off-by: Omar Shrit <omar@avontech.fr> * Minor style fixes. * Avoid temporary matrices, and test with multiple different types. * Update src/mlpack/config.hpp Co-authored-by: Ryan Curtin <ryan@ratml.org> * Update HISTORY.md Co-authored-by: Ryan Curtin <ryan@ratml.org> * Fix R build by including bundled STB headers in package. --------- Signed-off-by: Omar Shrit <omar@avontech.fr> Signed-off-by: Omar Shrit <omar@shrit.fr> Co-authored-by: Ryan Curtin <ryan@ratml.org> Co-authored-by: Dirk Eddelbuettel <edd@debian.org>
9.1 KiB
Compile an mlpack program
Once an mlpack application has been developed, it is easy to compile it into a standalone program. On this page, compilation is performed via the command-line on a standard Linux or OS X system; if this is not your environment, see also:
Simple command-line compilation
Assuming that mlpack and its dependencies are installed on the system, an mlpack program can be compiled just like any other C++ program:
g++ -std=c++17 -O3 -o mlpack_program mlpack_program.cpp -larmadillo -fopenmp
The command above uses gcc to compile the program
mlpack_program.cpp in C++17 mode with optimizations, using OpenMP for
parallelization. It is expected that mlpack_program.cpp has the int main()
function defined.
For more complex applications that have multiple source files, it can often be
easier to develop a simple Makefile.
The examples repository contains several
standalone C++ projects, each of which have Makefiles. These can be adapted
for any project, and are especially useful if any extra include directories or
library directories need to be specified. (This might be the case if, for
instance, mlpack or any dependencies are not installed to standard locations.)
A full list of compiler options to configure the build is beyond the scope of this simple documentation, but this simple list has a handful of commonly-used gcc/clang options.
Configuring mlpack with compile-time definitions
Several compilation options can control the behavior of an mlpack program. These can be specified directly on the command line, or at the top of the program (before including mlpack or Armadillo!).
| Command-line option | Code option | Meaning |
|---|---|---|
| Speed and debugging. | ||
-DNDEBUG |
#define NDEBUG |
Remove all debugging checks. This can result in slightly faster code, but with no error checking! |
-DARMA_NO_DEBUG |
#define ARMA_NO_DEBUG |
Remove all Armadillo error checking. Warning: if there are errors in your code, you are more likely to get a segfault instead of an exception! |
| --------------------------- | ------------------- | --------------- |
| Output. | ||
-DMLPACK_COUT_STREAM=std::cout |
#define MLPACK_COUT_STREAM std::cout |
Set the default output stream. (Defaults to std::cout.) |
-DMLPACK_CERR_STREAM=std::cerr |
#define MLPACK_CERR_STREAM std::cerr |
Set the default error stream. (Defaults to std::cerr.) |
-DMLPACK_PRINT_INFO |
#define MLPACK_PRINT_INFO |
Print information messages ([INFO ]) during program execution. |
-DMLPACK_PRINT_WARN |
#define MLPACK_PRINT_WARN |
Print warning messages ([WARN ]) during program execution. |
-DMLPACK_SUPPRESS_FATAL |
#define MLPACK_PRINT_FATAL |
Do not print [FATAL] messages during program execution. |
-DENS_PRINT_INFO |
#define ENS_PRINT_INFO |
Print informational messages from ensmallen optimizers. |
-DENS_PRINT_WARN |
#define ENS_PRINT_WARN |
Print warning messages from ensmallen optimizers. |
| --------------------------- | ------------------- | --------------- |
| Functionality. | ||
-DMLPACK_ENABLE_ANN_SERIALIZATION |
#define MLPACK_ENABLE_ANN_SERIALIZATION |
Allow neural network layers to be serialized. |
-DMLPACK_NO_STD_MUTEX |
#define MLPACK_NO_STD_MUTEX |
Disable mutexes inside mlpack; use this if your system has no support for std::mutex and has only one core. You may also need to define ARMA_DO_NOT_USE_STD_MUTEX for Armadillo. |
| --------------------------- | ------------------- | --------------- |
| Configuration. | ||
-DMLPACK_USE_SYSTEM_STB |
#define MLPACK_USE_SYSTEM_STB |
Use the version of STB available on the system instead of the version bundled with mlpack. If set, make sure stb_image.h, stb_image_write.h, and stb_image_resize2.h are available. |
-DMLPACK_DONT_USE_SYSTEM_STB |
#define MLPACK_DONT_USE_SYSTEM_STB |
Force usage of the bundled version of STB. Only necessary if mlpack was configured with USE_SYSTEM_STB=ON. |
Note: If your code serializes (saves or loads) mlpack neural networks, the
MLPACK_ENABLE_ANN_SERIALIZATION option must be enabled. This option is not
enabled by default because it can cause compilation time to increase
significantly, but it is necessary for any code that serializes neural networks.
Linking without the Armadillo wrapper
Armadillo, by default, requires linking against the runtime library
libarmadillo.so (or libarmadillo.dylib or armadillo.dll on non-Linux
systems). This library is a convenience library that internally contains all of
the symbols necessary from lower-level libraries (e.g.
OpenBLAS,
SuperLU,
ARPACK,
HDF5, and so on).
When the wrapper library is used, linking against Armadillo means simply typing
-larmadillo instead of linking against all of Armadillo's dependencies.
In some situations this is not preferable, and it is therefore possible via the
ARMA_DONT_USE_WRAPPER macro
to avoid the Armadillo runtime library and link directly against Armadillo's
dependencies.
When the Armadillo wrapper library is not being used, a compilation command will need to be adjusted. For instance, the example of the previous section would need to be changed to:
g++ -DARMA_DONT_USE_WRAPPER -std=c++17 -O3 -o mlpack_program mlpack_program.cpp -lopenblas -fopenmp
Some notes on the command above:
-
Here,
ARMA_DONT_USE_WRAPPERis specified on the command line instead of inmlpack_program.cpp(or otherwise in the Armadillo configuration). -
OpenBLAS is used for BLAS/LAPACK support. But, other options include ACML, reference LAPACK/BLAS, Intel MKL, and so forth.
-
In some programs, especially if sparse matrix support or HDF5 support is used, it may be necessary to link against other libraries (e.g.
-lSuperLU -lhdf5, etc.). The precise set of libraries to link against depends on the code being used and the system configuration, but it should be easy enough to use any linker errors to figure out what libraries need to be linked against.
Using mlpack in another CMake project
For complex C++ projects, a build system like CMake may be in use. Adding mlpack as a dependency to a C++ project is straightforward. The following CMake code will require mlpack and its dependencies to be available:
# Find mlpack and its dependencies.
find_package(Armadillo REQUIRED)
find_package(cereal REQUIRED)
find_package(ensmallen REQUIRED)
find_package(mlpack REQUIRED)
include_directories("${ARMADILLO_INCLUDE_DIRS}" "${CEREAL_INCLUDE_DIR}"
"${ENSMALLEN_INCLUDE_DIR}" "${MLPACK_INCLUDE_DIR}")
# Targets should link against ${ARMADILLO_LIBRARIES}.
If the relevant files are not available on the system to find those four packages, they can be downloaded from the models repository:
The following files in that directory are necessary (and can be added to the CMake files for the project):