August 2019
Intermediate to advanced
242 pages
5h 45m
English
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}
Read now
Unlock full access