Commit f017eae4 authored by Rob Schonberger's avatar Rob Schonberger Committed by Commit Bot

Add FeatureParam for Radius Polynomial, unittest thoroughly.

This CL adds a featureparam for experimental updates of radius
polynomial - and adds a parser for the string value.

The parser is tested both via the factory and as a standalone - which
is why it's placed in a separated namespace rather than the natural
anonymous namespace.

Bug: 1009290
Change-Id: I8d9edcd9c8267f6d85026f79bd30dc22cacefbc8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903108Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Commit-Queue: Rob Schonberger <robsc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713657}
parent 9efa8d66
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <utility> #include <utility>
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ui/events/ozone/evdev/event_device_info.h" #include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/touch_filter/heuristic_stylus_palm_detection_filter.h" #include "ui/events/ozone/evdev/touch_filter/heuristic_stylus_palm_detection_filter.h"
...@@ -25,6 +27,10 @@ const base::Feature kEnableHeuristicPalmDetectionFilter{ ...@@ -25,6 +27,10 @@ const base::Feature kEnableHeuristicPalmDetectionFilter{
const base::Feature kEnableNeuralPalmDetectionFilter{ const base::Feature kEnableNeuralPalmDetectionFilter{
"EnableNeuralPalmDetectionFilter", base::FEATURE_DISABLED_BY_DEFAULT}; "EnableNeuralPalmDetectionFilter", base::FEATURE_DISABLED_BY_DEFAULT};
EVENTS_OZONE_EVDEV_EXPORT
extern const base::FeatureParam<std::string> kNeuralPalmRadiusPolynomial{
&kEnableNeuralPalmDetectionFilter, "neural_palm_radius_polynomial", ""};
const base::FeatureParam<double> kHeuristicCancelThresholdSeconds{ const base::FeatureParam<double> kHeuristicCancelThresholdSeconds{
&kEnableHeuristicPalmDetectionFilter, &kEnableHeuristicPalmDetectionFilter,
"heuristic_palm_cancel_threshold_seconds", 0.4}; "heuristic_palm_cancel_threshold_seconds", 0.4};
...@@ -36,15 +42,38 @@ const base::FeatureParam<double> kHeuristicHoldThresholdSeconds{ ...@@ -36,15 +42,38 @@ const base::FeatureParam<double> kHeuristicHoldThresholdSeconds{
const base::FeatureParam<int> kHeuristicStrokeCount{ const base::FeatureParam<int> kHeuristicStrokeCount{
&kEnableHeuristicPalmDetectionFilter, "heuristic_palm_stroke_count", 0}; &kEnableHeuristicPalmDetectionFilter, "heuristic_palm_stroke_count", 0};
namespace internal {
std::vector<float> ParseRadiusPolynomial(const std::string& radius_string) {
std::vector<std::string> split_radii = base::SplitString(
radius_string, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
std::vector<float> return_value;
for (const std::string& unparsed : split_radii) {
double item;
if (!base::StringToDouble(unparsed, &item) && !std::isnan(item)) {
LOG(DFATAL) << "Unable to parse " << unparsed
<< " to a floating point; Returning empty.";
return {};
}
return_value.push_back(item);
}
return return_value;
}
} // namespace internal
std::unique_ptr<PalmDetectionFilter> CreatePalmDetectionFilter( std::unique_ptr<PalmDetectionFilter> CreatePalmDetectionFilter(
const EventDeviceInfo& devinfo, const EventDeviceInfo& devinfo,
SharedPalmDetectionFilterState* shared_palm_state) { SharedPalmDetectionFilterState* shared_palm_state) {
if (base::FeatureList::IsEnabled(kEnableNeuralPalmDetectionFilter) && if (base::FeatureList::IsEnabled(kEnableNeuralPalmDetectionFilter) &&
NeuralStylusPalmDetectionFilter:: NeuralStylusPalmDetectionFilter::
CompatibleWithNeuralStylusPalmDetectionFilter(devinfo)) { CompatibleWithNeuralStylusPalmDetectionFilter(devinfo)) {
std::vector<float> radius_polynomial =
internal::ParseRadiusPolynomial(kNeuralPalmRadiusPolynomial.Get());
// Theres only one model right now. // Theres only one model right now.
std::unique_ptr<NeuralStylusPalmDetectionFilterModel> model = std::unique_ptr<NeuralStylusPalmDetectionFilterModel> model =
std::make_unique<OneDeviceTrainNeuralStylusPalmDetectionFilterModel>(); std::make_unique<OneDeviceTrainNeuralStylusPalmDetectionFilterModel>(
radius_polynomial);
return std::make_unique<NeuralStylusPalmDetectionFilter>( return std::make_unique<NeuralStylusPalmDetectionFilter>(
devinfo, std::move(model), shared_palm_state); devinfo, std::move(model), shared_palm_state);
} }
......
...@@ -24,6 +24,9 @@ extern const base::Feature kEnableHeuristicPalmDetectionFilter; ...@@ -24,6 +24,9 @@ extern const base::Feature kEnableHeuristicPalmDetectionFilter;
EVENTS_OZONE_EVDEV_EXPORT EVENTS_OZONE_EVDEV_EXPORT
extern const base::Feature kEnableNeuralPalmDetectionFilter; extern const base::Feature kEnableNeuralPalmDetectionFilter;
EVENTS_OZONE_EVDEV_EXPORT
extern const base::FeatureParam<std::string> kNeuralPalmRadiusPolynomial;
EVENTS_OZONE_EVDEV_EXPORT EVENTS_OZONE_EVDEV_EXPORT
extern const base::FeatureParam<double> kHeuristicCancelThresholdSeconds; extern const base::FeatureParam<double> kHeuristicCancelThresholdSeconds;
...@@ -37,6 +40,13 @@ EVENTS_OZONE_EVDEV_EXPORT std::unique_ptr<PalmDetectionFilter> ...@@ -37,6 +40,13 @@ EVENTS_OZONE_EVDEV_EXPORT std::unique_ptr<PalmDetectionFilter>
CreatePalmDetectionFilter(const EventDeviceInfo& devinfo, CreatePalmDetectionFilter(const EventDeviceInfo& devinfo,
SharedPalmDetectionFilterState* shared_palm_state); SharedPalmDetectionFilterState* shared_palm_state);
namespace internal {
// In a named namespace for testing.
EVENTS_OZONE_EVDEV_EXPORT std::vector<float> ParseRadiusPolynomial(
const std::string& radius_string);
} // namespace internal
} // namespace ui } // namespace ui
#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_FACTORY_H_ #endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_FACTORY_H_
...@@ -42,6 +42,9 @@ class PalmDetectionFilterFactoryTest : public testing::Test { ...@@ -42,6 +42,9 @@ class PalmDetectionFilterFactoryTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(PalmDetectionFilterFactoryTest); DISALLOW_COPY_AND_ASSIGN(PalmDetectionFilterFactoryTest);
}; };
class PalmDetectionFilterFactoryDeathTest
: public PalmDetectionFilterFactoryTest {};
TEST_F(PalmDetectionFilterFactoryTest, AllDisabled) { TEST_F(PalmDetectionFilterFactoryTest, AllDisabled) {
scoped_feature_list_->InitWithFeatures( scoped_feature_list_->InitWithFeatures(
{}, {ui::kEnableHeuristicPalmDetectionFilter, {}, {ui::kEnableHeuristicPalmDetectionFilter,
...@@ -114,4 +117,32 @@ TEST_F(PalmDetectionFilterFactoryTest, NeuralBeatsHeuristic) { ...@@ -114,4 +117,32 @@ TEST_F(PalmDetectionFilterFactoryTest, NeuralBeatsHeuristic) {
ASSERT_EQ(NeuralStylusPalmDetectionFilter::kFilterName, ASSERT_EQ(NeuralStylusPalmDetectionFilter::kFilterName,
palm_filter->FilterNameForTesting()); palm_filter->FilterNameForTesting());
} }
TEST_F(PalmDetectionFilterFactoryTest, ParseTest) {
EXPECT_EQ(std::vector<float>(), internal::ParseRadiusPolynomial(""));
// Note we test for whitespace trimming.
EXPECT_EQ(std::vector<float>({3.7, 2.91, 15.19191}),
internal::ParseRadiusPolynomial("3.7, 2.91, 15.19191 "));
}
TEST_F(PalmDetectionFilterFactoryDeathTest, BadParseRecovery) {
// in debug, die. In non debug, expect {}
EXPECT_DEBUG_DEATH(EXPECT_EQ(std::vector<float>(),
internal::ParseRadiusPolynomial("cheese")),
"Unable to parse.*cheese");
}
TEST_F(PalmDetectionFilterFactoryDeathTest, BadNeuralParamParse) {
scoped_feature_list_->InitWithFeaturesAndParameters(
{base::test::ScopedFeatureList::FeatureAndParams(
ui::kEnableNeuralPalmDetectionFilter,
{
{"neural_palm_radius_polynomial", "1.0,chicken"},
})},
{ui::kEnableHeuristicPalmDetectionFilter});
EXPECT_DEBUG_DEATH(CreatePalmDetectionFilter(nocturne_touchscreen_info_,
&shared_palm_state_),
"Unable to parse.*chicken");
}
} // namespace ui } // namespace ui
...@@ -59,4 +59,11 @@ OneDeviceTrainNeuralStylusPalmDetectionFilterModel:: ...@@ -59,4 +59,11 @@ OneDeviceTrainNeuralStylusPalmDetectionFilterModel::
config_.heuristic_palm_area_limit = 400.0f; config_.heuristic_palm_area_limit = 400.0f;
} }
OneDeviceTrainNeuralStylusPalmDetectionFilterModel::
OneDeviceTrainNeuralStylusPalmDetectionFilterModel(
const std::vector<float>& radius_poly)
: OneDeviceTrainNeuralStylusPalmDetectionFilterModel() {
config_.radius_polynomial_resize = radius_poly;
}
} // namespace ui } // namespace ui
...@@ -20,7 +20,8 @@ class EVENTS_OZONE_EVDEV_EXPORT ...@@ -20,7 +20,8 @@ class EVENTS_OZONE_EVDEV_EXPORT
: public NeuralStylusPalmDetectionFilterModel { : public NeuralStylusPalmDetectionFilterModel {
public: public:
OneDeviceTrainNeuralStylusPalmDetectionFilterModel(); OneDeviceTrainNeuralStylusPalmDetectionFilterModel();
explicit OneDeviceTrainNeuralStylusPalmDetectionFilterModel(
const std::vector<float>& radius_poly);
float Inference(const std::vector<float>& features) const override; float Inference(const std::vector<float>& features) const override;
const NeuralStylusPalmDetectionFilterModelConfig& config() const override; const NeuralStylusPalmDetectionFilterModelConfig& config() const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment