mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
CI: Apply Go linter recommendations to "ai/classify" package #5330
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
@@ -53,11 +53,12 @@ func (l *Label) Title() string {
|
||||
|
||||
// Confidence returns a matching confidence in percent.
|
||||
func (l *Label) Confidence() float32 {
|
||||
if l.Uncertainty > 100 {
|
||||
switch {
|
||||
case l.Uncertainty > 100:
|
||||
return 0
|
||||
} else if l.Uncertainty < 0 {
|
||||
case l.Uncertainty < 0:
|
||||
return 1
|
||||
} else {
|
||||
default:
|
||||
return 1 - float32(l.Uncertainty)/100
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,14 @@ func (l Labels) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
|
||||
// for equal priority the lower-uncertainty label wins. Labels with an
|
||||
// uncertainty >= 100 are considered unusable and are ordered last.
|
||||
func (l Labels) Less(i, j int) bool {
|
||||
if l[i].Uncertainty >= 100 {
|
||||
switch {
|
||||
case l[i].Uncertainty >= 100:
|
||||
return false
|
||||
} else if l[j].Uncertainty >= 100 {
|
||||
case l[j].Uncertainty >= 100:
|
||||
return true
|
||||
} else if l[i].Priority == l[j].Priority {
|
||||
case l[i].Priority == l[j].Priority:
|
||||
return l[i].Uncertainty < l[j].Uncertainty
|
||||
} else {
|
||||
default:
|
||||
return l[i].Priority > l[j].Priority
|
||||
}
|
||||
}
|
||||
@@ -139,15 +140,16 @@ func (l Labels) Title(fallback string) string {
|
||||
label = l[1]
|
||||
}
|
||||
|
||||
if fallback != "" && label.Priority < 0 {
|
||||
switch {
|
||||
case fallback != "" && label.Priority < 0:
|
||||
return fallback
|
||||
} else if fallback != "" && label.Priority == 0 && label.Uncertainty > 50 {
|
||||
case fallback != "" && label.Priority == 0 && label.Uncertainty > 50:
|
||||
return fallback
|
||||
} else if label.Priority >= -1 && label.Uncertainty <= 60 {
|
||||
case label.Priority >= -1 && label.Uncertainty <= 60:
|
||||
return label.Name
|
||||
default:
|
||||
return fallback
|
||||
}
|
||||
|
||||
return fallback
|
||||
}
|
||||
|
||||
// IsNSFW reports whether any label marks the asset as "not safe for work"
|
||||
|
||||
@@ -25,7 +25,7 @@ const (
|
||||
var baseUrl = "https://dl.photoprism.app/tensorflow/models"
|
||||
|
||||
// To avoid downloading everything again and again...
|
||||
//var baseUrl = "http://host.docker.internal:8000"
|
||||
// var baseUrl = "http://host.docker.internal:8000"
|
||||
|
||||
type ModelTestCase struct {
|
||||
Info *tensorflow.ModelInfo
|
||||
@@ -286,7 +286,7 @@ func testModel_LabelsFromFile(t *testing.T, tensorFlow *Model) {
|
||||
|
||||
if len(result) > 0 {
|
||||
assert.Contains(t, result[0].Name, "chameleon")
|
||||
//assert.Equal(t, 7, result[0].Uncertainty)
|
||||
// assert.Equal(t, 7, result[0].Uncertainty)
|
||||
}
|
||||
})
|
||||
t.Run(testName("cat_224.jpeg"), func(t *testing.T) {
|
||||
@@ -312,7 +312,7 @@ func testModel_LabelsFromFile(t *testing.T, tensorFlow *Model) {
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, result)
|
||||
assert.IsType(t, Labels{}, result)
|
||||
//assert.Equal(t, 3, len(result))
|
||||
// assert.Equal(t, 3, len(result))
|
||||
assert.GreaterOrEqual(t, len(result), 1)
|
||||
|
||||
// t.Logf("labels: %#v", result)
|
||||
|
||||
Reference in New Issue
Block a user