-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: reduce allocations for FaceDetector (#1082)
* perf: avoid/reduce allocations * perf: optimize AssertStatusOk * perf: use ReadOnlySpan to deserialize proto message * perf: use stack to build a proto Packet * perf: avoid Reflection * refactor: DetectionResult.Empty * refactor: reuse NormalizedRect * perf: deserialize as List<Detection> faster * perf: avoid allocation when building DetectionResult * refactor: remove unused using statements * perf: reduce allocation on IMAGE mode * perf: reduce allocation on VIDEO mode * remove unnecessary directives
- Loading branch information
Showing
22 changed files
with
480 additions
and
151 deletions.
There are no files selected for viewing
This file contains 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 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
8 changes: 8 additions & 0 deletions
8
Packages/com.github.homuler.mediapipe/Runtime/Scripts/Extension.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
...ages/com.github.homuler.mediapipe/Runtime/Scripts/Extension/ProtoMessageClearExtension.cs
This file contains 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,48 @@ | ||
// Copyright (c) 2023 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
namespace Mediapipe | ||
{ | ||
public static class ProtoMessageClearExtension | ||
{ | ||
public static void Clear(this Detection detection) | ||
{ | ||
detection.Label.Clear(); | ||
detection.LabelId.Clear(); | ||
detection.Score.Clear(); | ||
|
||
detection.LocationData.ClearFormat(); | ||
if (detection.LocationData.BoundingBox != null) | ||
{ | ||
detection.LocationData.BoundingBox.ClearXmin(); | ||
detection.LocationData.BoundingBox.ClearYmin(); | ||
detection.LocationData.BoundingBox.ClearWidth(); | ||
detection.LocationData.BoundingBox.ClearHeight(); | ||
} | ||
if (detection.LocationData.RelativeBoundingBox != null) | ||
{ | ||
detection.LocationData.RelativeBoundingBox.ClearXmin(); | ||
detection.LocationData.RelativeBoundingBox.ClearYmin(); | ||
detection.LocationData.RelativeBoundingBox.ClearWidth(); | ||
detection.LocationData.RelativeBoundingBox.ClearHeight(); | ||
} | ||
if (detection.LocationData.Mask != null) | ||
{ | ||
detection.LocationData.Mask.ClearWidth(); | ||
detection.LocationData.Mask.ClearHeight(); | ||
detection.LocationData.Mask.Rasterization.Interval.Clear(); | ||
} | ||
detection.LocationData.RelativeKeypoints.Clear(); | ||
|
||
detection.ClearFeatureTag(); | ||
detection.ClearTrackId(); | ||
detection.ClearDetectionId(); | ||
detection.AssociatedDetections.Clear(); | ||
detection.DisplayName.Clear(); | ||
detection.ClearTimestampUsec(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...com.github.homuler.mediapipe/Runtime/Scripts/Extension/ProtoMessageClearExtension.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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
Oops, something went wrong.