forked from googlesamples/mlkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List of included changes imported by Copybara:
- Android: add a kNN-based pose classification example to vision quickstart app - Android: add selfie segmentation to vision quickstart app - Android: update README for pose classifier and selfie segmentation PiperOrigin-RevId: 359365704 Change-Id: I252773fa58f2b6dcbaf20dccc1f4af697a57135c
- Loading branch information
Google ML Kit
authored and
Chengji Yan
committed
Feb 26, 2021
1 parent
5a5e92e
commit ae9032e
Showing
29 changed files
with
2,312 additions
and
116 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
812 changes: 812 additions & 0 deletions
812
android/vision-quickstart/app/src/main/assets/pose/fitness_pose_samples.csv
Large diffs are not rendered by default.
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
61 changes: 61 additions & 0 deletions
61
...a/com/google/mlkit/vision/demo/java/posedetector/classification/ClassificationResult.java
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,61 @@ | ||
/* | ||
* Copyright 2020 Google LLC. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.google.mlkit.vision.demo.java.posedetector.classification; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static java.util.Collections.max; | ||
|
||
/** | ||
* Represents Pose classification result as outputted by {@link PoseClassifier}. Can be manipulated. | ||
*/ | ||
public class ClassificationResult { | ||
// For an entry in this map, the key is the class name, and the value is how many times this class | ||
// appears in the top K nearest neighbors. The value is in range [0, K] and could be a float after | ||
// EMA smoothing. We use this number to represent the confidence of a pose being in this class. | ||
private final Map<String, Float> classConfidences; | ||
|
||
public ClassificationResult() { | ||
classConfidences = new HashMap<>(); | ||
} | ||
|
||
public Set<String> getAllClasses() { | ||
return classConfidences.keySet(); | ||
} | ||
|
||
public float getClassConfidence(String className) { | ||
return classConfidences.containsKey(className) ? classConfidences.get(className) : 0; | ||
} | ||
|
||
public String getMaxConfidenceClass() { | ||
return max( | ||
classConfidences.entrySet(), | ||
(entry1, entry2) -> (int) (entry1.getValue() - entry2.getValue())) | ||
.getKey(); | ||
} | ||
|
||
public void incrementClassConfidence(String className) { | ||
classConfidences.put(className, | ||
classConfidences.containsKey(className) ? classConfidences.get(className) + 1 : 1); | ||
} | ||
|
||
public void putClassConfidence(String className, float confidence) { | ||
classConfidences.put(className, confidence); | ||
} | ||
} |
Oops, something went wrong.