Add test for makeTensor

This commit is contained in:
Theresa Gresch 2019-07-17 12:22:50 +02:00
parent 30013b6ea7
commit a995bb87de

View file

@ -1,6 +1,7 @@
package photoprism
import (
tensorflow "github.com/tensorflow/tensorflow/tensorflow/go"
"io/ioutil"
"testing"
@ -241,6 +242,32 @@ func TestTensorFlow_BestLabels(t *testing.T) {
})
}
func TestTensorFlow_MakeTensor(t *testing.T) {
t.Run("/cat_brown.jpg", func(t *testing.T) {
conf := config.TestConfig()
tensorFlow := NewTensorFlow(conf)
imageBuffer, err := ioutil.ReadFile(conf.ExamplesPath() + "/cat_brown.jpg")
assert.Nil(t, err)
result, err := tensorFlow.makeTensor(imageBuffer, "jpeg")
assert.Equal(t, tensorflow.DataType(0x1), result.DataType())
assert.Equal(t, int64(1), result.Shape()[0])
assert.Equal(t, int64(224), result.Shape()[2])
})
t.Run("/Random.docx", func(t *testing.T) {
conf := config.TestConfig()
tensorFlow := NewTensorFlow(conf)
imageBuffer, err := ioutil.ReadFile(conf.ExamplesPath() + "/Random.docx")
assert.Nil(t, err)
result, err := tensorFlow.makeTensor(imageBuffer, "jpeg")
assert.Empty(t, result)
assert.Equal(t, "image: unknown format", err.Error())
})
}
func Test_ConvertTF(t *testing.T) {
result := convertTF(uint32(98765432))
assert.Equal(t, float32(3024.898), result)