Exemplo n.º 1
0
def pre_train(mini_batch_size=1000):
    lsq = LSQ()
    '''bug bug bug'''
    sample_dict = tcdp.random_select_samples()

    mode = 'train'
    for _, (index, features, labels) in enumerate(tcdl.iter_mini_batches(mode, sample_dict[mode], mini_batch_size=mini_batch_size)):
        y, rmse = lsq.train(features, labels)
        # np.savetxt('ys_train_lsq.txt', np.hstack((index, labels, y)))
        print(y.tolist()[-6:], '\n', labels.tolist()[-6:], '\n', rmse)
        break

    mode = 'valid'
    for _, (index, features, labels) in enumerate(tcdl.iter_mini_batches('train', sample_dict[mode], mini_batch_size=2000)):
        y, rmse = lsq.predict(features, labels)
        # np.savetxt('ys_valid_lsq.txt', np.hstack((index, labels, y)))
        print(y.tolist()[-6:], '\n', labels.tolist()[-6:], '\n', rmse)
        break

    # mode = 'testA'
    # for _, (index, features, labels) in enumerate(tcdl.iter_mini_batches(mode, sample_dict[mode], mini_batch_size=2000)):
    #     y, rmse = lsq.predict(features, labels)
    #     np.savetxt('ys_testA_lsq.txt', np.hstack((index, labels, y)))
    #     print(y.tolist()[-6:], '\n', labels.tolist()[-6:], '\n', rmse)
    #     break
    #
    # print('\n')

    return (lsq.weights).astype(np.float32)
Exemplo n.º 2
0
    return ori_labels, pre_labels


if __name__ == '__main__':
    n_input = 4 * 101 * 101
    n_hidden = 1024
    n_output = 1
    n_steps = 15
    dropout = 0.75
    cnn = cnn2d(n_input, n_hidden, n_output, n_steps, dropout)
    print('a cnn model is created! ')


    for i in range(128):
        sample_dict = tcdp.random_select_samples()

        print('training ... ')
        cnn2d_train('train', cnn, sample_dict, i)

        print('validating ... ')
        ys_train = cnn2d_valid('train', cnn, sample_dict, i)
        ys_valid = cnn2d_valid('valid', cnn, sample_dict, i)
        ys_testA = cnn2d_valid('testA', cnn, sample_dict, i)

        obj = {'train': ys_train, 'valid': ys_valid, 'testA': ys_testA}
        fn2 = 'ys_cnn_model_%d.cpk' % (i + 1)
        loader.saveObject(obj, fn2)

        ''''''
        # #break