MyNN icon indicating copy to clipboard operation
MyNN copied to clipboard

Add support for exporting models

Open davidmascharka opened this issue 3 years ago • 1 comments

The current solution looks like iterating through the model parameters and np.saveing all the weights, then np.loading them in a new model. We should support actually serializing a model

davidmascharka avatar Jul 21 '20 17:07 davidmascharka

def save_model(self, path):
    """Path to .npz file where model parameters will be saved."""
    with open(path, "wb") as f:
        np.savez(f, *(x.data for x in self.parameters))

def load_model(self, path):
    with open(path, "rb") as f:
        for param, (name, array) in zip(self.parameters, np.load(f).items()):
            param.data[:] = array

davidmascharka avatar Jul 24 '20 16:07 davidmascharka