Skip to content

Commit 77d857d

Browse files
authored
Merge pull request #71 from DavidIkov/fixed-commits
Moved loggers from mnist to framework. Added tests for loggers
2 parents ef55dfd + 37d9c8e commit 77d857d

13 files changed

Lines changed: 621 additions & 337 deletions

File tree

examples/mnist-learn/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ if (NOT TARGET KNP::BaseFramework::Core)
2727
find_package(knp-base-framework REQUIRED)
2828
endif()
2929

30-
add_executable(mnist_learn_example main.cpp data_read.cpp construct_network.cpp evaluation.cpp logging.cpp train.cpp inference.cpp wta.cpp)
30+
add_executable(mnist_learn_example main.cpp data_read.cpp construct_network.cpp evaluation.cpp train.cpp inference.cpp wta.cpp time_string.cpp)
3131
target_link_libraries(mnist_learn_example PRIVATE KNP::BaseFramework::Core ${Boost_LIBRARIES})

examples/mnist-learn/inference.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <knp/framework/model.h>
2525
#include <knp/framework/model_executor.h>
26+
#include <knp/framework/monitoring/model.h>
2627
#include <knp/framework/monitoring/observer.h>
2728
#include <knp/framework/network.h>
2829
#include <knp/framework/sonata/network_io.h>
@@ -34,9 +35,10 @@
3435

3536
#include "construct_network.h"
3637
#include "data_read.h"
37-
#include "logging.h"
38+
#include "time_string.h"
3839
#include "wta.h"
3940

41+
constexpr size_t aggregated_spikes_logging_period = 4e3;
4042

4143
namespace fs = std::filesystem;
4244

@@ -66,16 +68,15 @@ std::vector<knp::core::messaging::SpikeMessage> run_mnist_inference(
6668
auto &out_channel = model_executor.get_loader().get_output_channel(o_channel_uid);
6769

6870
model_executor.get_backend()->stop_learning();
69-
std::vector<InferenceResult> result;
7071

71-
// Add observer.
72-
model_executor.add_observer<knp::core::messaging::SpikeMessage>(
73-
make_observer_function(result), described_network.data_.output_uids_);
72+
knp::framework::monitoring::model::add_status_logger(model_executor, model, std::cout, 1);
73+
7474
std::ofstream log_stream;
75-
// These two variables should have the same lifetime as model_executor, or else UB.
75+
76+
// This variable should have the same lifetime as model_executor, or else UB.
77+
// cppcheck-suppress variableScope
7678
std::map<std::string, size_t> spike_accumulator;
77-
// cppcheck-suppress variableScope
78-
size_t current_index = 0;
79+
7980
auto wta_uids = add_wta_handlers(described_network, model_executor);
8081
auto all_senders_names = described_network.data_.population_names_;
8182
for (const auto &uid : wta_uids)
@@ -91,7 +92,8 @@ std::vector<knp::core::messaging::SpikeMessage> run_mnist_inference(
9192
}
9293
if (log_stream.is_open())
9394
{
94-
add_aggregate_logger(model, all_senders_names, model_executor, current_index, spike_accumulator, log_stream);
95+
knp::framework::monitoring::model::add_aggregated_spikes_logger(
96+
model, all_senders_names, model_executor, spike_accumulator, log_stream, aggregated_spikes_logging_period);
9597
}
9698

9799
// Start model.

examples/mnist-learn/logging.cpp

Lines changed: 0 additions & 198 deletions
This file was deleted.

examples/mnist-learn/logging.h

Lines changed: 0 additions & 108 deletions
This file was deleted.

examples/mnist-learn/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "data_read.h"
2727
#include "evaluation.h"
2828
#include "inference.h"
29-
#include "logging.h"
29+
#include "time_string.h"
3030
#include "train.h"
3131

3232

0 commit comments

Comments
 (0)