Use image from examples to prevent use of initialize testdata in tensorflow test to make test faster

This commit is contained in:
Theresa Gresch 2019-07-04 09:50:39 +02:00
parent 516c9a892e
commit 4b44373253

View file

@ -11,11 +11,9 @@ import (
func TestTensorFlow_LabelsFromFile(t *testing.T) { func TestTensorFlow_LabelsFromFile(t *testing.T) {
conf := config.TestConfig() conf := config.TestConfig()
conf.InitializeTestData(t)
tensorFlow := NewTensorFlow(conf) tensorFlow := NewTensorFlow(conf)
result, err := tensorFlow.LabelsFromFile(conf.ImportPath() + "/iphone/IMG_6788.JPG") result, err := tensorFlow.LabelsFromFile(conf.ExamplesPath() + "/chameleon_lime.jpg")
assert.Nil(t, err) assert.Nil(t, err)
@ -26,15 +24,13 @@ func TestTensorFlow_LabelsFromFile(t *testing.T) {
assert.NotNil(t, result) assert.NotNil(t, result)
assert.IsType(t, Labels{}, result) assert.IsType(t, Labels{}, result)
assert.Equal(t, 2, len(result)) assert.Equal(t, 1, len(result))
t.Log(result) t.Log(result)
assert.Equal(t, "tabby cat", result[0].Name) assert.Equal(t, "chameleon", result[0].Name)
assert.Equal(t, "tiger cat", result[1].Name)
assert.Equal(t, 32, result[0].Uncertainty) assert.Equal(t, 7, result[0].Uncertainty)
assert.Equal(t, 86, result[1].Uncertainty)
} }
func TestTensorFlow_Labels(t *testing.T) { func TestTensorFlow_Labels(t *testing.T) {
@ -44,11 +40,9 @@ func TestTensorFlow_Labels(t *testing.T) {
conf := config.TestConfig() conf := config.TestConfig()
conf.InitializeTestData(t)
tensorFlow := NewTensorFlow(conf) tensorFlow := NewTensorFlow(conf)
if imageBuffer, err := ioutil.ReadFile(conf.ImportPath() + "/iphone/IMG_6788.JPG"); err != nil { if imageBuffer, err := ioutil.ReadFile(conf.ExamplesPath() + "/chameleon_lime.jpg"); err != nil {
t.Error(err) t.Error(err)
} else { } else {
result, err := tensorFlow.Labels(imageBuffer) result, err := tensorFlow.Labels(imageBuffer)
@ -59,13 +53,11 @@ func TestTensorFlow_Labels(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
assert.IsType(t, Labels{}, result) assert.IsType(t, Labels{}, result)
assert.Equal(t, 2, len(result)) assert.Equal(t, 1, len(result))
assert.Equal(t, "tabby cat", result[0].Name) assert.Equal(t, "chameleon", result[0].Name)
assert.Equal(t, "tiger cat", result[1].Name)
assert.Equal(t, 100-68, result[0].Uncertainty) assert.Equal(t, 100-93, result[0].Uncertainty)
assert.Equal(t, 100-14, result[1].Uncertainty)
} }
} }
@ -76,11 +68,9 @@ func TestTensorFlow_Labels_Dog(t *testing.T) {
conf := config.TestConfig() conf := config.TestConfig()
conf.InitializeTestData(t)
tensorFlow := NewTensorFlow(conf) tensorFlow := NewTensorFlow(conf)
if imageBuffer, err := ioutil.ReadFile(conf.ImportPath() + "/dog.jpg"); err != nil { if imageBuffer, err := ioutil.ReadFile(conf.ExamplesPath() + "/dog_orange.jpg"); err != nil {
t.Error(err) t.Error(err)
} else { } else {
result, err := tensorFlow.Labels(imageBuffer) result, err := tensorFlow.Labels(imageBuffer)
@ -91,12 +81,12 @@ func TestTensorFlow_Labels_Dog(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
assert.IsType(t, Labels{}, result) assert.IsType(t, Labels{}, result)
assert.Equal(t, 3, len(result)) assert.Equal(t, 2, len(result))
assert.Equal(t, "beagle dog", result[0].Name) assert.Equal(t, "chihuahua dog", result[0].Name)
assert.Equal(t, "basset dog", result[1].Name) assert.Equal(t, "pembroke dog", result[1].Name)
assert.Equal(t, 91, result[0].Uncertainty) assert.Equal(t, 34, result[0].Uncertainty)
assert.Equal(t, 92, result[1].Uncertainty) assert.Equal(t, 91, result[1].Uncertainty)
} }
} }