2021-08-13 20:04:59 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
|
|
"github.com/photoprism/photoprism/internal/service"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FacesCommand registers the faces cli command.
|
|
|
|
var FacesCommand = cli.Command{
|
|
|
|
Name: "faces",
|
2021-08-13 21:51:18 +02:00
|
|
|
Usage: "Runs facial recognition commands",
|
2021-08-13 20:04:59 +02:00
|
|
|
Subcommands: []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "stats",
|
|
|
|
Usage: "Shows stats on face embeddings",
|
|
|
|
Action: facesStatsAction,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "index",
|
2021-08-14 14:24:48 +02:00
|
|
|
Usage: "Performs face clustering and matching",
|
2021-08-13 20:04:59 +02:00
|
|
|
Action: facesIndexAction,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// facesStatsAction shows stats on face embeddings.
|
|
|
|
func facesStatsAction(ctx *cli.Context) error {
|
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
conf := config.NewConfig(ctx)
|
|
|
|
service.SetConfig(conf)
|
|
|
|
|
|
|
|
_, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
if err := conf.Init(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
conf.InitDb()
|
|
|
|
|
|
|
|
w := service.Faces()
|
|
|
|
|
|
|
|
if err := w.Analyze(); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
elapsed := time.Since(start)
|
|
|
|
|
|
|
|
log.Infof("completed in %s", elapsed)
|
|
|
|
}
|
|
|
|
|
|
|
|
conf.Shutdown()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-14 14:24:48 +02:00
|
|
|
// facesIndexAction performs face clustering and matching.
|
2021-08-13 20:04:59 +02:00
|
|
|
func facesIndexAction(ctx *cli.Context) error {
|
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
conf := config.NewConfig(ctx)
|
|
|
|
service.SetConfig(conf)
|
|
|
|
|
|
|
|
_, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
if err := conf.Init(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
conf.InitDb()
|
|
|
|
|
|
|
|
w := service.Faces()
|
|
|
|
|
|
|
|
if err := w.Start(); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
elapsed := time.Since(start)
|
|
|
|
|
|
|
|
log.Infof("completed in %s", elapsed)
|
|
|
|
}
|
|
|
|
|
|
|
|
conf.Shutdown()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|