quacknet.writeAndReadWeightBias
1import numpy as np 2 3class writeAndRead: 4 def write(self, pathToWeight="ExampleCode/MNISTExample/WeightsAndBiases/weights.txt", pathToBias="ExampleCode/MNISTExample/WeightsAndBiases/biases.txt"): 5 weightFile = open(pathToWeight, "w") 6 for a in range(len(self.weights)): 7 for b in range(len(self.weights[a])): 8 currLine = " ".join(map(str, self.weights[a][b])) 9 weightFile.write(currLine + "\n") 10 weightFile.write("\n") 11 weightFile.close() 12 13 biasFile = open(pathToBias, "w") 14 for a in range(len(self.biases)): 15 currLine = " ".join(map(str, self.biases[a])) 16 biasFile.write(currLine + "\n") 17 biasFile.close() 18 19 def read(self, pathToWeight="ExampleCode/MNISTExample/WeightsAndBiases/weights.txt", pathToBias="ExampleCode/MNISTExample/WeightsAndBiases/biases.txt"): 20 weightFile = open(pathToWeight, "r") 21 layerWeights = [] 22 for line in weightFile: 23 line = line.strip() 24 if(line == ""): 25 if(len(layerWeights) > 0): 26 self.weights.append(np.array(layerWeights)) 27 layerWeights = [] 28 else: 29 l = [] 30 for i in line.split(): 31 l.append(float(i)) 32 layerWeights.append(l) 33 34 if(len(layerWeights) > 0): 35 self.weights.append(layerWeights) 36 weightFile.close() 37 38 biasFile = open(pathToBias, "r") 39 layerWeights = [] 40 for line in biasFile: 41 line = line.strip() 42 if(line != ""): 43 line = list(map(float, line.split())) 44 self.biases.append(line) 45 biasFile.close()
class
writeAndRead:
4class writeAndRead: 5 def write(self, pathToWeight="ExampleCode/MNISTExample/WeightsAndBiases/weights.txt", pathToBias="ExampleCode/MNISTExample/WeightsAndBiases/biases.txt"): 6 weightFile = open(pathToWeight, "w") 7 for a in range(len(self.weights)): 8 for b in range(len(self.weights[a])): 9 currLine = " ".join(map(str, self.weights[a][b])) 10 weightFile.write(currLine + "\n") 11 weightFile.write("\n") 12 weightFile.close() 13 14 biasFile = open(pathToBias, "w") 15 for a in range(len(self.biases)): 16 currLine = " ".join(map(str, self.biases[a])) 17 biasFile.write(currLine + "\n") 18 biasFile.close() 19 20 def read(self, pathToWeight="ExampleCode/MNISTExample/WeightsAndBiases/weights.txt", pathToBias="ExampleCode/MNISTExample/WeightsAndBiases/biases.txt"): 21 weightFile = open(pathToWeight, "r") 22 layerWeights = [] 23 for line in weightFile: 24 line = line.strip() 25 if(line == ""): 26 if(len(layerWeights) > 0): 27 self.weights.append(np.array(layerWeights)) 28 layerWeights = [] 29 else: 30 l = [] 31 for i in line.split(): 32 l.append(float(i)) 33 layerWeights.append(l) 34 35 if(len(layerWeights) > 0): 36 self.weights.append(layerWeights) 37 weightFile.close() 38 39 biasFile = open(pathToBias, "r") 40 layerWeights = [] 41 for line in biasFile: 42 line = line.strip() 43 if(line != ""): 44 line = list(map(float, line.split())) 45 self.biases.append(line) 46 biasFile.close()
def
write( self, pathToWeight='ExampleCode/MNISTExample/WeightsAndBiases/weights.txt', pathToBias='ExampleCode/MNISTExample/WeightsAndBiases/biases.txt'):
5 def write(self, pathToWeight="ExampleCode/MNISTExample/WeightsAndBiases/weights.txt", pathToBias="ExampleCode/MNISTExample/WeightsAndBiases/biases.txt"): 6 weightFile = open(pathToWeight, "w") 7 for a in range(len(self.weights)): 8 for b in range(len(self.weights[a])): 9 currLine = " ".join(map(str, self.weights[a][b])) 10 weightFile.write(currLine + "\n") 11 weightFile.write("\n") 12 weightFile.close() 13 14 biasFile = open(pathToBias, "w") 15 for a in range(len(self.biases)): 16 currLine = " ".join(map(str, self.biases[a])) 17 biasFile.write(currLine + "\n") 18 biasFile.close()
def
read( self, pathToWeight='ExampleCode/MNISTExample/WeightsAndBiases/weights.txt', pathToBias='ExampleCode/MNISTExample/WeightsAndBiases/biases.txt'):
20 def read(self, pathToWeight="ExampleCode/MNISTExample/WeightsAndBiases/weights.txt", pathToBias="ExampleCode/MNISTExample/WeightsAndBiases/biases.txt"): 21 weightFile = open(pathToWeight, "r") 22 layerWeights = [] 23 for line in weightFile: 24 line = line.strip() 25 if(line == ""): 26 if(len(layerWeights) > 0): 27 self.weights.append(np.array(layerWeights)) 28 layerWeights = [] 29 else: 30 l = [] 31 for i in line.split(): 32 l.append(float(i)) 33 layerWeights.append(l) 34 35 if(len(layerWeights) > 0): 36 self.weights.append(layerWeights) 37 weightFile.close() 38 39 biasFile = open(pathToBias, "r") 40 layerWeights = [] 41 for line in biasFile: 42 line = line.strip() 43 if(line != ""): 44 line = list(map(float, line.split())) 45 self.biases.append(line) 46 biasFile.close()