Use image from examples to prevent use of initialize testdata in tensorflow test to make test faster
This commit is contained in:
parent
516c9a892e
commit
4b44373253
1 changed files with 36 additions and 46 deletions
|
@ -11,11 +11,9 @@ import (
|
|||
func TestTensorFlow_LabelsFromFile(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
conf.InitializeTestData(t)
|
||||
|
||||
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)
|
||||
|
||||
|
@ -26,15 +24,13 @@ func TestTensorFlow_LabelsFromFile(t *testing.T) {
|
|||
|
||||
assert.NotNil(t, result)
|
||||
assert.IsType(t, Labels{}, result)
|
||||
assert.Equal(t, 2, len(result))
|
||||
assert.Equal(t, 1, len(result))
|
||||
|
||||
t.Log(result)
|
||||
|
||||
assert.Equal(t, "tabby cat", result[0].Name)
|
||||
assert.Equal(t, "tiger cat", result[1].Name)
|
||||
assert.Equal(t, "chameleon", result[0].Name)
|
||||
|
||||
assert.Equal(t, 32, result[0].Uncertainty)
|
||||
assert.Equal(t, 86, result[1].Uncertainty)
|
||||
assert.Equal(t, 7, result[0].Uncertainty)
|
||||
}
|
||||
|
||||
func TestTensorFlow_Labels(t *testing.T) {
|
||||
|
@ -44,11 +40,37 @@ func TestTensorFlow_Labels(t *testing.T) {
|
|||
|
||||
conf := config.TestConfig()
|
||||
|
||||
conf.InitializeTestData(t)
|
||||
tensorFlow := NewTensorFlow(conf)
|
||||
|
||||
if imageBuffer, err := ioutil.ReadFile(conf.ExamplesPath() + "/chameleon_lime.jpg"); err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
result, err := tensorFlow.Labels(imageBuffer)
|
||||
|
||||
t.Log(result)
|
||||
|
||||
assert.NotNil(t, result)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.IsType(t, Labels{}, result)
|
||||
assert.Equal(t, 1, len(result))
|
||||
|
||||
assert.Equal(t, "chameleon", result[0].Name)
|
||||
|
||||
assert.Equal(t, 100-93, result[0].Uncertainty)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTensorFlow_Labels_Dog(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
conf := config.TestConfig()
|
||||
|
||||
tensorFlow := NewTensorFlow(conf)
|
||||
|
||||
if imageBuffer, err := ioutil.ReadFile(conf.ImportPath() + "/iphone/IMG_6788.JPG"); err != nil {
|
||||
if imageBuffer, err := ioutil.ReadFile(conf.ExamplesPath() + "/dog_orange.jpg"); err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
result, err := tensorFlow.Labels(imageBuffer)
|
||||
|
@ -61,42 +83,10 @@ func TestTensorFlow_Labels(t *testing.T) {
|
|||
assert.IsType(t, Labels{}, result)
|
||||
assert.Equal(t, 2, len(result))
|
||||
|
||||
assert.Equal(t, "tabby cat", result[0].Name)
|
||||
assert.Equal(t, "tiger cat", result[1].Name)
|
||||
assert.Equal(t, "chihuahua dog", result[0].Name)
|
||||
assert.Equal(t, "pembroke dog", result[1].Name)
|
||||
|
||||
assert.Equal(t, 100-68, result[0].Uncertainty)
|
||||
assert.Equal(t, 100-14, result[1].Uncertainty)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTensorFlow_Labels_Dog(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
conf := config.TestConfig()
|
||||
|
||||
conf.InitializeTestData(t)
|
||||
|
||||
tensorFlow := NewTensorFlow(conf)
|
||||
|
||||
if imageBuffer, err := ioutil.ReadFile(conf.ImportPath() + "/dog.jpg"); err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
result, err := tensorFlow.Labels(imageBuffer)
|
||||
|
||||
t.Log(result)
|
||||
|
||||
assert.NotNil(t, result)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.IsType(t, Labels{}, result)
|
||||
assert.Equal(t, 3, len(result))
|
||||
|
||||
assert.Equal(t, "beagle dog", result[0].Name)
|
||||
assert.Equal(t, "basset dog", result[1].Name)
|
||||
|
||||
assert.Equal(t, 91, result[0].Uncertainty)
|
||||
assert.Equal(t, 92, result[1].Uncertainty)
|
||||
assert.Equal(t, 34, result[0].Uncertainty)
|
||||
assert.Equal(t, 91, result[1].Uncertainty)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue