def __init__(self,tty,serialSpeed,outputPath,upthreshold=5,downthreshold=5,isThresholdRelativeToMean=True,preLength=10,postLength=120,mode='threshold'): self.ser=serial.Serial(tty,serialSpeed) self.isThresholdRelativeToMean=isThresholdRelativeToMean self.upthreshold=upthreshold self.outputPath=outputPath self.downthreshold=downthreshold self.__isReading=False self.__inputLisners=[] self.maxPlotLen=500 self.plotY=deque([0.0]*self.maxPlotLen) self.plotX=np.arange(0,self.maxPlotLen) self.figure=plt.figure() self.minY=200 self.maxY=300 self.plt= plt.axes(xlim=(0, self.maxPlotLen), ylim=(self.minY,self.maxY)) self.plt.grid(True) self.line,=self.plt.plot([],[],lw=2) self.mean=-1 self.buffer=deque() self.inCapturing=False self.pre=preLength self.post=postLength self.__caputredSignalListner=[] self.fff=0; self.socketController=socketController('localhost',8080) init()
def init(learningRate, numOfEpochs, batchSize, dimension, model_iter): nn.init(learningRate, numOfEpochs, batchSize, dimension, model_iter)
def init(learningRate, numOfEpochs, batchSize, dimension): nn.init(learningRate, numOfEpochs, batchSize, dimension)
import sys import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import nn learnRate = 0.1 if len(sys.argv) > 1: #use given settings dropout = float(sys.argv[1]) momentum = float(sys.argv[2]) decay = float(sys.argv[3]) (model, optimizer, criterion) = nn.init(learnRate, momentum=momentum, dropout=dropout, wd=decay) (accv, errv, losst) = nn.fullTrain(model, optimizer, criterion) testAccuracy = nn.test(model) print('Test Accuracy:\t' + str(testAccuracy.item() * 100.) + "%\n") fig, ax1 = plt.subplots() ax1.set_xlabel('Epochs') ax1.set_ylabel('Validation Error', color='tab:red') ax1.plot(errv, color='tab:red') ax1.tick_params(axis='y', labelcolor='tab:red') ax2 = ax1.twinx()
import sys import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import nn if len(sys.argv) < 2: learnRates = [1., 0.1, 0.01, 0.001, 0.0001] else: learnRates = [float(sys.argv[1])] for learnRate in learnRates: print("######## LEARNING RATE = " + str(learnRate) + " ########\n") (model, optimizer, criterion) = nn.init(learnRate) (accv, errv, losst) = nn.fullTrain(model, optimizer, criterion) testAccuracy = nn.test(model) print('Test Accuracy:\t' + str(testAccuracy.item() * 100.) + '%\n') fig, ax1 = plt.subplots() ax1.set_xlabel('Epochs') ax1.set_ylabel('Validation Error', color='tab:red') ax1.plot(errv, color='tab:red') ax1.tick_params(axis='y', labelcolor='tab:red') ax2 = ax1.twinx() ax2.set_ylabel('Training Loss', color='tab:blue') ax2.plot(losst, color='tab:blue') ax2.tick_params(axis='y', labelcolor='tab:blue')