Code Monkey home page Code Monkey logo

vade's Introduction

VaDE

This repository contains the Python implementation for our generative clustering method VaDE.

Further details about VaDE can be found in our paper:

Variational Deep Embedding : A Generative Approach to Clustering Requirements

  • Python-3.4.4
  • keras-1.1.0
  • scikit-learn-1.17.1

Replace keras/engine/training.py by training.py in this repository!!

(The modification version of keras/engine/training.py enables the simultaneous updating of the gmm parameters and the network parameters in our model.)

Usage

  • To train the VaDE model on the MNIST, Reuters, HHAR datasets:
python ./VaDE.py db

db can be one of mnist,reuters10k,har.

  • To achieve the 94.46% clustering accuracy on the MNIST dataset and generate the class-specified digits (Note that: unlike Conditional GAN, we do not use any supervised information during training):
python ./VaDE_test_mnist.py
  • To achieve the 79.38% clustering accuracy on the Reuters(685K) dataset:
cd $VaDE_ROOT/dataset/reuters
./get_data.sh
cd $VaDE_ROOT
python ./VaDE_test_reuters_all.py

Note: the data preprocessing code for the Reuters dataset is taken from (https://github.com/piiswrong/dec).

Face generation by VaDE on CelebA

(DCGAN-like network architecture)

  • Attribute-conditioned generation (sampled from each cluster) without using any supervised information

1-6 rows: 1.black/short hair, man; 2.black/long hair, woman; 3.gold/long hair, woman; 4.bald, sunglasses, man; 5.left side face, woman; 6.right side face, woman; image

  • Interpolation between cluster centers in latent space image

  • Vector arithmetic in latent space:right + left = front image

vade's People

Contributors

slim1017 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vade's Issues

mnist_weights_gmm.mat vs. mnist_gene.mat

From what I know, the gmm network parameters (theta, lambda & u) are the results of the tensors (u_p, lambda_p & theta_p) after training. However, I noticed that the gmm network parameters in mnist_weights_gmm.mat and those in mnist_gene.mat have different values. Do anyone know where is the source for these two trained gmm parameter come from? Thank you

Do you ever train gamma_output?

When running VaDE.py on MNIST, I get a constant acc_p_c_z value of 0.11252857, regardless of how long I run. Looking at the code, it seems that while vade is compiled and trained, gamma_output is never trained. Am I missing something? I'm not a Theano user, so I might be missing something obvious.

AttributeError: 'tensor' object has no attribute 'broadcastable'

I am getting this error while running VaDE.py in windows. Can you please suggest how to solve the problem?

C:\Users\GIGL\VaDE-master>python VaDE.py dataset
Using TensorFlow backend.
WARNING (theano.configdefaults): g++ not available, if using conda: conda insta ll m2w64-toolchain
C:\Program Files\Python35\lib\site-packages\theano\configdefaults.py:560: UserWa
rning: DeprecationWarning: there is no c++ compiler.This is deprecated and with
Theano 0.11 a c++ compiler will be mandatory
warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to exe
cute optimized C-implementations (for both CPU and GPU) and will default to Pyth
on implementations. Performance will be severely degraded. To remove this warnin
g, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS fu
nctions.
training on: mnist
Traceback (most recent call last):
File "VaDE.py", line 249, in
Gamma = Lambda(get_gamma, output_shape=(n_centroid,))(z)
File "C:\Program Files\Python35\lib\site-packages\keras\engine\topology.py", l
ine 603, in call
output = self.call(inputs, **kwargs)
File "C:\Program Files\Python35\lib\site-packages\keras\layers\core.py", line
651, in call
return self.function(inputs, **arguments)
File "VaDE.py", line 111, in get_gamma
temp_Z=T.transpose(K.repeat(tempz,n_centroid),[0,2,1])
File "C:\Program Files\Python35\lib\site-packages\theano\tensor\basic.py", lin
e 3691, in transpose
ret = DimShuffle(x.broadcastable, axes)(x)
AttributeError: 'Tensor' object has no attribute 'broadcastable'

training with new data

Hi,
I am training VaDE with my own dataset.
My X is of the shape 1603x1992.
I have followed your paper and your code. However, I am getting a Dimension Mismatch at the 'gamma_output.predict(X,batchsize = 100)' point.
the first layer of my gamma_output model is
input_24 (InputLayer) (100, 1992)
My error is

Input dimension mis-match. (input[0].shape[0] = 3, input[5].shape[0] = 100) Apply node that caused the error: Elemwise{Composite{(i0 + i1 + (exp((i2 * (i3 + i4))) * i5))}}[(0, 0)](InplaceDimShuffle{0,x,x,1}.0, InplaceDimShuffle{x,x,x,0}.0, TensorConstant{(1, 1, 1, 1) of 0.5}, InplaceDimShuffle{0,x,x,1}.0, InplaceDimShuffle{x,x,x,0}.0, InplaceDimShuffle{0,x,x,1}.0) Toposort index: 41 Inputs types: [TensorType(float32, (False, True, True, False)), TensorType(float32, (True, True, True, False)), TensorType(float32, (True, True, True, True)), TensorType(float32, (False, True, True, False)), TensorType(float32, (True, True, True, False)), TensorType(float32, (False, True, True, False))] Inputs shapes: [(3, 1, 1, 18), (1, 1, 1, 18), (1, 1, 1, 1), (3, 1, 1, 18), (1, 1, 1, 18), (100, 1, 1, 18)] Inputs strides: [(72, 72, 72, 4), (72, 72, 72, 4), (4, 4, 4, 4), (72, 72, 72, 4), (72, 72, 72, 4), (72, 72, 72, 4)] Inputs values: ['not shown', 'not shown', array([[[[0.5]]]], dtype=float32), 'not shown', 'not shown', 'not shown'] Inputs type_num: [11, 11, 11, 11, 11, 11] Outputs clients: [[Alloc(Elemwise{Composite{(i0 + i1 + (exp((i2 * (i3 + i4))) * i5))}}[(0, 0)].0, Shape_i{0}.0, TensorConstant{1}, TensorConstant{18}, Shape_i{1}.0)]]
Can you please help me solve this or interpret it?

Derivation of the VADE-loss

The function that has been mentioned for VADE-loss, could I get a reference to the derivation. I need the mathematical derivation for a project of mine

ValueError: Invalid argument "add_trainable_weights" passed to K.function with Theano backend

Hi folks,

I've been trying to reproduce the results with python 3.7.7. After substituting training.py, i receive a ValueError. I aint an expert in low-level coding with keras and I am curios if it is worth to adapt the code for newer python versions. I am able to compile the model, but there are some problems with vade.fit()

keras - 2.3.1
theano - 1.0.5

vade.compile(optimizer=adam_nn,
loss=vae_loss,
add_trainable_weights=[theta_p,u_p,lambda_p],
add_optimizer=adam_gmm,
)

epoch_begin=EpochBegin()
vade.fit(X_train, X_train,
shuffle=True,
epochs=epoch,
batch_size=batch_size,
callbacks=[epoch_begin])


ValueError Traceback (most recent call last)
/tmp/ipykernel_3305833/3949754183.py in
3 epochs=epoch,
4 batch_size=batch_size,
----> 5 callbacks=[epoch_begin])

