Example #1
0
def T6():
    '''
    Tests basic functionality of CNNC
    '''
    A = np.random.rand(32, 9, 9, 3)
    Y = np.array((16 * [1]) + (16 * [0]))
    ws = [('C', [3, 3, 3, 4], [1, 1, 1, 1]), ('P', [1, 4, 4, 1], [1, 2, 2, 1]), ('F', 16), ('F', 2)]
    a = CNNC([9, 9, 3], ws, maxIter = 12, name = "cnnc1")
    a.fit(A, Y)
    a.score(A, Y)
    a.predict(A)
    return True
Example #2
0
      ('C', [8, 5, NC, NC], [1, 8, 5, 1]), ('R', [-1, 64, NC])]
#Create the neural network in TensorFlow
cnnc = CNNC(IS,
            ws,
            batchSize=64,
            learnRate=5e-5,
            maxIter=4,
            reg=1e-5,
            tol=1e-2,
            verbose=True)
if not cnnc.RestoreModel('TFModel/', 'ocrnet'):
    A, Y, T, FN = LoadData()
    ss = ShuffleSplit(n_splits=1, random_state=42)
    trn, tst = next(ss.split(A))
    #Fit the network
    cnnc.fit(A[trn], Y[trn])
    #The predictions as sequences of character indices
    YH = []
    for i in np.array_split(np.arange(A.shape[0]), 32):
        YH.append(cnnc.predict(A[i]))
    YH = np.vstack(YH)
    #Convert from sequence of char indices to strings
    PS = np.array([''.join(YHi) for YHi in YH])
    #Compute the accuracy
    S1 = SAcc(PS[trn], T[trn])
    S2 = SAcc(PS[tst], T[tst])
    print('Train: ' + str(S1))
    print('Test: ' + str(S2))
    for PSi, Ti, FNi in zip(PS, T, FN):
        print(FNi + ': ' + Ti + ' -> ' + PSi)
    cnnc.SaveModel(os.path.join('TFModel', 'ocrnet'))