sarsbug / DCN_keras

Keras Implementation of "Towards K-means-friendly Spaces: Simultaneous Deep Learning and Clustering"
11 stars 3 forks source link

something wrong #1

Open lhy2749 opened 4 years ago

lhy2749 commented 4 years ago

after model predict y,the result is: acc: 0.1918 nmi: 0.11572 ari: 0.04568 could you please tell why is that?

MingxuanY commented 4 years ago

Actually the function get_centers_and_types_of_points is wrong. You can replace the first two lines in this function with the code below.

    from scipy.spatial import distance as sd
    distances = sd.cdist(reductX, self.centers)
    label_types = np.argmin(distances, axis = 1)

after model predict y,the result is: acc: 0.1918 nmi: 0.11572 ari: 0.04568 could you please tell why is that?

JosephKJ commented 3 years ago

I believe that is not the only reason for the drop in performance.

Apparently, dcn is trained with a wrong loss. Do compile it before training as below:

if ae_weights is None:
    pretrain_epochs = 200
    dcn.pretrain(x=x_train,epochs=pretrain_epochs)
else:
    dcn.autoencoder.load_weights(ae_weights)

dcn.compile()  # Please note this. This resets the loss. 
dcn.init_centers(x_train,y_train)

I get:

acc: 0.8558
nmi: 0.80288
ari: 0.75729

Further, if you are using the Keras that comes with the latest TensorFlow, you need to disable eager mode by:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()