Updating our CNN to save the model

We need to add a simple function to our CNN example to ensure the model that gets produced is saved, so it can be managed as an object by Pachyderm. Let's add the following to main.go:

func (m *convnet) savemodel() (err error) {
learnables := m.learnables()
var f io.WriteCloser
if f, err = os.OpenFile("model.bin", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644); err != nil {
return
}
defer f.Close()
enc := json.NewEncoder(f)
for _, l := range learnables {
t := l.Value().(*tensor.Dense).Data() // []float32
if err = enc.Encode(t); err != nil {
return
}
}

return nil
}
..................Content has been hidden....................

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