Config: Add options to disable classification and/or facial recognition

This commit is contained in:
Michael Mayer 2021-09-24 01:53:42 +02:00
parent 2929733f78
commit a1822f9b19
9 changed files with 177 additions and 117 deletions

View file

@ -67,6 +67,8 @@ func configAction(ctx *cli.Context) error {
fmt.Printf("%-25s %t\n", "disable-places", conf.DisablePlaces())
fmt.Printf("%-25s %t\n", "disable-exiftool", conf.DisableExifTool())
fmt.Printf("%-25s %t\n", "disable-tensorflow", conf.DisableTensorFlow())
fmt.Printf("%-25s %t\n", "disable-faces", conf.DisableFaces())
fmt.Printf("%-25s %t\n", "disable-classification", conf.DisableClassification())
fmt.Printf("%-25s %t\n", "disable-darktable", conf.DisableDarktable())
fmt.Printf("%-25s %t\n", "disable-rawtherapee", conf.DisableRawtherapee())
fmt.Printf("%-25s %t\n", "disable-sips", conf.DisableSips())

View file

@ -67,17 +67,19 @@ type Years []int
// ClientDisable represents disabled client features a user can't turn back on.
type ClientDisable struct {
Backups bool `json:"backups"`
WebDAV bool `json:"webdav"`
Settings bool `json:"settings"`
Places bool `json:"places"`
ExifTool bool `json:"exiftool"`
Darktable bool `json:"darktable"`
Rawtherapee bool `json:"rawtherapee"`
Sips bool `json:"sips"`
HeifConvert bool `json:"heifconvert"`
FFmpeg bool `json:"ffmpeg"`
TensorFlow bool `json:"tensorflow"`
Backups bool `json:"backups"`
WebDAV bool `json:"webdav"`
Settings bool `json:"settings"`
Places bool `json:"places"`
ExifTool bool `json:"exiftool"`
Darktable bool `json:"darktable"`
Rawtherapee bool `json:"rawtherapee"`
Sips bool `json:"sips"`
HeifConvert bool `json:"heifconvert"`
FFmpeg bool `json:"ffmpeg"`
TensorFlow bool `json:"tensorflow"`
Faces bool `json:"faces"`
Classification bool `json:"classification"`
}
// ClientCounts represents photo, video and album counts for the client UI.
@ -282,17 +284,19 @@ func (c *Config) UserConfig() ClientConfig {
result := ClientConfig{
Settings: *c.Settings(),
Disable: ClientDisable{
Backups: c.DisableBackups(),
WebDAV: c.DisableWebDAV(),
Settings: c.DisableSettings(),
Places: c.DisablePlaces(),
ExifTool: c.DisableExifTool(),
TensorFlow: c.DisableTensorFlow(),
Darktable: c.DisableDarktable(),
Rawtherapee: c.DisableRawtherapee(),
Sips: c.DisableSips(),
HeifConvert: c.DisableHeifConvert(),
FFmpeg: c.DisableFFmpeg(),
Backups: c.DisableBackups(),
WebDAV: c.DisableWebDAV(),
Settings: c.DisableSettings(),
Places: c.DisablePlaces(),
ExifTool: c.DisableExifTool(),
TensorFlow: c.DisableTensorFlow(),
Faces: c.DisableFaces(),
Classification: c.DisableClassification(),
Darktable: c.DisableDarktable(),
Rawtherapee: c.DisableRawtherapee(),
Sips: c.DisableSips(),
HeifConvert: c.DisableHeifConvert(),
FFmpeg: c.DisableFFmpeg(),
},
Flags: strings.Join(c.Flags(), " "),
Mode: "user",

View file

@ -37,16 +37,34 @@ func (c *Config) DisableExifTool() bool {
return c.options.DisableExifTool
}
// DisableTensorFlow tests if TensorFlow should not be used for image classification (or anything else).
// DisableTensorFlow tests if features that require TensorFlow should be disabled.
func (c *Config) DisableTensorFlow() bool {
if LowMem && !c.options.DisableTensorFlow {
c.options.DisableTensorFlow = true
log.Warnf("config: disabled image classification due to memory constraints")
log.Warnf("config: disabled tensorflow due to memory constraints")
}
return c.options.DisableTensorFlow
}
// DisableFaces tests if facial recognition is disabled.
func (c *Config) DisableFaces() bool {
if c.DisableTensorFlow() || c.options.DisableFaces {
return true
}
return false
}
// DisableClassification tests if image classification is disabled.
func (c *Config) DisableClassification() bool {
if c.DisableTensorFlow() || c.options.DisableClassification {
return true
}
return false
}
// DisableFFmpeg tests if FFmpeg is disabled for video transcoding.
func (c *Config) DisableFFmpeg() bool {
return c.options.DisableFFmpeg || c.FFmpegBin() == ""

View file

@ -27,3 +27,27 @@ func TestConfig_DisableExifTool(t *testing.T) {
c.options.ExifToolBin = "XXX"
assert.True(t, c.DisableExifTool())
}
func TestConfig_DisableFaces(t *testing.T) {
c := NewConfig(CliTestContext())
assert.False(t, c.DisableFaces())
c.options.DisableFaces = true
assert.True(t, c.DisableFaces())
c.options.DisableFaces = false
c.options.DisableTensorFlow = true
assert.True(t, c.DisableFaces())
c.options.DisableTensorFlow = false
assert.False(t, c.DisableFaces())
}
func TestConfig_DisableClassification(t *testing.T) {
c := NewConfig(CliTestContext())
assert.False(t, c.DisableClassification())
c.options.DisableClassification = true
assert.True(t, c.DisableClassification())
c.options.DisableClassification = false
c.options.DisableTensorFlow = true
assert.True(t, c.DisableClassification())
c.options.DisableTensorFlow = false
assert.False(t, c.DisableClassification())
}

View file

@ -155,9 +155,19 @@ var GlobalFlags = []cli.Flag{
},
cli.BoolFlag{
Name: "disable-tensorflow",
Usage: "disables image classification with TensorFlow",
Usage: "disables features that require TensorFlow",
EnvVar: "PHOTOPRISM_DISABLE_TENSORFLOW",
},
cli.BoolFlag{
Name: "disable-faces",
Usage: "disables facial recognition",
EnvVar: "PHOTOPRISM_DISABLE_FACES",
},
cli.BoolFlag{
Name: "disable-classification",
Usage: "disables image classification",
EnvVar: "PHOTOPRISM_DISABLE_CLASSIFICATION",
},
cli.BoolFlag{
Name: "disable-ffmpeg",
Usage: "disables video transcoding and thumbnail generation with FFmpeg",

View file

@ -30,94 +30,96 @@ const (
//
// See https://github.com/photoprism/photoprism/issues/50#issuecomment-433856358
type Options struct {
Name string `json:"-"`
Version string `json:"-"`
Copyright string `json:"-"`
Debug bool `yaml:"Debug" json:"Debug" flag:"debug"`
Test bool `yaml:"-" json:"Test,omitempty" flag:"test"`
Demo bool `yaml:"Demo" json:"-" flag:"demo"`
Sponsor bool `yaml:"-" json:"-" flag:"sponsor"`
Public bool `yaml:"Public" json:"-" flag:"public"`
ReadOnly bool `yaml:"ReadOnly" json:"ReadOnly" flag:"read-only"`
Experimental bool `yaml:"Experimental" json:"Experimental" flag:"experimental"`
ConfigPath string `yaml:"ConfigPath" json:"-" flag:"config-path"`
ConfigFile string `json:"-"`
AdminPassword string `yaml:"AdminPassword" json:"-" flag:"admin-password"`
OriginalsPath string `yaml:"OriginalsPath" json:"-" flag:"originals-path"`
OriginalsLimit int64 `yaml:"OriginalsLimit" json:"OriginalsLimit" flag:"originals-limit"`
ImportPath string `yaml:"ImportPath" json:"-" flag:"import-path"`
StoragePath string `yaml:"StoragePath" json:"-" flag:"storage-path"`
SidecarPath string `yaml:"SidecarPath" json:"-" flag:"sidecar-path"`
TempPath string `yaml:"TempPath" json:"-" flag:"temp-path"`
BackupPath string `yaml:"BackupPath" json:"-" flag:"backup-path"`
AssetsPath string `yaml:"AssetsPath" json:"-" flag:"assets-path"`
CachePath string `yaml:"CachePath" json:"-" flag:"cache-path"`
Workers int `yaml:"Workers" json:"Workers" flag:"workers"`
WakeupInterval int `yaml:"WakeupInterval" json:"WakeupInterval" flag:"wakeup-interval"`
AutoIndex int `yaml:"AutoIndex" json:"AutoIndex" flag:"auto-index"`
AutoImport int `yaml:"AutoImport" json:"AutoImport" flag:"auto-import"`
DisableBackups bool `yaml:"DisableBackups" json:"DisableBackups" flag:"disable-backups"`
DisableWebDAV bool `yaml:"DisableWebDAV" json:"DisableWebDAV" flag:"disable-webdav"`
DisableSettings bool `yaml:"DisableSettings" json:"-" flag:"disable-settings"`
DisablePlaces bool `yaml:"DisablePlaces" json:"DisablePlaces" flag:"disable-places"`
DisableExifTool bool `yaml:"DisableExifTool" json:"DisableExifTool" flag:"disable-exiftool"`
DisableTensorFlow bool `yaml:"DisableTensorFlow" json:"DisableTensorFlow" flag:"disable-tensorflow"`
DisableFFmpeg bool `yaml:"DisableFFmpeg" json:"DisableFFmpeg" flag:"disable-ffmpeg"`
DisableDarktable bool `yaml:"DisableDarktable" json:"DisableDarktable" flag:"disable-darktable"`
DisableRawtherapee bool `yaml:"DisableRawtherapee" json:"DisableRawtherapee" flag:"disable-rawtherapee"`
DisableSips bool `yaml:"DisableSips" json:"DisableSips" flag:"disable-sips"`
DisableHeifConvert bool `yaml:"DisableHeifConvert" json:"DisableHeifConvert" flag:"disable-heifconvert"`
DetectNSFW bool `yaml:"DetectNSFW" json:"DetectNSFW" flag:"detect-nsfw"`
UploadNSFW bool `yaml:"UploadNSFW" json:"-" flag:"upload-nsfw"`
LogLevel string `yaml:"LogLevel" json:"-" flag:"log-level"`
LogFilename string `yaml:"LogFilename" json:"-" flag:"log-filename"`
PIDFilename string `yaml:"PIDFilename" json:"-" flag:"pid-filename"`
CdnUrl string `yaml:"CdnUrl" json:"CdnUrl" flag:"cdn-url"`
SiteUrl string `yaml:"SiteUrl" json:"SiteUrl" flag:"site-url"`
SitePreview string `yaml:"SitePreview" json:"SitePreview" flag:"site-preview"`
SiteTitle string `yaml:"SiteTitle" json:"SiteTitle" flag:"site-title"`
SiteCaption string `yaml:"SiteCaption" json:"SiteCaption" flag:"site-caption"`
SiteDescription string `yaml:"SiteDescription" json:"SiteDescription" flag:"site-description"`
SiteAuthor string `yaml:"SiteAuthor" json:"SiteAuthor" flag:"site-author"`
DatabaseDriver string `yaml:"DatabaseDriver" json:"-" flag:"database-driver"`
DatabaseDsn string `yaml:"DatabaseDsn" json:"-" flag:"database-dsn"`
DatabaseServer string `yaml:"DatabaseServer" json:"-" flag:"database-server"`
DatabaseName string `yaml:"DatabaseName" json:"-" flag:"database-name"`
DatabaseUser string `yaml:"DatabaseUser" json:"-" flag:"database-user"`
DatabasePassword string `yaml:"DatabasePassword" json:"-" flag:"database-password"`
DatabaseConns int `yaml:"DatabaseConns" json:"-" flag:"database-conns"`
DatabaseConnsIdle int `yaml:"DatabaseConnsIdle" json:"-" flag:"database-conns-idle"`
HttpHost string `yaml:"HttpHost" json:"-" flag:"http-host"`
HttpPort int `yaml:"HttpPort" json:"-" flag:"http-port"`
HttpMode string `yaml:"HttpMode" json:"-" flag:"http-mode"`
HttpCompression string `yaml:"HttpCompression" json:"-" flag:"http-compression"`
RawPresets bool `yaml:"RawPresets" json:"RawPresets" flag:"raw-presets"`
DarktableBin string `yaml:"DarktableBin" json:"-" flag:"darktable-bin"`
DarktableBlacklist string `yaml:"DarktableBlacklist" json:"-" flag:"darktable-blacklist"`
RawtherapeeBin string `yaml:"RawtherapeeBin" json:"-" flag:"rawtherapee-bin"`
RawtherapeeBlacklist string `yaml:"RawtherapeeBlacklist" json:"-" flag:"rawtherapee-blacklist"`
SipsBin string `yaml:"SipsBin" json:"-" flag:"sips-bin"`
HeifConvertBin string `yaml:"HeifConvertBin" json:"-" flag:"heifconvert-bin"`
FFmpegBin string `yaml:"FFmpegBin" json:"-" flag:"ffmpeg-bin"`
FFmpegEncoder string `yaml:"FFmpegEncoder" json:"FFmpegEncoder" flag:"ffmpeg-encoder"`
FFmpegBitrate int `yaml:"FFmpegBitrate" json:"FFmpegBitrate" flag:"ffmpeg-bitrate"`
FFmpegBuffers int `yaml:"FFmpegBuffers" json:"FFmpegBuffers" flag:"ffmpeg-buffers"`
ExifToolBin string `yaml:"ExifToolBin" json:"-" flag:"exiftool-bin"`
DetachServer bool `yaml:"DetachServer" json:"-" flag:"detach-server"`
DownloadToken string `yaml:"DownloadToken" json:"-" flag:"download-token"`
PreviewToken string `yaml:"PreviewToken" json:"-" flag:"preview-token"`
ThumbFilter string `yaml:"ThumbFilter" json:"ThumbFilter" flag:"thumb-filter"`
ThumbUncached bool `yaml:"ThumbUncached" json:"ThumbUncached" flag:"thumb-uncached"`
ThumbSize int `yaml:"ThumbSize" json:"ThumbSize" flag:"thumb-size"`
ThumbSizeUncached int `yaml:"ThumbSizeUncached" json:"ThumbSizeUncached" flag:"thumb-size-uncached"`
JpegSize int `yaml:"JpegSize" json:"JpegSize" flag:"jpeg-size"`
JpegQuality int `yaml:"JpegQuality" json:"JpegQuality" flag:"jpeg-quality"`
FaceSize int `yaml:"-" json:"-" flag:"face-size"`
FaceScore float64 `yaml:"-" json:"-" flag:"face-score"`
FaceOverlap int `yaml:"-" json:"-" flag:"face-overlap"`
FaceClusterCore int `yaml:"-" json:"-" flag:"face-cluster-core"`
FaceClusterDist float64 `yaml:"-" json:"-" flag:"face-cluster-dist"`
FaceMatchDist float64 `yaml:"-" json:"-" flag:"face-match-dist"`
Name string `json:"-"`
Version string `json:"-"`
Copyright string `json:"-"`
Debug bool `yaml:"Debug" json:"Debug" flag:"debug"`
Test bool `yaml:"-" json:"Test,omitempty" flag:"test"`
Demo bool `yaml:"Demo" json:"-" flag:"demo"`
Sponsor bool `yaml:"-" json:"-" flag:"sponsor"`
Public bool `yaml:"Public" json:"-" flag:"public"`
ReadOnly bool `yaml:"ReadOnly" json:"ReadOnly" flag:"read-only"`
Experimental bool `yaml:"Experimental" json:"Experimental" flag:"experimental"`
ConfigPath string `yaml:"ConfigPath" json:"-" flag:"config-path"`
ConfigFile string `json:"-"`
AdminPassword string `yaml:"AdminPassword" json:"-" flag:"admin-password"`
OriginalsPath string `yaml:"OriginalsPath" json:"-" flag:"originals-path"`
OriginalsLimit int64 `yaml:"OriginalsLimit" json:"OriginalsLimit" flag:"originals-limit"`
ImportPath string `yaml:"ImportPath" json:"-" flag:"import-path"`
StoragePath string `yaml:"StoragePath" json:"-" flag:"storage-path"`
SidecarPath string `yaml:"SidecarPath" json:"-" flag:"sidecar-path"`
TempPath string `yaml:"TempPath" json:"-" flag:"temp-path"`
BackupPath string `yaml:"BackupPath" json:"-" flag:"backup-path"`
AssetsPath string `yaml:"AssetsPath" json:"-" flag:"assets-path"`
CachePath string `yaml:"CachePath" json:"-" flag:"cache-path"`
Workers int `yaml:"Workers" json:"Workers" flag:"workers"`
WakeupInterval int `yaml:"WakeupInterval" json:"WakeupInterval" flag:"wakeup-interval"`
AutoIndex int `yaml:"AutoIndex" json:"AutoIndex" flag:"auto-index"`
AutoImport int `yaml:"AutoImport" json:"AutoImport" flag:"auto-import"`
DisableBackups bool `yaml:"DisableBackups" json:"DisableBackups" flag:"disable-backups"`
DisableWebDAV bool `yaml:"DisableWebDAV" json:"DisableWebDAV" flag:"disable-webdav"`
DisableSettings bool `yaml:"DisableSettings" json:"-" flag:"disable-settings"`
DisablePlaces bool `yaml:"DisablePlaces" json:"DisablePlaces" flag:"disable-places"`
DisableExifTool bool `yaml:"DisableExifTool" json:"DisableExifTool" flag:"disable-exiftool"`
DisableTensorFlow bool `yaml:"DisableTensorFlow" json:"DisableTensorFlow" flag:"disable-tensorflow"`
DisableFaces bool `yaml:"DisableFaces" json:"DisableFaces" flag:"disable-faces"`
DisableClassification bool `yaml:"DisableClassification" json:"DisableClassification" flag:"disable-classification"`
DisableFFmpeg bool `yaml:"DisableFFmpeg" json:"DisableFFmpeg" flag:"disable-ffmpeg"`
DisableDarktable bool `yaml:"DisableDarktable" json:"DisableDarktable" flag:"disable-darktable"`
DisableRawtherapee bool `yaml:"DisableRawtherapee" json:"DisableRawtherapee" flag:"disable-rawtherapee"`
DisableSips bool `yaml:"DisableSips" json:"DisableSips" flag:"disable-sips"`
DisableHeifConvert bool `yaml:"DisableHeifConvert" json:"DisableHeifConvert" flag:"disable-heifconvert"`
DetectNSFW bool `yaml:"DetectNSFW" json:"DetectNSFW" flag:"detect-nsfw"`
UploadNSFW bool `yaml:"UploadNSFW" json:"-" flag:"upload-nsfw"`
LogLevel string `yaml:"LogLevel" json:"-" flag:"log-level"`
LogFilename string `yaml:"LogFilename" json:"-" flag:"log-filename"`
PIDFilename string `yaml:"PIDFilename" json:"-" flag:"pid-filename"`
CdnUrl string `yaml:"CdnUrl" json:"CdnUrl" flag:"cdn-url"`
SiteUrl string `yaml:"SiteUrl" json:"SiteUrl" flag:"site-url"`
SitePreview string `yaml:"SitePreview" json:"SitePreview" flag:"site-preview"`
SiteTitle string `yaml:"SiteTitle" json:"SiteTitle" flag:"site-title"`
SiteCaption string `yaml:"SiteCaption" json:"SiteCaption" flag:"site-caption"`
SiteDescription string `yaml:"SiteDescription" json:"SiteDescription" flag:"site-description"`
SiteAuthor string `yaml:"SiteAuthor" json:"SiteAuthor" flag:"site-author"`
DatabaseDriver string `yaml:"DatabaseDriver" json:"-" flag:"database-driver"`
DatabaseDsn string `yaml:"DatabaseDsn" json:"-" flag:"database-dsn"`
DatabaseServer string `yaml:"DatabaseServer" json:"-" flag:"database-server"`
DatabaseName string `yaml:"DatabaseName" json:"-" flag:"database-name"`
DatabaseUser string `yaml:"DatabaseUser" json:"-" flag:"database-user"`
DatabasePassword string `yaml:"DatabasePassword" json:"-" flag:"database-password"`
DatabaseConns int `yaml:"DatabaseConns" json:"-" flag:"database-conns"`
DatabaseConnsIdle int `yaml:"DatabaseConnsIdle" json:"-" flag:"database-conns-idle"`
HttpHost string `yaml:"HttpHost" json:"-" flag:"http-host"`
HttpPort int `yaml:"HttpPort" json:"-" flag:"http-port"`
HttpMode string `yaml:"HttpMode" json:"-" flag:"http-mode"`
HttpCompression string `yaml:"HttpCompression" json:"-" flag:"http-compression"`
RawPresets bool `yaml:"RawPresets" json:"RawPresets" flag:"raw-presets"`
DarktableBin string `yaml:"DarktableBin" json:"-" flag:"darktable-bin"`
DarktableBlacklist string `yaml:"DarktableBlacklist" json:"-" flag:"darktable-blacklist"`
RawtherapeeBin string `yaml:"RawtherapeeBin" json:"-" flag:"rawtherapee-bin"`
RawtherapeeBlacklist string `yaml:"RawtherapeeBlacklist" json:"-" flag:"rawtherapee-blacklist"`
SipsBin string `yaml:"SipsBin" json:"-" flag:"sips-bin"`
HeifConvertBin string `yaml:"HeifConvertBin" json:"-" flag:"heifconvert-bin"`
FFmpegBin string `yaml:"FFmpegBin" json:"-" flag:"ffmpeg-bin"`
FFmpegEncoder string `yaml:"FFmpegEncoder" json:"FFmpegEncoder" flag:"ffmpeg-encoder"`
FFmpegBitrate int `yaml:"FFmpegBitrate" json:"FFmpegBitrate" flag:"ffmpeg-bitrate"`
FFmpegBuffers int `yaml:"FFmpegBuffers" json:"FFmpegBuffers" flag:"ffmpeg-buffers"`
ExifToolBin string `yaml:"ExifToolBin" json:"-" flag:"exiftool-bin"`
DetachServer bool `yaml:"DetachServer" json:"-" flag:"detach-server"`
DownloadToken string `yaml:"DownloadToken" json:"-" flag:"download-token"`
PreviewToken string `yaml:"PreviewToken" json:"-" flag:"preview-token"`
ThumbFilter string `yaml:"ThumbFilter" json:"ThumbFilter" flag:"thumb-filter"`
ThumbUncached bool `yaml:"ThumbUncached" json:"ThumbUncached" flag:"thumb-uncached"`
ThumbSize int `yaml:"ThumbSize" json:"ThumbSize" flag:"thumb-size"`
ThumbSizeUncached int `yaml:"ThumbSizeUncached" json:"ThumbSizeUncached" flag:"thumb-size-uncached"`
JpegSize int `yaml:"JpegSize" json:"JpegSize" flag:"jpeg-size"`
JpegQuality int `yaml:"JpegQuality" json:"JpegQuality" flag:"jpeg-quality"`
FaceSize int `yaml:"-" json:"-" flag:"face-size"`
FaceScore float64 `yaml:"-" json:"-" flag:"face-score"`
FaceOverlap int `yaml:"-" json:"-" flag:"face-overlap"`
FaceClusterCore int `yaml:"-" json:"-" flag:"face-cluster-core"`
FaceClusterDist float64 `yaml:"-" json:"-" flag:"face-cluster-dist"`
FaceMatchDist float64 `yaml:"-" json:"-" flag:"face-match-dist"`
}
// NewOptions creates a new configuration entity by using two methods:

View file

@ -92,10 +92,10 @@ func (ind *Index) Start(opt IndexOptions) fs.Done {
}
// Detect faces in images?
ind.findFaces = ind.conf.Settings().Features.People
ind.findFaces = !ind.conf.DisableFaces() && ind.conf.Settings().Features.People
// Classify images with TensorFlow?
ind.findLabels = !ind.conf.DisableTensorFlow()
ind.findLabels = !ind.conf.DisableClassification()
defer mutex.MainWorker.Stop()

View file

@ -9,7 +9,7 @@ import (
var onceClassify sync.Once
func initClassify() {
services.Classify = classify.New(Config().AssetsPath(), Config().DisableTensorFlow())
services.Classify = classify.New(Config().AssetsPath(), Config().DisableClassification())
}
func Classify() *classify.TensorFlow {

View file

@ -9,7 +9,7 @@ import (
var onceFaceNet sync.Once
func initFaceNet() {
services.FaceNet = face.NewNet(conf.FaceNetModelPath(), "", conf.DisableTensorFlow())
services.FaceNet = face.NewNet(conf.FaceNetModelPath(), "", conf.DisableFaces())
}
func FaceNet() *face.Net {