amten / NeuralNetwork

Java (convolutional or fully-connected) neural network implementation with plugin for Weka. Uses dropout and rectified linear units.
108 stars 31 forks source link

saving and retrieving trained NN #12

Closed gitnichi closed 6 years ago

gitnichi commented 6 years ago

Hello, thank you for writing such a good code, it's really easy to get it running and experimenting quickly! I'm using the NNs to classify a data set unrelated to weka, therefore I need to train my NN before using it and then use the trained NN with data from the users, in a live fashion. Since training takes several hours, I can't afford to train it every time I need to use it. I haven't found any methods in your code to save the NN's weights, nor configuration. I found in a weka related page the following code:

Debug.saveToFile(filename+"_nn.dat", nn); then, to load in the classifying part:
SerializedClassifier classifier = new SerializedClassifier(); classifier.setModelFile(new File("/path/to/weka-neural-network"));

Will this work with your code,i.e. if I use instead of "SerializedClassifier" NNParams params = new NNParams(); params.numClasses = 10; // 10 digits to classify params.hiddenLayerParams = myNNconfig and then classifier.setModelFile(new File("/path/to/weka-neural-network"));?

Thank you very much for your help!

gitnichi commented 6 years ago

I've already solved it, using the write/readCSV of the MatrixUtils class, here is the code if someone needs it, just put into the NeuralNetwork class the following methods: /**