Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cpp/OcvDnnDetection/OcvDnnDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,29 @@ std::string getFeedForwardExcludeBehavior(const MPFJob &job, const Properties &f
if (feed_forward_props_iter != feed_forward_props.end()) {
const std::string &class_name = feed_forward_props_iter->second;

std::string feed_forward_whitelist_file =
DetectionComponentUtils::GetProperty(job.job_properties, "FEED_FORWARD_WHITELIST_FILE", "");
std::string feed_forward_allow_list_file =
DetectionComponentUtils::GetProperty(job.job_properties, "FEED_FORWARD_ALLOW_LIST_FILE", "");

if (!feed_forward_whitelist_file.empty()) {
if (!feed_forward_allow_list_file.empty()) {
std::string expanded_file_path;
std::string error = Utils::expandFileName(feed_forward_whitelist_file, expanded_file_path);
std::string error = Utils::expandFileName(feed_forward_allow_list_file, expanded_file_path);

if (!error.empty()) {
throw MPFInvalidPropertyException(
"FEED_FORWARD_WHITELIST_FILE",
"The value, \"" + feed_forward_whitelist_file + "\", could not be expanded due to: " + error);
"FEED_FORWARD_ALLOW_LIST_FILE",
"The value, \"" + feed_forward_allow_list_file + "\", could not be expanded due to: " + error);
}

std::ifstream whitelist_file(expanded_file_path);
if (!whitelist_file.good()) {
std::ifstream allow_list_file(expanded_file_path);
if (!allow_list_file.good()) {
throw MPFDetectionException(
MPF_COULD_NOT_OPEN_DATAFILE,
"Failed to load feed-forward class whitelist that was supposed to be located at \""
"Failed to load feed-forward class allow list that was supposed to be located at \""
+ expanded_file_path + "\".");
}

std::string line;
while (std::getline(whitelist_file, line)) {
while (std::getline(allow_list_file, line)) {
Utils::trim(line);
if (boost::iequals(line, class_name)) {
return "";
Expand Down
4 changes: 2 additions & 2 deletions cpp/OcvDnnDetection/plugin-files/descriptor/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@
"defaultValue": "CLASSIFICATION"
},
{
"name": "FEED_FORWARD_WHITELIST_FILE",
"name": "FEED_FORWARD_ALLOW_LIST_FILE",
"description": "When FEED_FORWARD_TYPE is provided and not set to NONE, only feed-forward detections with class names contained in the specified file will be processed. If no file is specified, all of the detections will be processed.",
"type": "STRING",
"defaultValue": ""
},
{
"name": "FEED_FORWARD_EXCLUDE_BEHAVIOR",
"description": "When FEED_FORWARD_TYPE is provided and not set to NONE, and FEED_FORWARD_WHITELIST_FILE is provided, this value determines what to do with feed-forward detections with class names not contained in the FEED_FORWARD_WHITELIST_FILE. Acceptable values are PASS_THROUGH and DROP.",
"description": "When FEED_FORWARD_TYPE is provided and not set to NONE, and FEED_FORWARD_ALLOW_LIST_FILE is provided, this value determines what to do with feed-forward detections with class names not contained in the FEED_FORWARD_ALLOW_LIST_FILE. Acceptable values are PASS_THROUGH and DROP.",
"type": "STRING",
"defaultValue": "PASS_THROUGH"
},
Expand Down
2 changes: 1 addition & 1 deletion cpp/OcvDnnDetection/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ if (${GTEST_FOUND})
# Install test images, videos, and other files
file(GLOB OCVDNN_TEST_FILES data/*)
file(COPY ${OCVDNN_TEST_FILES} DESTINATION data)
file(COPY vehicle-whitelist.txt DESTINATION .)
file(COPY vehicle-allow-list.txt DESTINATION .)
endif()
4 changes: 2 additions & 2 deletions cpp/OcvDnnDetection/test/test_ocv_dnn_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ TEST(OCVDNN, FeedForwardImageTest) {
Properties props = getVehicleColorProperties();
props["CLASSIFICATION_TYPE"] = classification_type;
props["FEED_FORWARD_TYPE"] = "FRAME";
props["FEED_FORWARD_WHITELIST_FILE"] = "vehicle-whitelist.txt";
props["FEED_FORWARD_ALLOW_LIST_FILE"] = "vehicle-allow-list.txt";

// Test feed-forward person pass-through

Expand Down Expand Up @@ -311,7 +311,7 @@ TEST(OCVDNN, FeedForwardVideoTest) {
Properties props = getVehicleColorProperties();
props["CLASSIFICATION_TYPE"] = classification_type;
props["FEED_FORWARD_TYPE"] = "FRAME";
props["FEED_FORWARD_WHITELIST_FILE"] = "vehicle-whitelist.txt";
props["FEED_FORWARD_ALLOW_LIST_FILE"] = "vehicle-allow-list.txt";

// Test feed-forward vehicle processing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* limitations under the License. *
******************************************************************************/

#include "WhitelistFilter.h"
#include "AllowListFilter.h"

#include <fstream>

Expand All @@ -37,65 +37,65 @@ using namespace MPF::COMPONENT;

namespace {

std::unordered_set<std::string> LoadWhitelist(
const std::string &whiteListPath, const std::vector<std::string> &names) {
std::unordered_set<std::string> LoadAllowlist(
const std::string &allowListPath, const std::vector<std::string> &names) {
std::string expandedFilePath;
std::string error = Utils::expandFileName(whiteListPath, expandedFilePath);
std::string error = Utils::expandFileName(allowListPath, expandedFilePath);
if (!error.empty()) {
throw MPFInvalidPropertyException(
"CLASS_WHITELIST_FILE",
"The value, \"" + whiteListPath + "\", could not be expanded due to: "
"CLASS_ALLOW_LIST_FILE",
"The value, \"" + allowListPath + "\", could not be expanded due to: "
+ error);
}

std::ifstream whitelistFile(expandedFilePath);
if (!whitelistFile.good()) {
std::ifstream allowListFile(expandedFilePath);
if (!allowListFile.good()) {
throw MPFDetectionException(
MPF_COULD_NOT_OPEN_DATAFILE,
"Failed to load class whitelist that was supposed to be located at \""
"Failed to load class allow list that was supposed to be located at \""
+ expandedFilePath + "\".");
}

std::unordered_set<std::string> tempWhitelist;
std::unordered_set<std::string> tempAllowList;
std::string line;
while (std::getline(whitelistFile, line)) {
while (std::getline(allowListFile, line)) {
Utils::trim(line);
if (!line.empty()) {
tempWhitelist.insert(std::move(line));
tempAllowList.insert(std::move(line));
line = "";
}
}

if (tempWhitelist.empty()) {
if (tempAllowList.empty()) {
throw MPFDetectionException(
MPF_COULD_NOT_READ_DATAFILE,
"The class whitelist file located at \"" + expandedFilePath + "\" was empty.");
"The class allow list file located at \"" + expandedFilePath + "\" was empty.");
}

std::unordered_set<std::string> whitelist;
std::unordered_set<std::string> allowList;
for (const std::string &name: names) {
if (tempWhitelist.count(name) > 0) {
whitelist.insert(name);
if (tempAllowList.count(name) > 0) {
allowList.insert(name);
}
}

if (whitelist.empty()) {
if (allowList.empty()) {
throw MPFDetectionException(
MPF_COULD_NOT_READ_DATAFILE,
"None of the class names specified in the whitelist file located at \""
"None of the class names specified in the allow list file located at \""
+ expandedFilePath + "\" were found in the names file.");
}
return whitelist;
return allowList;
}
}


WhitelistFilter::WhitelistFilter(const std::string &whiteListPath,
AllowListFilter::AllowListFilter(const std::string &allowListPath,
const std::vector<std::string> &names)
: whitelist_(LoadWhitelist(whiteListPath, names)) {
: allowList_(LoadAllowlist(allowListPath, names)) {
}


bool WhitelistFilter::operator()(const std::string &className) {
return whitelist_.count(className) > 0;
bool AllowListFilter::operator()(const std::string &className) const {
return allowList_.count(className) > 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@
* limitations under the License. *
******************************************************************************/

#ifndef OPENMPF_COMPONENTS_WHITELISTFILTER_H
#define OPENMPF_COMPONENTS_WHITELISTFILTER_H
#ifndef OPENMPF_COMPONENTS_ALLOWLISTFILTER_H
#define OPENMPF_COMPONENTS_ALLOWLISTFILTER_H

#include <string>
#include <unordered_set>
#include <vector>


class WhitelistFilter {
class AllowListFilter {
public:
WhitelistFilter(const std::string &whiteListPath, const std::vector<std::string> &names);
AllowListFilter(const std::string &allowListPath, const std::vector<std::string> &names);

bool operator()(const std::string &className);
bool operator()(const std::string &className) const;

private:
std::unordered_set<std::string> whitelist_;
std::unordered_set<std::string> allowList_;
};


#endif //OPENMPF_COMPONENTS_WHITELISTFILTER_H
#endif //OPENMPF_COMPONENTS_ALLOWLISTFILTER_H
2 changes: 1 addition & 1 deletion cpp/OcvYoloDetection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ set(COMMON_OCV_YOLO_DETECTION_SOURCE_FILES
KFTracker.cpp KFTracker.h
OcvYoloDetection.cpp OcvYoloDetection.h
ocv_phasecorr.cpp ocv_phasecorr.h
WhitelistFilter.cpp WhitelistFilter.h
AllowListFilter.cpp AllowListFilter.h
yolo_network/BaseYoloNetworkImpl.cpp yolo_network/BaseYoloNetworkImpl.h)

set(LOCAL_OCV_YOLO_DETECTION_SOURCE_FILES
Expand Down
4 changes: 2 additions & 2 deletions cpp/OcvYoloDetection/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Config::Config(const Properties &jobProps)
GetProperty(jobProps, "KF_QN", "[ 1000.0, 1000.0, 1000.0, 1000.0 ]")))
, fallback2CpuWhenGpuProblem(GetProperty(jobProps, "FALLBACK_TO_CPU_WHEN_GPU_PROBLEM", false))
, cudaDeviceId(GetProperty(jobProps, "CUDA_DEVICE_ID", -1))
, classWhiteListPath(GetProperty(jobProps, "CLASS_WHITELIST_FILE", ""))
, classAllowListPath(GetProperty(jobProps, "CLASS_ALLOW_LIST_FILE", ""))
, enableDebug(GetProperty(jobProps, "ENABLE_DEBUG", false))
, tritonEnabled(GetProperty(jobProps, "ENABLE_TRITON", false))
, tritonServer(GetProperty(jobProps, "TRITON_SERVER", "ocv-yolo-detection-server:8001"))
Expand Down Expand Up @@ -116,7 +116,7 @@ std::ostream &operator<<(std::ostream &out, const Config &cfg) {
<< "\"mosseTrackerDisabled\":" << (cfg.mosseTrackerDisabled ? "1" : "0") << ","
<< "\"fallback2CpuWhenGpuProblem\":" << (cfg.fallback2CpuWhenGpuProblem ? "1" : "0") << ","
<< "\"cudaDeviceId\":" << cfg.cudaDeviceId << ","
<< "\"classWhiteListPath\":" << cfg.classWhiteListPath << ","
<< "\"classAllowListPath\":" << cfg.classAllowListPath << ","
<< "\"enabledDebug\":" << cfg.enableDebug << ","
<< "\"tritonServer\":" << cfg.tritonModelVersion << ","
<< "\"tritonModelName\":" << cfg.tritonModelName << ","
Expand Down
2 changes: 1 addition & 1 deletion cpp/OcvYoloDetection/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Config {
/// gpu device id to use for cuda
int cudaDeviceId;

std::string classWhiteListPath;
std::string classAllowListPath;

bool enableDebug;

Expand Down
14 changes: 7 additions & 7 deletions cpp/OcvYoloDetection/plugin-files/descriptor/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"defaultValue": "5"
},
{
"name": "CLASS_WHITELIST_FILE",
"name": "CLASS_ALLOW_LIST_FILE",
"description": "When provided, only class names contained in the specified file will be reported.",
"type": "STRING",
"defaultValue": ""
Expand Down Expand Up @@ -269,8 +269,8 @@
"value": "416"
},
{
"name": "CLASS_WHITELIST_FILE",
"value": "$MPF_HOME/plugins/OcvYoloDetection/models/vehicle-whitelist.txt"
"name": "CLASS_ALLOW_LIST_FILE",
"value": "$MPF_HOME/plugins/OcvYoloDetection/models/vehicle-allow-list.txt"
}
]
},
Expand Down Expand Up @@ -303,8 +303,8 @@
"value": "608"
},
{
"name": "CLASS_WHITELIST_FILE",
"value": "$MPF_HOME/plugins/OcvYoloDetection/models/vehicle-whitelist.txt"
"name": "CLASS_ALLOW_LIST_FILE",
"value": "$MPF_HOME/plugins/OcvYoloDetection/models/vehicle-allow-list.txt"
}
]
},
Expand Down Expand Up @@ -341,8 +341,8 @@
"value": "608"
},
{
"name": "CLASS_WHITELIST_FILE",
"value": "$MPF_HOME/plugins/OcvYoloDetection/models/vehicle-whitelist.txt"
"name": "CLASS_ALLOW_LIST_FILE",
"value": "$MPF_HOME/plugins/OcvYoloDetection/models/vehicle-allow-list.txt"
},
{
"name": "ENABLE_TRITON",
Expand Down
8 changes: 4 additions & 4 deletions cpp/OcvYoloDetection/test/test_ocv_local_yolo_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ TEST_F(OcvLocalYoloDetectionTestFixture, TestInvalidModel) {
}


TEST_F(OcvLocalYoloDetectionTestFixture, TestWhitelist) {
TEST_F(OcvLocalYoloDetectionTestFixture, TestAllowList) {
Properties jobProps = getTinyYoloConfig();
auto component = initComponent();

{
jobProps["CLASS_WHITELIST_FILE"] = "data/test-whitelist.txt";
jobProps["CLASS_ALLOW_LIST_FILE"] = "data/test-allow-list.txt";
MPFImageJob job("Test", "data/dog.jpg", jobProps, {});

std::vector<MPFImageLocation> results = component.GetDetections(job);
Expand All @@ -274,8 +274,8 @@ TEST_F(OcvLocalYoloDetectionTestFixture, TestWhitelist) {
{
int end_frame = 2;
setenv("TEST_ENV_VAR", "data", true);
setenv("TEST_ENV_VAR2", "whitelist", true);
jobProps["CLASS_WHITELIST_FILE"] = "$TEST_ENV_VAR/test-${TEST_ENV_VAR2}.txt";
setenv("TEST_ENV_VAR2", "allow-list", true);
jobProps["CLASS_ALLOW_LIST_FILE"] = "$TEST_ENV_VAR/test-${TEST_ENV_VAR2}.txt";

MPFVideoJob job("Test", "data/lp-ferrari-texas-shortened.mp4", 0, end_frame, jobProps, {});

Expand Down
14 changes: 7 additions & 7 deletions cpp/OcvYoloDetection/yolo_network/BaseYoloNetworkImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "../Config.h"
#include "../Frame.h"
#include "YoloNetwork.h"
#include "../WhitelistFilter.h"
#include "../AllowListFilter.h"

#include "BaseYoloNetworkImpl.h"

Expand Down Expand Up @@ -215,11 +215,11 @@ namespace {


std::function<bool(const std::string &)> GetClassFilter(
const std::string &whiteListPath, const std::vector<std::string> &names) {
if (whiteListPath.empty()) {
const std::string &allowListPath, const std::vector<std::string> &names) {
if (allowListPath.empty()) {
return [](const std::string &) { return true; };
} else {
return WhitelistFilter(whiteListPath, names);
return AllowListFilter(allowListPath, names);
}
}

Expand Down Expand Up @@ -278,8 +278,8 @@ BaseYoloNetworkImpl::BaseYoloNetworkImpl(ModelSettings model_settings, const Con
net_(config.tritonEnabled ? cv::dnn::Net() : LoadNetwork(modelSettings_, cudaDeviceId_, log_)),
names_(LoadNames(net_, modelSettings_, config)),
confusionMatrix_(LoadConfusionMatrix(modelSettings_.confusionMatrixFile, names_.size())),
classWhiteListPath_(config.classWhiteListPath),
classFilter_(GetClassFilter(classWhiteListPath_, names_)) {}
classAllowListPath_(config.classAllowListPath),
classFilter_(GetClassFilter(classAllowListPath_, names_)) {}

BaseYoloNetworkImpl::~BaseYoloNetworkImpl() = default;

Expand All @@ -297,7 +297,7 @@ bool BaseYoloNetworkImpl::IsCompatible(const ModelSettings &modelSettings, const
&& modelSettings_.namesFile == modelSettings.namesFile
&& modelSettings_.confusionMatrixFile == modelSettings.confusionMatrixFile
&& config.cudaDeviceId == cudaDeviceId_
&& config.classWhiteListPath == classWhiteListPath_;
&& config.classAllowListPath == classAllowListPath_;
}

void BaseYoloNetworkImpl::Finish() {}
Expand Down
2 changes: 1 addition & 1 deletion cpp/OcvYoloDetection/yolo_network/BaseYoloNetworkImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class BaseYoloNetworkImpl {

std::vector<std::string> names_;
cv::Mat1f confusionMatrix_;
std::string classWhiteListPath_;
std::string classAllowListPath_;
std::function<bool(const std::string &)> classFilter_;

std::vector<std::vector<DetectionLocation>> GetDetectionsCvdnn(
Expand Down
4 changes: 2 additions & 2 deletions cpp/OcvYoloDetection/yolo_network/TritonYoloNetworkImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ class YoloNetwork::YoloNetworkImpl : public BaseYoloNetworkImpl {
// common settings with local yolo network
&& modelSettings_.namesFile == modelSettings.namesFile
&& modelSettings_.confusionMatrixFile == modelSettings.confusionMatrixFile
&& config.classWhiteListPath == classWhiteListPath_;
&& config.classAllowListPath == classAllowListPath_;
} else {
return !tritonInferencer_
&& modelSettings_.ocvDnnNetworkConfigFile == modelSettings.ocvDnnNetworkConfigFile
&& modelSettings_.ocvDnnWeightsFile == modelSettings.ocvDnnWeightsFile
&& modelSettings_.namesFile == modelSettings.namesFile
&& modelSettings_.confusionMatrixFile == modelSettings.confusionMatrixFile
&& config.cudaDeviceId == cudaDeviceId_
&& config.classWhiteListPath == classWhiteListPath_;
&& config.classAllowListPath == classAllowListPath_;
}
}

Expand Down