Exemplo n.º 1
0
def pre_training(df, cfg):
    # Train autoencoder as pre training
    encoder_train = df[:-int(len(df) * cfg['test_size'])]
    print(encoder_train)
    train_x = []
    for name, values in df.iteritems():
        x, _ = split_sequence(values.values.reshape(-1, 1), cfg)
        train_x.append(x)
    train_x = np.asarray(train_x)
    train_x = train_x.reshape([
        train_x.shape[0] * train_x.shape[1], train_x.shape[2], train_x.shape[3]
    ])
    print(train_x.shape)
    encoder, decoder, cfg = build_autoencoder(
        train_x, cfg, weights='weights//pretrained_encoder.hdf5')

    # Test autoencoder on holdout data
    #encoder_test = data.x_test
    #predictions = decoder.predict(encoder_test)

    #mse = 0
    #for i in range(len(predictions)):
    #    mse += mean_squared_error(encoder_test[i], predictions[i])
    #print('Test mean mse:', mse/len(predictions))

    return encoder, cfg
def pre_training(data, cfg):
    # Train autoencoder as pre training
    train, test = data.get_x()
    encoder, decoder, cfg = build_autoencoder(train, cfg, weights='weights//pretrained_encoder.hdf5')

    # Test autoencoder on holdout data
    predictions = decoder.predict(test)

    mse = 0
    for i in range(len(predictions)):
        mse += mean_squared_error(test[i], predictions[i])
    print('Test mean mse:', mse/len(predictions))

    return encoder, cfg
Exemplo n.º 3
0
def train_autoencoder(data, cfg):
    # Train autoencoder as pre training
    encoder_train = np.concatenate([data.train_conv, data.train_org], axis=0)
    encoder, decoder, cfg = build_autoencoder(encoder_train, cfg, weights='weights//pretrained_encoder.hdf5')
    return encoder, cfg