-
Notifications
You must be signed in to change notification settings - Fork 21
Fix for inference_evaluation and f_score #104
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 0 additions & 115 deletions
115
knp/base-framework/include/knp/framework/inference_evaluation/classification.h
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
knp/base-framework/include/knp/framework/inference_evaluation/classification/processor.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /** | ||
| * @file processor.h | ||
| * @brief Processing inference results. | ||
| * @kaspersky_support D. Postnikov | ||
| * @date 05.09.2025 | ||
| * @license Apache 2.0 | ||
| * @copyright © 2025 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <knp/core/messaging/messaging.h> | ||
| #include <knp/framework/data_processing/classification/image.h> | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include "result.h" | ||
|
|
||
|
|
||
| namespace knp::framework::inference_evaluation::classification | ||
| { | ||
|
|
||
| /** | ||
| * @details A class to process inference results. | ||
| */ | ||
| class KNP_DECLSPEC InferenceResultsProcessor | ||
| { | ||
| public: | ||
| /** | ||
| * @brief Process inference results. Suited for classification models. | ||
| * @param spikes All spikes from inference. | ||
| * @param dataset Dataset. | ||
| */ | ||
| void process_inference_results( | ||
| const std::vector<knp::core::messaging::SpikeMessage> &spikes, | ||
| const knp::framework::data_processing::classification::Dataset &dataset); | ||
|
|
||
| /** | ||
| * @brief Put inference results for each class to a stream in form of csv. | ||
| * @param results_stream stream for output. | ||
| */ | ||
| void write_inference_results_to_stream_as_csv(std::ostream &results_stream); | ||
|
|
||
| /** | ||
| * @brief Get inference results. | ||
| * @return Inference results. | ||
| */ | ||
| [[nodiscard]] const std::vector<InferenceResult> &get_inference_results() const { return inference_results_; } | ||
|
|
||
|
artiomn marked this conversation as resolved.
|
||
| private: | ||
| /** | ||
| * @brief Processed inference results. | ||
| */ | ||
| std::vector<InferenceResult> inference_results_; | ||
| }; | ||
|
|
||
| } // namespace knp::framework::inference_evaluation::classification | ||
61 changes: 61 additions & 0 deletions
61
knp/base-framework/include/knp/framework/inference_evaluation/classification/result.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /** | ||
| * @file result.h | ||
| * @brief Structure to hold inference results. | ||
| * @kaspersky_support D. Postnikov | ||
| * @date 16.07.2025 | ||
| * @license Apache 2.0 | ||
| * @copyright © 2025 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <knp/core/impexp.h> | ||
|
|
||
| namespace knp::framework::inference_evaluation::classification | ||
| { | ||
|
|
||
| /** | ||
| * @brief Processed inference result for single class. | ||
| */ | ||
| struct KNP_DECLSPEC InferenceResult | ||
| { | ||
| /** | ||
| * @brief Amount of times model, that is supposed to predict dog, predicted dog when it is a dog. | ||
|
artiomn marked this conversation as resolved.
|
||
| */ | ||
| size_t true_positives_ = 0; | ||
|
artiomn marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * @brief Amount of times model, that is supposed to predict dog, predicted not a dog when it is a dog. | ||
| */ | ||
| size_t false_negatives_ = 0; | ||
|
|
||
| /** | ||
| * @brief Amount of times model, that is supposed to predict dog, predicted dog when it is not a dog. | ||
| */ | ||
| size_t false_positives_ = 0; | ||
|
|
||
| /** | ||
| * @brief Amount of times model, that is supposed to predict dog, predicted not a dog when it is a not a dog. | ||
| */ | ||
| size_t true_negatives_ = 0; | ||
|
|
||
| /** | ||
| * @brief Shortcut for getting total votes. | ||
| * @return Total votes. | ||
| */ | ||
| [[nodiscard]] size_t get_total_votes() const { return true_positives_ + false_negatives_ + false_positives_; } | ||
| }; | ||
|
|
||
| } // namespace knp::framework::inference_evaluation::classification | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.