Closed gitnichi closed 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: /**
it's up to the developer to specify them properly when invoking the NN constructor */
public void loadNN(String filename){
mySoftmax = myParams.numClasses > 1;
myNumOutputs = myParams.numClasses;
// Add null params for layer 0, which is just the input and last layer, which is just output.
myLayerParams = new NNParams.NNLayerParams[myParams.hiddenLayerParams.length+2];
System.arraycopy(myParams.hiddenLayerParams, 0, myLayerParams, 1, myParams.hiddenLayerParams.length);
myLayerParams[myLayerParams.length-1] = new NNParams.NNLayerParams(myNumOutputs);
myParams.numThreads = myParams.numThreads > 0 ? myParams.numThreads : Runtime.getRuntime().availableProcessors();
myExecutorService = Executors.newFixedThreadPool(myParams.numThreads);
int numLayers = myLayerParams.length;
initThetas();
for (int layer = 1; layer < numLayers; layer++)
try{
myThetas[layer]=MatrixUtils.readCSV(filename+"_l"+layer+".csv",',', 0);
}catch(Exception e) {System.out.println(e.toString());}
}
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!