~/anaconda3/lib/python3.7/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
1211 else:
1212 fit_inputs = x + y + sample_weights
-> 1213 self._make_train_function()
1214 fit_function = self.train_function
1215

~/anaconda3/lib/python3.7/site-packages/keras/engine/training.py in _make_train_function(self)
331 updates=updates + metrics_updates,
332 name='train_function',
--> 333 **self._function_kwargs)
334
335 def _make_test_function(self):

~/anaconda3/lib/python3.7/site-packages/keras/backend/theano_backend.py in function(inputs, outputs, updates, **kwargs)
1451 for key in kwargs.keys():
1452 if not has_arg(theano.function, key, True):
-> 1453 _raise_invalid_arg(key)
1454 return Function(inputs, outputs, updates=updates, **kwargs)
1455

~/anaconda3/lib/python3.7/site-packages/keras/backend/theano_backend.py in _raise_invalid_arg(key)
1444 def _raise_invalid_arg(key):
1445 msg = 'Invalid argument "%s" passed to K.function with Theano backend' % key
-> 1446 raise ValueError(msg)
1447
1448

ValueError: Invalid argument "add_trainable_weights" passed to K.function with Theano backend

The loss function

I am confused about the loss function in the code, for different parts int the loss functions, it has different + or - symbols between the paper and the code? Can someone help to verify it?

AttributeError: 'Tensor' object has no attribute 'broadcastable'

