Last active
August 17, 2019 09:34
-
-
Save owulveryck/3d15c0eb9cf7dea6518116ec0a5be581 to your computer and use it in GitHub Desktop.
yolo testing material
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func eqInDelta(a,b tensor.Tensor, delta float32) bool { | |
outputValue := outputT[0].Data().([]float32) | |
expectedValue := expectedOutput.Data().([]float32) | |
if ! outputT[0].Shape().Eq(expectedOutput.Shape()) { | |
return false | |
} | |
for i := 0; i < len(outputValue); i++ { | |
if math.Abs(float64(outputValue[i]-expectedValue[i])) > delta { | |
return false | |
} | |
} | |
return true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io/ioutil" | |
"os" | |
"testing" | |
"github.com/owulveryck/onnx-go" | |
"github.com/owulveryck/onnx-go/backend/x/gorgonnx" | |
"github.com/stretchr/testify/assert" | |
"gorgonia.org/tensor" | |
) | |
var ( | |
modelONNX = "../FACES/yolo.onnx" | |
npyZeroResult = "../FACES/keras/output.npy" | |
) | |
func TestYOLO(t *testing.T) { | |
b, err := ioutil.ReadFile(modelONNX) | |
check(t, err) | |
backend := gorgonnx.NewGraph() | |
model := onnx.NewModel(backend) | |
err = model.UnmarshalBinary(b) | |
check(t, err) | |
inputT := tensor.New( | |
tensor.WithShape(1, 416, 416, 3), | |
tensor.Of(tensor.Float32)) | |
err = model.SetInput(0, inputT) | |
check(t, err) | |
err = backend.Run() | |
check(t, err) | |
outputT, err := model.GetOutputTensors() | |
check(t, err) | |
file, err := os.Open(npyZeroResult) | |
check(t, err) | |
defer file.Close() | |
expectedOutput := new(tensor.Dense) | |
err = expectedOutput.ReadNpy(file) | |
check(t, err) | |
assert.Equal(t, expectedOutput.Shape(), outputT[0].Shape()) | |
outputValue := outputT[0].Data().([]float32) | |
expectedValue := expectedOutput.Data().([]float32) | |
assert.InDeltaSlice(t, expectedValue, outputValue, 5e-5) | |
} | |
func check(t *testing.T, err error) { | |
if err != nil { | |
t.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment