Acceptable format

What is an acceptable format to represent the image? A slice of bytes is useful for reading and displaying the image, but it's not particularly useful for doing any machine learning. Rather, we should want to represent the image as a slice of floating points. So, here's a function to convert a byte into a float64:

func pixelWeight(px byte) float64 {  retVal := float64(px)/pixelRange*0.9 + 0.1  if retVal == 1.0 {    return 0.999  }  return retVal}

This is essentially a scaling function that scales from 0-255 to between 0.0 and 1.0. There is an additional check; if the value is 1.0, we return 0.999 instead of 1. This is mainly due to the fact that when values are 1.0, numerical instability tends to happen, as mathematical functions ...

Get Go Machine Learning Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.