Ejemplo n.º 1
0
    input_var = T.tensor4('inputs')
    target_var = T.ivector('targets')
    enable = False
       
    if model_type == 1:
		path = 'p1.npz'
		filter = [16,32,256]
    elif model_type == 2:
		path = 'p2.npz'
		filter = [8,16,128]
    else:
		path = 'p3.npz'
		filter = [16,32,128]
		enable = True
		
    network = CNNL.convnetL(input_var,enable,filter)
	
    if loadmodel:
		print ("setting params")
		network.setParams(path)
    if training:		
        network.trainNetwork(trainX, trainY, validationX, validationY ,lRate ,num_epochs ,target_var, path)
	   
    
    pred = getPredictions(validationX,input_var)
    a = getAcc(pred,validationY)
    writeToFile('accuracy.csv',a,"id,accuracy")
	
    if model_type == 3:	
		pred = getPredictions(tX,input_var)
		a = analysis(pred,tY)
Ejemplo n.º 2
0
    rng = numpy.random.RandomState(42)
    br = BatchReader2.inputs()
    br2 = BatchReader2.inputs(testingData=True)
    X, Y = br.getNPArray(2)
    testX = br2.getNPArray(2)
    print testX.shape
    num_epochs = 200
    n = X.shape[0]
    sizeTrain = 0.8
    trainX = X[:n * sizeTrain].reshape(-1, 1, 48, 48)
    trainY = Y[:n * sizeTrain].astype('uint8')
    validationX = X[n * sizeTrain:].reshape(-1, 1, 48, 48)
    validationY = Y[n * sizeTrain:].astype('uint8')
    testX = testX.reshape(-1, 1, 48, 48)
    input_var = T.tensor4('inputs')
    target_var = T.ivector('targets')
    network = CNNL.convnetL(input_var)
    network.setParams('p3.npz')
    #network.trainNetwork(trainX, trainY, validationX, validationY ,0.08 ,num_epochs,target_var,0.0001,'p3.npz')
    #network.getParams('p3.npz')
    y = np.array([])
    for i in range(0, testX.shape[0] / 500):
        y = np.append(
            y, network.makePred(testX[i * 500:(i + 1) * 500], input_var))

    f = file('CNNL_Prediction.csv', 'w')
    f.write("Id,Prediction\n")
    for i, p in enumerate(y):
        f.write("%d,%d\n" % (i + 1, p))
    f.close()
if __name__ == '__main__':
    
    rng = numpy.random.RandomState(42)
    br = BatchReader2.inputs()
    br2 = BatchReader2.inputs(testingData = True)
    X, Y = br.getNPArray(2)
    testX = br2.getNPArray(2)
    print testX.shape
    num_epochs = 200
    n = X.shape[0]
    sizeTrain = 0.8
    trainX = X[:n*sizeTrain].reshape(-1,1,48,48)
    trainY = Y[:n*sizeTrain].astype('uint8')
    validationX = X[n*sizeTrain:].reshape(-1,1,48,48)
    validationY = Y[n*sizeTrain:].astype('uint8')
    testX = testX.reshape(-1,1,48,48)
    input_var = T.tensor4('inputs')
    target_var = T.ivector('targets')
    network = CNNL.convnetL(input_var)
    network.setParams('p3.npz')    
    #network.trainNetwork(trainX, trainY, validationX, validationY ,0.08 ,num_epochs,target_var,0.0001,'p3.npz')
    #network.getParams('p3.npz')
    y = np.array([])
    for i in range(0,testX.shape[0]/500):
        y = np.append(y,network.makePred(testX[i*500:(i+1)*500],input_var))

    f = file('CNNL_Prediction.csv','w')
    f.write("Id,Prediction\n")        
    for i,p in enumerate(y):
        f.write("%d,%d\n"%(i+1,p))
    f.close()