6#if MATH_IMAGE_PROCESSING
8 #include <Magick++/Image.h>
25 :
DataSet(inputCount, outputCount) { }
34 std::cout <<
"Moving files..." << std::flush;
36 std::filesystem::copy(
39 std::filesystem::copy_options::update_existing | std::filesystem::copy_options::recursive);
42 size_t classCount = 0;
44 for(
const auto& entry : std::filesystem::directory_iterator(
trainDirectory)) {
45 if(entry.is_directory()) {
47 auto dirIter = std::filesystem::directory_iterator(entry);
48 totalCount += std::count_if(begin(dirIter), end(dirIter), [](
auto& elem) {
return elem.is_regular_file(); });
60 for(
const auto& entry : std::filesystem::directory_iterator(
trainDirectory)) {
61 if(entry.is_directory()) {
62 MatrixDS<bool> elem(
false, 1, classCount);
63 elem(0, index) =
true;
68 std::cout <<
"done!\nDirectory \"" <<
trainDirectory <<
"\" ready." << std::endl;
69 std::cout <<
"Found " <<
totalCount <<
" files belonging to " << classCount <<
" classes.\nUsing "
86#if MATH_IMAGE_PROCESSING
87 std::cout <<
"Resizing files and saving into memory..." << std::flush;
88 size_t count = 0, i = 0, classCount = 0;
89 size_t trainingIter = 0, validationIter = 0;
90 for(
const auto& classDirectory : std::filesystem::directory_iterator(
trainDirectory)) {
91 bool hadEntry =
false;
92 if(!classDirectory.is_directory() || classCount >=
classes.size())
continue;
93 for(
const auto& entry : std::filesystem::directory_iterator(classDirectory)) {
94 if(!entry.is_regular_file())
continue;
100 image.read(std::string(entry.path()));
107 Magick::PixelData pixelBlob(image,
"RGBA", Magick::FloatPixel);
109 auto* in = (
float*)pixelBlob.data();
111 for(i = 0; i <
InputCount; i++) { (*target).Input[is_validation ? validationIter : trainingIter][i] = in[i]; }
113 (*target).Output[is_validation ? validationIter : trainingIter][i] =
classes[classCount][0][i];
122 classCount += hadEntry;
Definition: DataSet.h:195
size_t OutputCount
number output elements
Definition: DataSet.h:234
Set Validation
set for validation of training
Definition: DataSet.h:239
size_t InputCount
number input elements
Definition: DataSet.h:232
Set Training
set for training
Definition: DataSet.h:237
bool verbose
use verbose output during fitting
Definition: DataSet.h:252
only include Magick++ if needed
Definition: ImageDataSet.h:17
double validationShare
percentage of validation data
Definition: ImageDataSet.h:133
size_t validationCount
number of validation data records
Definition: ImageDataSet.h:145
size_t trainingCount
number of training data records
Definition: ImageDataSet.h:143
std::vector< MatrixDS< bool > > classes
representation of all classes
Definition: ImageDataSet.h:137
ImageDataSet(size_t inputCount, size_t outputCount)
Definition: ImageDataSet.h:24
std::vector< std::string > classNames
representation of all class names
Definition: ImageDataSet.h:139
size_t totalCount
total number of data records
Definition: ImageDataSet.h:141
size_t imageWidth
desired image width
Definition: ImageDataSet.h:131
virtual void PrepareDirectory(const char *filePath)
Definition: ImageDataSet.h:31
size_t imageHeight
desired image height
Definition: ImageDataSet.h:129
void Cache()
Definition: ImageDataSet.h:85
const char * trainDirectory
target directory for training
Definition: ImageDataSet.h:135
Matrix< double > Input
input data
Definition: DataSet.h:20
Matrix< double > Output
expected output data
Definition: DataSet.h:22