Skip to content
This repository has been archived by the owner on Feb 28, 2018. It is now read-only.

Reload a pre-trained model #4

Open
shiffman opened this issue Apr 12, 2017 · 3 comments
Open

Reload a pre-trained model #4

shiffman opened this issue Apr 12, 2017 · 3 comments

Comments

@shiffman
Copy link
Owner

Right now there is a button to download a JSON file with all of the network weights. It would be nice to add a feature to reload weights.

@makeyourownneuralnetwork

storing and reloading network weights is something I wish I had done ... especially for long training sessions with a laptop I need to turn off sometimes

@shiffman
Copy link
Owner Author

This feature should be built into nn.js as a save() and load() function.

@NatoBoram
Copy link

Saving is not that hard, JSON.stringify(nn) does the trick. Exporting, however, is painful.

function saveNN() {
	localStorage.setItem("nn", JSON.stringify(nn));
}

To load, I've tried so many things, but Matrices are hard to load.

function loadNN() {
	if (localStorage.getItem("nn") === null) {
		nn = new NeuralNetwork(100, 100, 100, 1/100, "tanh");
		console.log("Loaded a new neural network.");
	} else {
		nn = JSON.parse(localStorage.getItem("nn"));
		nn = Object.assign(new NeuralNetwork, nn);

		// This doesn't work. How do we do that?
		nn.wih = Object.assign(new Matrix, nn.wih);
		nn.woh = Object.assign(new Matrix, nn.woh);

		console.log("Loaded an existing neural network.");
	}
}

So, if you have an idea about how to do this, I'd be grateful :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants