-
Notifications
You must be signed in to change notification settings - Fork 26
Created new visualizer, fixed sonata tags: #219 #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4864b0b
66c3043
b3966bb
d1cf114
7ecf8a2
be655a8
7a1bb02
da95183
21e796b
41f73c2
0ef6d87
8f95fa0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,15 +74,9 @@ int main(int argc, char **argv) | |
| // https://click.kaspersky.com/?hl=en-US&version=2.0&pid=KNP&link=online_help&helpid=235801 | ||
| // https://click.kaspersky.com/?hl=en-US&version=2.0&pid=KNP&link=online_help&helpid=274991 | ||
| knp::framework::Network network = knp::framework::sonata::load_network(network_path); | ||
| // Constructs a network graph. | ||
| const knp::framework::NetworkGraph net_graph(network); | ||
| // Prints descriptions of graph connections. | ||
| knp::framework::print_network_description(net_graph); | ||
| // Draws a subgraph in the OpenCV window. | ||
| // Press `Esc` to exit the OpenCV window. | ||
| knp::framework::position_network_test( | ||
| knp::framework::NetworkGraph(network), knp::framework::divide_graph_by_connectivity(net_graph)[0], | ||
| {1000, 700}); | ||
|
|
||
| // knp::framework::set_saving_path("temp_test_dir"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Удалить. |
||
| knp::framework::visualize_network(network); | ||
| } | ||
|
|
||
| // If `task=infer`, the function loads a network and runs inference. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ if (NOT TARGET KNP::BaseFramework::Core) | |
| endif() | ||
|
|
||
| find_package(Boost ${KNP_BOOST_MIN_VERSION} COMPONENTS program_options REQUIRED) | ||
| find_package(PkgConfig REQUIRED) | ||
| pkg_check_modules(GRAPHVIZ REQUIRED IMPORTED_TARGET libgvc libcgraph) | ||
|
|
||
| add_executable(${PROJECT_NAME} | ||
| main.cpp | ||
|
|
@@ -40,4 +42,7 @@ add_executable(${PROJECT_NAME} | |
| models/altai/prepare_network_for_inference.cpp | ||
| models/altai/spike_generators.cpp) | ||
| target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}) | ||
| target_link_libraries(${PROJECT_NAME} PRIVATE KNP::BaseFramework::Core Boost::program_options) | ||
| target_link_libraries(${PROJECT_NAME} PRIVATE | ||
| KNP::BaseFramework::Core | ||
| Boost::program_options | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Скобку наверх. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,16 @@ | |
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include <knp/framework/io/input_channel.h> | ||
| #include <knp/framework/monitoring/observer.h> | ||
| #include <knp/framework/network.h> | ||
| #include <knp/framework/sonata/network_io.h> | ||
| #include <knp/framework/visualizer/visualize_network.h> | ||
|
|
||
| #include <iostream> | ||
|
|
||
| #include <boost/program_options.hpp> | ||
|
|
||
| #include "dataset.h" | ||
| #include "evaluate_results.h" | ||
| #include "inference.h" | ||
|
|
@@ -31,6 +39,7 @@ | |
|
|
||
| /** | ||
| * @brief Run whole model. | ||
| * | ||
| * @tparam Neuron Neuron type. | ||
| * @param model_desc Model description. | ||
| */ | ||
|
|
@@ -43,10 +52,16 @@ void run_model(const ModelDescription& model_desc) | |
|
|
||
| // Online Help link: https://click.kaspersky.com/?hl=en-US&version=2.0&pid=KNP&link=online_help&helpid=243548 | ||
| knp::framework::BackendLoader backend_loader; | ||
| train_model<Neuron>(model_desc, dataset, network, backend_loader); | ||
| auto backend = train_model<Neuron>(model_desc, dataset, network, backend_loader); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вообще странно получать бэк из функции тренировки модели. |
||
|
|
||
| if (!model_desc.model_saving_path_.empty()) save_network(model_desc, network); | ||
|
|
||
|
|
||
| // knp::framework::set_saving_path("temp_test_dir"); | ||
| visualize_network(network.network_); | ||
| visualize_network(network.network_, backend); | ||
|
Comment on lines
+61
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я так понимаю, где-то есть какие-то скрытые переменные, и потому вызов делается несколько раз? Если да, так не должно быть. Всё надо сделать явно. |
||
| visualize_bus(network.network_, backend); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вообще непонятно, причём тут шина. |
||
|
|
||
| auto inference_spikes = infer_model<Neuron>(model_desc, dataset, network, backend_loader); | ||
|
|
||
| evaluate_results(inference_spikes, dataset); | ||
|
|
@@ -55,8 +70,10 @@ void run_model(const ModelDescription& model_desc) | |
|
|
||
| /** | ||
| * @brief Main function. | ||
| * | ||
| * @param argc Argument count. | ||
| * @param argv Arguments value. | ||
| * | ||
| * @return Error code. | ||
| */ | ||
| int main(int argc, char** argv) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,19 +48,19 @@ using ResourceNeuronData = knp::neuron_traits::neuron_parameters<knp::neuron_tra | |
| struct NetworkPopulations | ||
| { | ||
| /// Input population. | ||
| const PopulationInfo &input_pop_; | ||
| const PopulationInfo& input_pop_; | ||
| /// Output population. | ||
| const PopulationInfo &output_pop_; | ||
| const PopulationInfo& output_pop_; | ||
| /// Gate population. Used for training. | ||
| const PopulationInfo &gate_pop_; | ||
| const PopulationInfo& gate_pop_; | ||
| /// Population for rasterized images. | ||
| const PopulationInfo &raster_pop_; | ||
| const PopulationInfo& raster_pop_; | ||
| /// Population for images labels. | ||
| const PopulationInfo &target_pop_; | ||
| const PopulationInfo& target_pop_; | ||
| }; | ||
|
|
||
|
|
||
| static NetworkPopulations create_populations(NetworkConstructor &constructor) | ||
| static NetworkPopulations create_populations(NetworkConstructor& constructor) | ||
| { | ||
| // Creating neurons. | ||
| // Online Help link: https://click.kaspersky.com/?hl=en-US&version=2.0&pid=KNP&link=online_help&helpid=235859 | ||
|
|
@@ -78,25 +78,22 @@ static NetworkPopulations create_populations(NetworkConstructor &constructor) | |
| input_neuron.stochastic_stimulation_ = stochastic_stimulation; | ||
|
|
||
| // Creating populations using neurons. | ||
| const auto &input_pop = | ||
| const auto& input_pop = | ||
| constructor.add_population(input_neuron, num_input_neurons, PopulationRole::INPUT, true, "INPUT"); | ||
| const auto &output_pop = | ||
| const auto& output_pop = | ||
| constructor.add_population(default_neuron, classes_amount, PopulationRole::OUTPUT, true, "OUTPUT"); | ||
| const auto &gate_pop = | ||
| constructor.add_population(default_neuron, classes_amount, PopulationRole::NORMAL, false, "GATE"); | ||
| const auto &raster_pop = constructor.add_channeled_population(input_size, true); | ||
| const auto &target_pop = constructor.add_channeled_population(classes_amount, false); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А это зачем удалять? |
||
| const auto& gate_pop = | ||
| constructor.add_population(default_neuron, classes_amount, PopulationRole::NORMAL, true, "GATE"); // was false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Комментарий "was false" вводит в заблуждения и не несёт смысловой нагрузки, - лучше убрать или дополнить. |
||
| const auto& raster_pop = constructor.add_channeled_population(input_size, true); | ||
| const auto& target_pop = constructor.add_channeled_population(classes_amount, true); // was false | ||
| // Returning them. | ||
| return {input_pop, output_pop, gate_pop, raster_pop, target_pop}; | ||
| } | ||
|
|
||
|
|
||
| static void create_projections( | ||
| AnnotatedNetwork &network, NetworkConstructor &constructor, const NetworkPopulations &pops) | ||
| AnnotatedNetwork& network, NetworkConstructor& constructor, const NetworkPopulations& pops) | ||
| { | ||
| // Creating synapse and projection out of it. Multiple times. | ||
|
|
||
| // Synapse creation. | ||
| ResourceSynapseParams raster_to_input_synapse; | ||
| raster_to_input_synapse.rule_.synaptic_resource_ = | ||
|
|
@@ -172,7 +169,7 @@ static void create_projections( | |
| * @see [Online Help](https://click.kaspersky.com/?hl=en-US&version=2.0&pid=KNP&link=online_help&helpid=235801) | ||
| */ | ||
| template <> | ||
| AnnotatedNetwork construct_network<knp::neuron_traits::BLIFATNeuron>(const ModelDescription &model_desc) | ||
| AnnotatedNetwork construct_network<knp::neuron_traits::BLIFATNeuron>(const ModelDescription& model_desc) | ||
| { | ||
| AnnotatedNetwork result; | ||
|
|
||
|
|
@@ -187,7 +184,6 @@ AnnotatedNetwork construct_network<knp::neuron_traits::BLIFATNeuron>(const Model | |
|
|
||
| // Add input_pop as WTA sender. | ||
| result.data_.wta_data_.emplace_back().first.push_back(pops.input_pop_.uid_); | ||
|
|
||
| create_projections(result, constructor, pops); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Возможно, искать следует без префикса
lib?