Code Monkey home page Code Monkey logo

keras_deep_clustering's Introduction

How to Run

Require Python 3.5+ and Jupyter notebook installed

Clone or download this repo

git clone https://github.com/Tony607/Keras_Deep_Clustering

Install required libraries

pip3 install -r requirements.txt

In the project start a command line run

jupyter notebook

In the opened browser window open

Keras-DEC.ipynb

If you want to skip the training, you can try the pre-trained weights from the releases, results.zip. Extract results folders to the root of the project directory.

Happy coding! Leave a comment if you have any question.

keras_deep_clustering's People

Contributors

tony607 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

keras_deep_clustering's Issues

TypeError: add_weight() got multiple values for argument 'name'

when run the code:
class ClusteringLayer(Layer):

def __init__(self, n_clusters, weights=None, alpha=1.0, **kwargs):
    if 'input_shape' not in kwargs and 'input_dim' in kwargs:
        kwargs['input_shape'] = (kwargs.pop('input_dim'),)
    super(ClusteringLayer, self).__init__(**kwargs)
    self.n_clusters = n_clusters
    self.alpha = alpha
    self.initial_weights = weights
    self.input_spec = InputSpec(ndim=2)

def build(self, input_shape):
    assert len(input_shape) == 2
    input_dim = input_shape[1]
    self.input_spec = InputSpec(dtype=K.floatx(), shape=(None, input_dim))
    self.clusters = self.add_weight((self.n_clusters, input_dim), initializer='glorot_uniform', name='clusters')
    if self.initial_weights is not None:
        self.set_weights(self.initial_weights)
        del self.initial_weights
    self.built = True

def call(self, inputs, **kwargs):
    q = 1.0 / (1.0 + (K.sum(K.square(K.expand_dims(inputs, axis=1) - self.clusters), axis=2) / self.alpha))
    q **= (self.alpha + 1.0) / 2.0
    q = K.transpose(K.transpose(q) / K.sum(q, axis=1)) # Make sure each sample's 10 values add up to 1.
    return q

def compute_output_shape(self, input_shape):
    assert input_shape and len(input_shape) == 2
    return input_shape[0], self.n_clusters

def get_config(self):
    config = {'n_clusters': self.n_clusters}
    base_config = super(ClusteringLayer, self).get_config()
    return dict(list(base_config.items()) + list(config.items()))

clustering_layer = ClusteringLayer(n_clusters, name='clustering')(encoder.output)
model = Model(inputs=encoder.input, outputs=clustering_layer)

TypeError: add_weight() got multiple values for argument 'name'

iris data

have you tried using this on a tabular data, e.g. iris ? (with a smaller number of nodes and parameters). do you think, makes sense to try it out ?

Check the results

Hello, I'm not an expert in this field however I'm trying to do something on it. One simple question: Why are you using x as x=np.concatenate (x_train,x_test)? How can you check the NN's performance if you don't separate x_train from x_test?
Thanks in advance

Understanding issues of custom layer- "ClusteringLayer"

Thank you for sharing the code.
I am new in Keras. I know it is a stupid idea to ask this bellow question.
In ClusteringLayer, the encoder.output shpae is (?,10) which has been passed through the custom layer. When I pass the encoder.output weights to the custom layer "Bulid function", it generates weights for self.clustering by the size of(10,10) i.e the n_clusters is 10 and input_shape[1] is 10. Is it so? or I am missing something.
In "Call function", specifically in this line, q = 1.0 / (1.0 + (K.sum(K.square(K.expand_dims(inputs, axis=1) - self.clusters), axis=2) / self.alpha)), why do you use K.expand_dims? What is the purpose of using this?

Please help me to figure out these two problems.
Again thank you for sharing the beautiful code.

No license attached to code

Hi!
Very interested in using your code, but you have not attached a license!

Could you perhaps do so? The BSD and MIT licenses are probably the most used in the scientific python community.

Thanks!

ValueError: Layer AE was called with an input that isn't a symbolic tensor. Received type: <class 'int'>. Full input: [784, 500, 500, 2000, 10]. All inputs to the layer should be tensors.

when I try to run the part
Model to train clustering and autoencoder at same time(Fully connected)!
I get the
ValueError: Layer AE was called with an input that isn't a symbolic tensor. Received type: <class 'int'>. Full input: [784, 500, 500, 2000, 10]. All inputs to the layer should be tensors.
pls hel fix it

unknown number of clusters

What if we don't know the number of clusters ?! and if the case is something like tabular data (many users with demographical data) do we need the autoencoder model ?!
How I can invest your code in data as I mentioned?

Saving the clustered images to a folder?

Hello,
How do you save the results of the model into their respective cluster folders? In this case there is 10 clusters so then there should be 10 folders with images from the clusters inside.

None label evaluate ?

There is a data set that only knows the category but does not have an annotation for each image. How to evaluate it?

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.