fferroni / DEC-Keras

Deep Embedding Clustering in Keras
GNU General Public License v3.0
130 stars 59 forks source link

DEC in TensorFlow 1.3; AttributeError: can't set attribute #8

Open NatLun091238 opened 7 years ago

NatLun091238 commented 7 years ago

Thank you for posting the code! I attempted to implement your code in TF 1.3 making the following changes:

import tensorflow.contrib.keras.api.keras as K
from tensorflow.contrib.keras.api.keras.initializers import RandomNormal
from tensorflow.contrib.keras.api.keras.layers import Layer, InputSpec
from tensorflow.contrib.keras.api.keras.models import Model, Sequential
from tensorflow.contrib.keras.api.keras.layers import Dense, Dropout, Input
from tensorflow.contrib.keras.api.keras.optimizers import SGD
from tensorflow.contrib.keras.api.keras.callbacks import LearningRateScheduler
from tensorflow.contrib.keras.api.keras.backend import floatx

However, I encounter en error message pointing to line#71, which is the last line in the following:

def build(self, input_shape):
        assert len(input_shape) == 2
        input_dim = input_shape[1]
        self.input_spec = [InputSpec(dtype=K.backend.floatx(),
                                     shape=(None, input_dim))]

        self.W = K.backend.variable(self.initial_weights) 
        self.trainable_weights = [self.W]

layerwise pretrain and Finetuning autoencoder works fine on the test example (mnist), but then Initializing cluster centres with k-means. crushes with an error message:

self.trainable_weights = K.backend.variable(self.initial_weights)

AttributeError: can't set attribute

What could be the reason for that??? Thanks in advance.