コード例 #1
0
def encode_dataset(model_path, min_std=0.0):

    VAE = VariationalAutoencoder(
        dim_x=28 * 28, dim_z=50)  #Should be consistent with model being loaded
    with VAE.session:
        VAE.saver.restore(VAE.session, VAE_model_path)

        enc_x_lab_mean, enc_x_lab_var = VAE.encode(x_lab)
        enc_x_ulab_mean, enc_x_ulab_var = VAE.encode(x_ulab)
        enc_x_valid_mean, enc_x_valid_var = VAE.encode(x_valid)
        enc_x_test_mean, enc_x_test_var = VAE.encode(x_test)

        id_x_keep = np.std(enc_x_ulab_mean, axis=0) > min_std
        print(id_x_keep)
        #       enc_x_lab_mean, enc_x_lab_var = enc_x_lab_mean[ :, id_x_keep ], enc_x_lab_var[ :, id_x_keep ]
        #       enc_x_ulab_mean, enc_x_ulab_var = enc_x_ulab_mean[ :, id_x_keep ], enc_x_ulab_var[ :, id_x_keep ]
        #       enc_x_valid_mean, enc_x_valid_var = enc_x_valid_mean[ :, id_x_keep ], enc_x_valid_var[ :, id_x_keep ]
        #       enc_x_test_mean, enc_x_test_var = enc_x_test_mean[ :, id_x_keep ], enc_x_test_var[ :, id_x_keep ]

        #        data_lab = np.hstack( [ enc_x_lab_mean, enc_x_lab_var ] )
        #        data_ulab = np.hstack( [ enc_x_ulab_mean, enc_x_ulab_var ] )
        #        data_valid = np.hstack( [enc_x_valid_mean, enc_x_valid_var] )
        #        data_test = np.hstack( [enc_x_test_mean, enc_x_test_var] )
        #        print(data_lab.shape)

        data_lab = np.hstack([enc_x_lab_mean, enc_x_lab_var])
        data_ulab = np.hstack([enc_x_ulab_mean, enc_x_ulab_var])
        data_valid = np.hstack([enc_x_valid_mean, enc_x_valid_var])
        data_test = np.hstack([enc_x_test_mean, enc_x_test_var])
        print(data_lab.shape)

    return data_lab, data_ulab, data_valid, data_test
コード例 #2
0
def encode_dataset(model_path, x_lab, x_ulab, x_valid, x_test, min_std=0.0):

    dim_x = x_lab.shape[1]
    VAE = VariationalAutoencoder(
        dim_x=dim_x, dim_z=50)  #Should be consistent with model being loaded
    with VAE.session:
        VAE.saver.restore(VAE.session, model_path)

        enc_x_lab_mean, enc_x_lab_var = VAE.encode(x_lab)
        enc_x_ulab_mean, enc_x_ulab_var = VAE.encode(x_ulab)
        enc_x_valid_mean, enc_x_valid_var = VAE.encode(x_valid)
        enc_x_test_mean, enc_x_test_var = VAE.encode(x_test)

        id_x_keep = np.std(enc_x_ulab_mean, axis=0) > min_std

        enc_x_lab_mean, enc_x_lab_var = enc_x_lab_mean[:,
                                                       id_x_keep], enc_x_lab_var[:,
                                                                                 id_x_keep]
        enc_x_ulab_mean, enc_x_ulab_var = enc_x_ulab_mean[:,
                                                          id_x_keep], enc_x_ulab_var[:,
                                                                                     id_x_keep]
        enc_x_valid_mean, enc_x_valid_var = enc_x_valid_mean[:,
                                                             id_x_keep], enc_x_valid_var[:,
                                                                                         id_x_keep]
        enc_x_test_mean, enc_x_test_var = enc_x_test_mean[:,
                                                          id_x_keep], enc_x_test_var[:,
                                                                                     id_x_keep]

        data_lab = np.hstack([enc_x_lab_mean, enc_x_lab_var])
        data_ulab = np.hstack([enc_x_ulab_mean, enc_x_ulab_var])
        data_valid = np.hstack([enc_x_valid_mean, enc_x_valid_var])
        data_test = np.hstack([enc_x_test_mean, enc_x_test_var])

    return data_lab, data_ulab, data_valid, data_test
コード例 #3
0
def encode_dataset( model_path, min_std = 0.0 ):

    VAE = VariationalAutoencoder( dim_x = 28*28, dim_z = 50 ) #Should be consistent with model being loaded
    with VAE.session:
        VAE.saver.restore( VAE.session, VAE_model_path )

        enc_x_lab_mean, enc_x_lab_var = VAE.encode( x_lab )
        enc_x_ulab_mean, enc_x_ulab_var = VAE.encode( x_ulab )
        enc_x_valid_mean, enc_x_valid_var = VAE.encode( x_valid )
        enc_x_test_mean, enc_x_test_var = VAE.encode( x_test )

        id_x_keep = np.std( enc_x_ulab_mean, axis = 0 ) > min_std

        enc_x_lab_mean, enc_x_lab_var = enc_x_lab_mean[ :, id_x_keep ], enc_x_lab_var[ :, id_x_keep ]
        enc_x_ulab_mean, enc_x_ulab_var = enc_x_ulab_mean[ :, id_x_keep ], enc_x_ulab_var[ :, id_x_keep ]
        enc_x_valid_mean, enc_x_valid_var = enc_x_valid_mean[ :, id_x_keep ], enc_x_valid_var[ :, id_x_keep ]
        enc_x_test_mean, enc_x_test_var = enc_x_test_mean[ :, id_x_keep ], enc_x_test_var[ :, id_x_keep ]

        data_lab = np.hstack( [ enc_x_lab_mean, enc_x_lab_var ] )
        data_ulab = np.hstack( [ enc_x_ulab_mean, enc_x_ulab_var ] )
        data_valid = np.hstack( [enc_x_valid_mean, enc_x_valid_var] )
        data_test = np.hstack( [enc_x_test_mean, enc_x_test_var] )

    return data_lab, data_ulab, data_valid, data_test