When I run $ python3 ./VaDE_test_mnist.py
it shows error:
Using TensorFlow backend.
Traceback (most recent call last):
File "./VaDE_test_mnist.py", line 124, in
p_c_z = Lambda(get_gamma, output_shape=(n_centroid,))(z_mean)
File "/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py", line 602, in call
output = self.call(inputs, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/keras/layers/core.py", line 650, in call
return self.function(inputs, **arguments)
File "./VaDE_test_mnist.py", line 90, in get_gamma
temp_Z=T.transpose(K.repeat(tempz,n_centroid),[0,2,1])
File "/usr/local/lib/python3.5/dist-packages/theano/tensor/basic.py", line 3567, in transpose
ret = DimShuffle(x.broadcastable, axes)(x)
AttributeError: 'Tensor' object has no attribute 'broadcastable'

Any clue on this? Thanks a lot.

ValueError: Invalid argument "add_optimizer" passed to K.function with Theano backend

Hi, I cloned your git and try to run "python VaDE.py mnist". But got the following errors:

Using Theano backend.
training on: mnist
pretrain weights loaded!
Traceback (most recent call last):
File "VaDE.py", line 266, in
callbacks=[epoch_begin])
File "build/bdist.macosx-10.7-x86_64/egg/keras/engine/training.py", line 1607, in fit
'''Generates predictions for the input samples from a data generator.
File "build/bdist.macosx-10.7-x86_64/egg/keras/engine/training.py", line 996, in _make_train_function
check_array_lengths(x, y, sample_weights)
File "build/bdist.macosx-10.7-x86_64/egg/keras/backend/theano_backend.py", line 1231, in function
ValueError: Invalid argument "add_optimizer" passed to K.function with Theano backend

Please advise.

cannot import name Container

Hi,

I am trying to execute your code for the following versions of theano, keras and sklearn

Keras - '2.2.4'
Theano - '1.0.3'
sklearn - '0.20.1'

I had to make some modifications to your VaDE.py code by changing GMM to GaussianMixture. Now, when replacing the training.py at keras/engine/ with the one included in your code results in the following error. Can you please help me out with this?

Using Theano backend.
Traceback (most recent call last):
File "VaDE.py", line 14, in
from keras.callbacks import Callback
File "/Users/vineeth/anaconda2/envs/DeepLearning/lib/python2.7/site-packages/keras/init.py", line 3, in
from . import utils
File "/Users/vineeth/anaconda2/envs/DeepLearning/lib/python2.7/site-packages/keras/utils/init.py", line 27, in
from .multi_gpu_utils import multi_gpu_model
File "/Users/vineeth/anaconda2/envs/DeepLearning/lib/python2.7/site-packages/keras/utils/multi_gpu_utils.py", line 7, in
from ..layers.merge import concatenate
File "/Users/vineeth/anaconda2/envs/DeepLearning/lib/python2.7/site-packages/keras/layers/init.py", line 4, in
from ..engine.base_layer import Layer
File "/Users/vineeth/anaconda2/envs/DeepLearning/lib/python2.7/site-packages/keras/engine/init.py", line 8, in
from .training import Model
File "/Users/vineeth/anaconda2/envs/DeepLearning/lib/python2.7/site-packages/keras/engine/training.py", line 15, in
from .topology import Container
ImportError: cannot import name Container

I appreciate your help in advance.

Thanks
Vineeth

Training.py modification

I am new to writing codes; it has been instructed to "Replace keras/engine/training.py by training.py in this repository!!", but I can not understand where in this repository I make the changes?

Please someone help me.

same class probablities

Hi, I translated your code to keras with tensorflow backend and run VaDE model on a simulated GMM data set. However, I always get same probabilities for all classes. For example, assuming I have four classes, then I always get [0.25, 0.25, 0.25, 0.25] from gamma_output. Is it a bug in your code?

Amplitudes of the GMM

Hi,

How do you ensure that the amplitudes of the GMM (pi[i]) remain positive and sum to unity, when minimizing the cost function with respect to these amplitudes? Thanks.

Gordon

Pretrain code?

Where can I see the codes to make files such as 'ae_XXXX.json' and ''ae_XXXX_weights.h5'?

Question on Hyperparameter Selection

I recently came across this paper on arxiv, and then found the implementation here - great work! I was wondering if you could give any guidance on hyperparameter selection, especially the alpha parameter? I don't see its mention in the original paper, and it seems to act like a regularization strength. Small values tend to force all mixture components to be the same, while larger values allow for different means/variances. Do you have any further insights in how to set that parameter?

Open source license?

I read about this approach at NLP Day in Austin. Is there a chance that you're willing to put an open source license on this?

Pretraining

Hi,
My team and I are trying to duplicate the results of your paper, but cannot. Would it be possible to gain access to the code that pretrains the data? That would help us a lot. Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.