//Load a SavedRecognizer from a file public void Load(string filename) { NeuralNetworkStub stub = Utils.Instance.ReadNeuralNetworkStub(filename); outputs = stub.gestures; neuralNet = new NeuralNetwork(stub.numInput, stub.numHidden, stub.numOutput); neuralNet.SetWeights(stub.weights); }
//Load a SavedRecognizer from a file public void Load(string filename) { gestureSettings = Utils.GetGestureSettings(); NeuralNetworkStub stub = Utils.ReadNeuralNetworkStub(filename); outputs = stub.gestures; BuildOutputDictionary(); neuralNet = new NeuralNetwork(stub.numInput, stub.numHidden, stub.numOutput); neuralNet.SetWeights(stub.weights); }
public static NeuralNetworkStub ReadNeuralNetworkStub(string networkName) { string path = Application.streamingAssetsPath + Config.NEURAL_NET_PATH + networkName + "/" + networkName + ".txt"; if (System.IO.File.Exists(path)) { string[] lines = System.IO.File.ReadAllLines(path); NeuralNetworkStub stub = JsonUtility.FromJson <NeuralNetworkStub>(string.Concat(lines)); return(stub); } else { NeuralNetworkStub stub = new NeuralNetworkStub(); stub.gestures = new List <Gesture>(); return(stub); } }
} // SplitTrainTest public void SaveNeuralNetwork(double[] weights) { NeuralNetworkStub stub = new NeuralNetworkStub(); stub.numInput = numInput; stub.numHidden = numHidden; stub.numOutput = numOutput; stub.gestures = gestures; stub.weights = weights; string filePath = Application.streamingAssetsPath + Config.NEURAL_NET_PATH + recognizerName + "/" + recognizerName + ".txt"; using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath, false)) { //file.WriteLine(dumbString); file.WriteLine(JsonUtility.ToJson(stub, true)); } #if UNITY_EDITOR AssetDatabase.ImportAsset(filePath); #endif }
public NeuralNetworkStub ReadNeuralNetworkStub(string networkName) { string path = Config.SAVE_FILE_PATH + networkName + "/" + networkName + ".txt"; if (System.IO.File.Exists(path)) { string[] lines = System.IO.File.ReadAllLines(path); ////System.IO.File. string inputLine = lines[0]; NeuralNetworkStub stub = JsonUtility.FromJson <NeuralNetworkStub>(inputLine); return(stub); } else { NeuralNetworkStub stub = new NeuralNetworkStub(); stub.gestures = new List <string>(); return(stub); } }