mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
@@ -5,10 +5,12 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/clean"
|
||||
)
|
||||
|
||||
func loadLabelsFromPath(path string) (labels []string, err error) {
|
||||
log.Infof("tensorflow: loading model labels from %s", path)
|
||||
log.Infof("vision: loading TensorFlow model labels from %s", path)
|
||||
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
@@ -39,22 +41,22 @@ func LoadLabels(modelPath string, expectedLabels int) (labels []string, err erro
|
||||
}
|
||||
|
||||
for i := range matches {
|
||||
labels, err := loadLabelsFromPath(filepath.Join(modelPath, matches[i]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
loadedLabels, labelsErr := loadLabelsFromPath(filepath.Join(modelPath, matches[i]))
|
||||
|
||||
if labelsErr != nil {
|
||||
return nil, labelsErr
|
||||
}
|
||||
|
||||
switch expectedLabels - len(labels) {
|
||||
switch expectedLabels - len(loadedLabels) {
|
||||
case 0:
|
||||
log.Infof("Found a valid labels file: %s", matches[i])
|
||||
return labels, nil
|
||||
log.Infof("vision: found valid labels in %s", clean.Log(matches[i]))
|
||||
return loadedLabels, nil
|
||||
case 1:
|
||||
log.Infof("Found a valid labels file %s but we have to add bias", matches[i])
|
||||
|
||||
return append([]string{"background"}, labels...), nil
|
||||
log.Infof("vision: found valid labels in %s, but bias needs to be added", clean.Log(matches[i]))
|
||||
return append([]string{"background"}, loadedLabels...), nil
|
||||
default:
|
||||
log.Infof("File not valid. Expected %d labels and have %d",
|
||||
expectedLabels, len(labels))
|
||||
log.Infof("vision: invalid labels file, expected %d labels and found %d",
|
||||
expectedLabels, len(loadedLabels))
|
||||
}
|
||||
}
|
||||
return nil, os.ErrNotExist
|
||||
|
||||
Reference in New Issue
Block a user