OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
image_dataset.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// I M A G E D A T A S E T C L A S S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#pragma once
10
11#include "dataset.h"
12#include "io_utilities.h"
13
14namespace opennn
15{
16
30
32class ImageDataset : public Dataset
33{
34
35public:
36
41 ImageDataset(const Index = 0, const Shape& = {0, 0, 0}, const Shape& = {0});
42
44 ImageDataset(const filesystem::path&);
45
47 Index get_channels_number() const;
48
49 const AugmentationSettings& get_augmentation() const { return augmentation; }
50 void set_augmentation(const AugmentationSettings& new_augmentation) { augmentation = new_augmentation; }
51
53 Index get_samples_number() const override;
55
57 void set_data_random() override;
58
59 void set_image_padding(int new_padding) { padding = new_padding; }
60
62
64 vector<Descriptives> scale_features(const string&) override;
66 void unscale_features(const string&);
67
69 void read_bmp(const Shape& new_input_shape = { 0, 0, 0 });
70
71 void from_JSON(const JsonDocument&) override;
72 void to_JSON(JsonWriter&) const override;
73
75 void fill_inputs(const vector<Index>&,
76 const vector<Index>&,
77 float*,
78 bool is_training,
79 bool parallelize = true,
80 int = -1) const override;
81
83 void fill_targets(const vector<Index>&,
84 const vector<Index>&,
85 float*,
86 bool is_training,
87 bool parallelize = true,
88 int = -1) const override;
89
91 void augment_inputs(float*, Index) const override;
92
93private:
94
95 Index padding = 0;
96
97 AugmentationSettings augmentation;
98
99 // Binary streaming cache: <data_path>/.cache/images.bin
100 // Pixels stored as uint8 [0..255]; labels as int32_t.
101 filesystem::path cache_path;
102 mutable FileReader cache_reader;
103 uint64_t record_bytes_ = 0;
104 uint64_t labels_off_ = 0;
105 uint32_t num_classes_ = 0;
106 vector<int32_t> labels_ram; // small; one entry per sample
107
108 vector<string> labels_tokens;
109
110 Index width_no_padding = 0;
111
112 Index regions_number = 1000;
113 Index region_rows = 6;
114 Index region_variables = 6;
115
116};
117
118}
119
120// OpenNN: Open Neural Networks Library.
121// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
122// Licensed under the GNU Lesser General Public License v2.1 or later.
Dataset()=default
virtual Index get_samples_number() const
Returns the total number of samples (rows) in the data matrix.
Definition dataset.h:74
virtual void unscale_features(const string &, const vector< Descriptives > &)
Reverts a previously applied scaling using the supplied descriptives.
Definition dataset.h:375
Thread-safe positional file reader (pread on POSIX, overlapped ReadFile on Windows).
Definition io_utilities.h:20
void set_image_padding(int new_padding)
Definition image_dataset.h:59
Index get_samples_number() const override
Returns the number of image samples in the dataset.
vector< Descriptives > scale_features(const string &) override
Scales image pixel values for the given feature role.
void to_JSON(JsonWriter &) const override
Writes dataset state to a JSON writer.
const AugmentationSettings & get_augmentation() const
Definition image_dataset.h:49
ImageDataset(const filesystem::path &)
Creates an image dataset by reading the BMP archive at the given path.
void unscale_features(const string &)
Reverts the pixel scaling for the given feature role.
Index get_channels_number() const
Returns the number of image channels (typically 1 or 3).
ImageDataset(const Index=0, const Shape &={0, 0, 0}, const Shape &={0})
Creates an image dataset with the given sample count, image shape and target shape.
void read_bmp(const Shape &new_input_shape={ 0, 0, 0 })
Reads BMP images into the dataset, resizing to new_input_shape when non-zero.
void fill_inputs(const vector< Index > &, const vector< Index > &, float *, bool is_training, bool parallelize=true, int=-1) const override
Streams pixel data of the selected samples into the destination buffer.
void from_JSON(const JsonDocument &) override
Loads dataset state from a JSON document.
void set_augmentation(const AugmentationSettings &new_augmentation)
Definition image_dataset.h:50
void fill_targets(const vector< Index > &, const vector< Index > &, float *, bool is_training, bool parallelize=true, int=-1) const override
Writes one-hot encoded labels of the selected samples into the destination buffer.
void set_data_random() override
Generates random image data, replacing the current contents.
void augment_inputs(float *, Index) const override
Applies the configured augmentations in place to a batch of images.
Definition json.h:72
Definition json.h:85
Definition adaptive_moment_estimation.h:14
Image augmentation parameters: reflections, rotations and translations applied at training.
Definition image_dataset.h:19
bool enabled
Definition image_dataset.h:20
float vertical_translation_minimum
Definition image_dataset.h:27
bool reflection_axis_y
Definition image_dataset.h:22
bool reflection_axis_x
Definition image_dataset.h:21
float vertical_translation_maximum
Definition image_dataset.h:28
float rotation_minimum
Definition image_dataset.h:23
float rotation_maximum
Definition image_dataset.h:24
float horizontal_translation_maximum
Definition image_dataset.h:26
float horizontal_translation_minimum
Definition image_dataset.h:25
Fixed-capacity small-vector describing tensor dimensions (rank up to MaxRank).
Definition tensor_utilities.h:42