Taking a closer look

Alternatively, you may also want to inspect the predictions coming out, in order to get a better understanding of what's happening in your model. In that case, you may wish to extract your results into a .csv file, which you can do with the following code:

arrayOutput := m.predVal.Data().([]float64)
yOutput := tensor.New(tensor.WithShape(bs, 10), tensor.WithBacking(arrayOutput))

file, err := os.OpenFile(fmt.Sprintf("%d.csv", b), os.O_CREATE|os.O_WRONLY, 0777)
if err = xVal.(*tensor.Dense).Reshape(bs, 784); err != nil {
log.Fatal("Unable to create csv", err)
}
defer file.Close()
var matrixToWrite [][]string

for j := 0; j < yOutput.Shape()[0]; j++ {
rowT, _ := yOutput.Slice(sli{j, j + 1})
row := rowT.Data().([]float64)
var rowToWrite []string

for k := 0; k < 10; k++ {
rowToWrite = append(rowToWrite, strconv.FormatFloat(row[k], 'f', 6, 64))
}
matrixToWrite = append(matrixToWrite, rowToWrite)
}

csvWriter := csv.NewWriter(file)
csvWriter.WriteAll(matrixToWrite)
csvWriter.Flush()

The output for the offending digit can be seen in the following screenshot and code output.

The following is the screenshot output:

You can also observe the same output in code:

[ 0  0  0.000457  0.99897  0  0  0  0.000522  0.000051  0 ]

Likewise, you can see it wavers from a good guess if only slightly, as shown in the following screenshot: 


In code format, this is also the same:

[0 0 0 0 0 0 0 1 0 0]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.113.55