-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from circled-me/face-recognition
Face recognition + use alpine as output image
- Loading branch information
Showing
23 changed files
with
606 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
FROM golang:1.22-alpine | ||
RUN apk add make gcc libc-dev mailcap | ||
RUN apk add dlib dlib-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ | ||
RUN apk add blas blas-dev cblas lapack lapack-dev libjpeg-turbo-dev cmake make gcc libc-dev g++ unzip libx11-dev pkgconf jpeg jpeg-dev libpng libpng-dev mailcap | ||
|
||
COPY go.mod /go/src/circled-server/ | ||
COPY go.sum /go/src/circled-server/ | ||
WORKDIR /go/src/circled-server/ | ||
RUN go mod download | ||
RUN go build github.com/Kagami/go-face | ||
RUN CGO_CFLAGS="-D_LARGEFILE64_SOURCE" go build github.com/mattn/go-sqlite3 | ||
COPY . /go/src/circled-server | ||
RUN CGO_ENABLED=1 CGO_CFLAGS="-D_LARGEFILE64_SOURCE" GOOS=linux go build -a -installsuffix cgo -o circled-server . | ||
|
||
# Final output image | ||
FROM alpine:3.20.1 | ||
RUN apk --no-cache add ca-certificates exiftool tzdata ffmpeg | ||
RUN apk add dlib --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ | ||
RUN apk --no-cache add ca-certificates exiftool tzdata blas cblas lapack libjpeg-turbo libstdc++ libgcc ffmpeg | ||
WORKDIR /opt/circled | ||
COPY --from=0 /etc/mime.types /etc/mime.types | ||
COPY --from=0 /go/src/circled-server/circled-server . | ||
COPY --from=0 /go/src/circled-server/templates ./templates | ||
# Use 68 landmarks model instead of 5 landmarks model | ||
ADD https://github.com/ageitgey/face_recognition_models/raw/master/face_recognition_models/models/shape_predictor_68_face_landmarks.dat ./models/shape_predictor_5_face_landmarks.dat | ||
ADD https://github.com/ageitgey/face_recognition_models/raw/master/face_recognition_models/models/dlib_face_recognition_resnet_model_v1.dat ./models/ | ||
ADD https://github.com/ageitgey/face_recognition_models/raw/master/face_recognition_models/models/mmod_human_face_detector.dat ./models/ | ||
ENTRYPOINT ["./circled-server"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package faces | ||
|
||
import ( | ||
"log" | ||
"path/filepath" | ||
"server/config" | ||
|
||
"github.com/Kagami/go-face" | ||
) | ||
|
||
var ( | ||
modelsDir = filepath.Join(".", "models") | ||
rec *face.Recognizer | ||
) | ||
|
||
func init() { | ||
log.Println("Loading face recognition models...") | ||
// Init the recognizer. | ||
var err error | ||
rec, err = face.NewRecognizer(modelsDir) | ||
if err != nil { | ||
log.Fatalf("Can't init face recognizer: %v", err) | ||
} | ||
} | ||
|
||
func Detect(imgPath string) ([]face.Face, error) { | ||
log.Printf("Detecting faces in %s", imgPath) | ||
// Recognize faces on that image. | ||
if !config.FACE_DETECT_CNN { | ||
// HOG (Histogram of Oriented Gradients) based detection | ||
return rec.RecognizeFile(imgPath) | ||
} | ||
// CNN (Convolutional Neural Network) based detection | ||
return rec.RecognizeFileCNN(imgPath) | ||
} |
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 @@ | ||
package faces | ||
|
||
import "encoding/json" | ||
|
||
const ( | ||
IndexTop = 0 | ||
IndexRight = 1 | ||
IndexBottom = 2 | ||
IndexLeft = 3 | ||
) | ||
|
||
type ( | ||
FaceBoundaries [4]int | ||
FaceBoundariesList []FaceBoundaries | ||
FaceEncoding [128]float64 | ||
FaceEncodingList []FaceEncoding | ||
FaceDetectionResult struct { | ||
Locations FaceBoundariesList `json:"locations"` | ||
Encodings FaceEncodingList `json:"encodings"` | ||
} | ||
) | ||
|
||
func toFacesResult(data []byte) (result FaceDetectionResult, err error) { | ||
// Parse the string | ||
err = json.Unmarshal(data, &result) | ||
return result, err | ||
} | ||
|
||
func (l *FaceBoundaries) ToJSONString() string { | ||
data, _ := json.Marshal(l) | ||
return string(data) | ||
} | ||
|
||
func (e *FaceEncoding) ToJSONString() string { | ||
data, _ := json.Marshal(e) | ||
return string(data) | ||
} |
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.