-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add face detection models and face alignment model for android (#461)
* Unify detected objects property names and reorder constructor parameters * Allow unlabeled DetectedObject instances * Add face detection models * Add face alignment model for android * fixup! Add face detection models Add a method working on ImageProxy, make NMS public. * fixup! Add face alignment model for android
- Loading branch information
1 parent
9393809
commit 484b0e8
Showing
32 changed files
with
483 additions
and
99 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
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
37 changes: 37 additions & 0 deletions
37
examples/src/main/kotlin/examples/onnx/faces/FaceDetectionWithVisualization.kt
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,37 @@ | ||
/* | ||
* Copyright 2022 JetBrains s.r.o. and Kotlin Deep Learning project contributors. All Rights Reserved. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package examples.onnx.faces | ||
|
||
import examples.transferlearning.getFileFromResource | ||
import org.jetbrains.kotlinx.dl.api.inference.loaders.ONNXModelHub | ||
import org.jetbrains.kotlinx.dl.api.inference.onnx.ONNXModels | ||
import org.jetbrains.kotlinx.dl.api.inference.onnx.executionproviders.ExecutionProvider | ||
import org.jetbrains.kotlinx.dl.api.inference.onnx.inferAndCloseUsing | ||
import org.jetbrains.kotlinx.dl.dataset.image.ImageConverter | ||
import org.jetbrains.kotlinx.dl.dataset.preprocessing.pipeline | ||
import org.jetbrains.kotlinx.dl.dataset.preprocessor.image.resize | ||
import org.jetbrains.kotlinx.dl.visualization.swing.createDetectedObjectsPanel | ||
import org.jetbrains.kotlinx.dl.visualization.swing.showFrame | ||
import java.awt.image.BufferedImage | ||
import java.io.File | ||
|
||
fun main() { | ||
val modelHub = ONNXModelHub(cacheDirectory = File("cache/pretrainedModels")) | ||
val model = ONNXModels.FaceDetection.UltraFace320.pretrainedModel(modelHub) | ||
|
||
model.inferAndCloseUsing(ExecutionProvider.CPU()) { | ||
val file = getFileFromResource("datasets/poses/multi/1.jpg") | ||
val image = ImageConverter.toBufferedImage(file) | ||
val faces = it.detectFaces(image) | ||
|
||
val width = 600 | ||
val resize = pipeline<BufferedImage>().resize { | ||
outputWidth = width | ||
outputHeight = width * image.height / image.width | ||
} | ||
showFrame("Detected Faces", createDetectedObjectsPanel(resize.apply(image), faces)) | ||
} | ||
} |
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
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
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.