forked from KasperskyLab/knp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset.cpp
More file actions
56 lines (47 loc) · 2.09 KB
/
dataset.cpp
File metadata and controls
56 lines (47 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @file dataset.cpp
* @brief Process dataset.
* @kaspersky_support D. Postnikov
* @date 03.02.2026
* @license Apache 2.0
* @copyright © 2026 AO Kaspersky Lab
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dataset.h"
#include <fstream>
#include "global_config.h"
Dataset process_dataset(ModelDescription const& model_desc)
{
// Check if files exist.
if (!std::filesystem::exists(model_desc.images_file_path_))
throw std::runtime_error("Provided images file does not exists.");
else if (!std::filesystem::exists(model_desc.labels_file_path_))
throw std::runtime_error("Provided labels file does not exists.");
// Create streams for images and labels.
std::ifstream images_stream(model_desc.images_file_path_, std::ios::binary);
std::ifstream labels_stream(model_desc.labels_file_path_, std::ios::in);
Dataset dataset;
// Process them.
dataset.process_labels_and_images(
images_stream, labels_stream, model_desc.train_images_amount_ + model_desc.inference_images_amount_,
classes_amount, input_size, steps_per_image,
dataset.make_incrementing_image_to_spikes_converter(active_steps, state_increment_factor));
// Split dataset according to model description.
dataset.split(model_desc.train_images_amount_, model_desc.inference_images_amount_);
// Print out results.
std::cout << "Processed dataset, training will last " << dataset.get_steps_amount_for_training()
<< " steps, inference " << dataset.get_steps_amount_for_inference() << " steps\n"
<< std::endl;
return dataset;
}