From 9987d65933c9428eeb261cf0426d9d725f05bc57 Mon Sep 17 00:00:00 2001 From: Michael Mayer <michael@liquidbytes.net> Date: Sat, 14 Dec 2019 14:38:43 +0100 Subject: [PATCH] Backend: Remove NSFW code from photoprism package Signed-off-by: Michael Mayer <michael@liquidbytes.net> --- internal/photoprism/tensorflow.go | 11 +++-------- internal/photoprism/tensorflow_test.go | 27 -------------------------- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/internal/photoprism/tensorflow.go b/internal/photoprism/tensorflow.go index 8786a764f..3389a7fb0 100644 --- a/internal/photoprism/tensorflow.go +++ b/internal/photoprism/tensorflow.go @@ -46,13 +46,6 @@ func NewTensorFlow(conf *config.Config) *TensorFlow { return &TensorFlow{conf: conf, modelName: "nasnet", modelTags: []string{"photoprism"}} } -// NewTensorFlowNSFW returns new TensorFlow instance with NSFW model. -/* TODO: Need to convert model to tagged .pb file before we can test -func NewTensorFlowNSFW(conf *config.Config) *TensorFlow { - return &TensorFlow{conf: conf, modelName: "nsfw", modelTags: []string{"photoprism"}} -} -*/ - func (t *TensorFlow) loadLabelRules() (err error) { if len(t.labelRules) > 0 { return nil @@ -103,6 +96,7 @@ func (t *TensorFlow) Labels(img []byte) (result Labels, err error) { tensor, err := t.makeTensor(img, "jpeg") if err != nil { + log.Error(err) return nil, errors.New("invalid image") } @@ -117,6 +111,7 @@ func (t *TensorFlow) Labels(img []byte) (result Labels, err error) { nil) if err != nil { + log.Error(err) return result, errors.New("could not run inference") } @@ -239,7 +234,7 @@ func (t *TensorFlow) bestLabels(probabilities []float32) Labels { } // Sort by probability - sort.Sort(Labels(result)) + sort.Sort(result) if l := len(result); l < 5 { return result[:l] diff --git a/internal/photoprism/tensorflow_test.go b/internal/photoprism/tensorflow_test.go index 9014bb6f7..f6f4cecb3 100644 --- a/internal/photoprism/tensorflow_test.go +++ b/internal/photoprism/tensorflow_test.go @@ -273,30 +273,3 @@ func Test_ConvertTF(t *testing.T) { result := convertTF(uint32(98765432)) assert.Equal(t, float32(3024.898), result) } - -/* TODO: Need to convert model to tagged .pb file before we can test -func TestTensorFlow_NSFW(t *testing.T) { - t.Run("/chameleon_lime.jpg", func(t *testing.T) { - conf := config.TestConfig() - - conf.TensorFlowModelPath() - - tensorFlow := NewTensorFlowNSFW(conf) - - result, err := tensorFlow.LabelsFromFile(conf.ExamplesPath() + "/chameleon_lime.jpg") - - assert.Nil(t, err) - - if err != nil { - t.Log(err.Error()) - t.Fail() - } - - assert.NotNil(t, result) - assert.IsType(t, Labels{}, result) - assert.Equal(t, 1, len(result)) - - t.Log(result) - }) -} -*/