-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
308 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,7 @@ services: | |
reservations: | ||
devices: | ||
- capabilities: [gpu] | ||
|
||
networks: | ||
default: | ||
name: face_devcontainer_default |
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,46 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/dev6699/face/client" | ||
"github.com/dev6699/face/examples" | ||
"github.com/dev6699/face/model" | ||
_2dfan4 "github.com/dev6699/face/model/2dfan4" | ||
"github.com/dev6699/face/model/yoloface" | ||
"gocv.io/x/gocv" | ||
) | ||
|
||
func main() { | ||
faceDetectorScore := float32(0.5) | ||
iouThreshold := 0.4 | ||
yolofaceFactory := yoloface.NewFactory(faceDetectorScore, iouThreshold) | ||
_2dfan4Factory := _2dfan4.NewFactory() | ||
err := client.Init( | ||
"tritonserver:8001", | ||
[]model.ModelMeta{ | ||
yolofaceFactory(), | ||
_2dfan4Factory(), | ||
}, | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
img := gocv.IMRead("../image.jpg", gocv.IMReadColor) | ||
yoloFaceOutput, err := client.Infer(yolofaceFactory, &yoloface.Input{Img: img}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for _, d := range yoloFaceOutput.Detections { | ||
fanOutput, err := client.Infer(_2dfan4Factory, &_2dfan4.Input{Img: img, BoundingBox: d.BoundingBox}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
examples.DrawPoints(&img, fanOutput.FaceLandmark68.Data, examples.Red, 2) | ||
} | ||
|
||
gocv.IMWrite("output.jpg", img) | ||
} |
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,52 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/dev6699/face/client" | ||
"github.com/dev6699/face/model" | ||
"github.com/dev6699/face/model/arcface" | ||
"github.com/dev6699/face/model/yoloface" | ||
"gocv.io/x/gocv" | ||
) | ||
|
||
func main() { | ||
faceDetectorScore := float32(0.5) | ||
iouThreshold := 0.4 | ||
yolofaceFactory := yoloface.NewFactory(faceDetectorScore, iouThreshold) | ||
arcfaceFactory := arcface.NewFactory() | ||
err := client.Init( | ||
"tritonserver:8001", | ||
[]model.ModelMeta{ | ||
yolofaceFactory(), | ||
arcfaceFactory(), | ||
}, | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
img := gocv.IMRead("../image.jpg", gocv.IMReadColor) | ||
yoloFaceOutput, err := client.Infer(yolofaceFactory, &yoloface.Input{Img: img}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
faceEmbeddings := [][]float32{} | ||
for _, d := range yoloFaceOutput.Detections { | ||
arcfaceOutput, err := client.Infer(arcfaceFactory, &arcface.Input{Img: img, FaceLandmark5: d.FaceLandmark5}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
faceEmbeddings = append(faceEmbeddings, arcfaceOutput.NormedEmbedding) | ||
} | ||
|
||
similarDistance := 0.6 | ||
for i, f1 := range faceEmbeddings { | ||
for j, f2 := range faceEmbeddings { | ||
faceDistance := model.CalcFaceDistance(f1, f2) | ||
isSimilar := faceDistance < similarDistance | ||
fmt.Printf("Face %d & %d: %.2f %v\n", i, j, faceDistance, isSimilar) | ||
} | ||
} | ||
} |
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,51 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/dev6699/face/client" | ||
"github.com/dev6699/face/examples" | ||
"github.com/dev6699/face/model" | ||
"github.com/dev6699/face/model/genderage" | ||
"github.com/dev6699/face/model/yoloface" | ||
"gocv.io/x/gocv" | ||
) | ||
|
||
func main() { | ||
faceDetectorScore := float32(0.5) | ||
iouThreshold := 0.4 | ||
yolofaceFactory := yoloface.NewFactory(faceDetectorScore, iouThreshold) | ||
genderAgeFactory := genderage.NewFactory() | ||
err := client.Init( | ||
"tritonserver:8001", | ||
[]model.ModelMeta{ | ||
yolofaceFactory(), | ||
genderAgeFactory(), | ||
}, | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
img := gocv.IMRead("../image.jpg", gocv.IMReadColor) | ||
yoloFaceOutput, err := client.Infer(yolofaceFactory, &yoloface.Input{Img: img}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for _, d := range yoloFaceOutput.Detections { | ||
genderAgeOutput, err := client.Infer(genderAgeFactory, &genderage.Input{Img: img, BoundingBox: d.BoundingBox}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
genderString := "M" | ||
if genderAgeOutput.Gender == 0 { | ||
genderString = "F" | ||
} | ||
examples.DrawBoundingBoxes(&img, d.BoundingBox, fmt.Sprintf("%s %d", genderString, genderAgeOutput.Age), examples.Green, examples.Red) | ||
} | ||
|
||
gocv.IMWrite("output.jpg", img) | ||
} |
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,43 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/dev6699/face/client" | ||
"github.com/dev6699/face/model" | ||
"github.com/dev6699/face/model/gfpgan" | ||
"github.com/dev6699/face/model/yoloface" | ||
"gocv.io/x/gocv" | ||
) | ||
|
||
func main() { | ||
faceDetectorScore := float32(0.5) | ||
iouThreshold := 0.4 | ||
yolofaceFactory := yoloface.NewFactory(faceDetectorScore, iouThreshold) | ||
gfpganFactory := gfpgan.NewFactory(80.0) | ||
err := client.Init( | ||
"tritonserver:8001", | ||
[]model.ModelMeta{ | ||
yolofaceFactory(), | ||
gfpganFactory(), | ||
}, | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
img := gocv.IMRead("../image.jpg", gocv.IMReadColor) | ||
yoloFaceOutput, err := client.Infer(yolofaceFactory, &yoloface.Input{Img: img}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for i, d := range yoloFaceOutput.Detections { | ||
gfpganOutput, err := client.Infer(gfpganFactory, &gfpgan.Input{Img: img, FaceLandmark5: d.FaceLandmark5}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
gocv.IMWrite(fmt.Sprintf("output%d.jpg", i+1), gfpganOutput.OutFrame) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,26 @@ | ||
package examples | ||
|
||
import ( | ||
"image" | ||
"image/color" | ||
|
||
"github.com/dev6699/face/model" | ||
"gocv.io/x/gocv" | ||
) | ||
|
||
var ( | ||
Red = color.RGBA{R: 255, G: 0, B: 0, A: 255} | ||
Green = color.RGBA{R: 0, G: 255, B: 0, A: 255} | ||
Blue = color.RGBA{R: 0, G: 0, B: 255, A: 255} | ||
) | ||
|
||
func DrawBoundingBoxes(img *gocv.Mat, box model.BoundingBox, text string, boxColor, textColor color.RGBA) { | ||
gocv.Rectangle(img, image.Rectangle{Min: image.Point{X: int(box.X1), Y: int(box.Y1)}, Max: image.Point{X: int(box.X2), Y: int(box.Y2)}}, boxColor, 2) | ||
gocv.PutText(img, text, image.Point{X: int(box.X1), Y: int(box.Y1) - 5}, gocv.FontHersheySimplex, 0.5, textColor, 2) | ||
} | ||
|
||
func DrawPoints(img *gocv.Mat, points []gocv.Point2f, col color.RGBA, radius int) { | ||
for _, pt := range points { | ||
gocv.Circle(img, image.Pt(int(pt.X), int(pt.Y)), radius, col, -1) | ||
} | ||
} |
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,40 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/dev6699/face/client" | ||
"github.com/dev6699/face/examples" | ||
"github.com/dev6699/face/model" | ||
"github.com/dev6699/face/model/yoloface" | ||
"gocv.io/x/gocv" | ||
) | ||
|
||
func main() { | ||
faceDetectorScore := float32(0.5) | ||
iouThreshold := 0.4 | ||
yolofaceFactory := yoloface.NewFactory(faceDetectorScore, iouThreshold) | ||
err := client.Init( | ||
"tritonserver:8001", | ||
[]model.ModelMeta{ | ||
yolofaceFactory(), | ||
}, | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
img := gocv.IMRead("../image.jpg", gocv.IMReadColor) | ||
yoloFaceOutput, err := client.Infer(yolofaceFactory, &yoloface.Input{Img: img}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for _, d := range yoloFaceOutput.Detections { | ||
examples.DrawBoundingBoxes(&img, d.BoundingBox, fmt.Sprintf("Score: %.2f", d.Confidence), examples.Green, examples.Green) | ||
examples.DrawPoints(&img, d.FaceLandmark5, examples.Red, 3) | ||
} | ||
|
||
gocv.IMWrite("output.jpg", img) | ||
} |
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