Closed cartal closed 4 years ago
Hi Cartal, I think this is a common issue for Keras package. Here I suggest 2 ways to solve it: 1) Make sure your environment is the same as one of the environment I listed, especially the version of Keras, since I have never encounter this error using my environments. 2) If you don't want to change your current environment, I think this page may be helpful: https://github.com/keras-team/keras/issues/13540#issuecomment-554213632 Please let me know if you still get the error.
Jian
Hi,
I'm happy to change my environment. I did so because my version of Keras
was keras = 2.4
instead of keras = 2.2.4
. Now I have keras = 2.2.4
but I get the following error:
/opt/conda/lib/python3.7/site-packages/scanpy/preprocessing/_simple.py:297: DeprecationWarning: Use is_view instead of isview, isview will be removed in the future.
if isinstance(data, AnnData) and data.isview:
the var_names of adata.raw: adata.raw.var_names.is_unique=: True
/opt/conda/lib/python3.7/site-packages/scanpy/preprocessing/_simple.py:297: DeprecationWarning: Use is_view instead of isview, isview will be removed in the future.
if isinstance(data, AnnData) and data.isview:
/opt/conda/lib/python3.7/site-packages/scanpy/_utils.py:341: DeprecationWarning: Use is_view instead of isview, isview will be removed in the future.
if adata.isview:
/opt/conda/lib/python3.7/site-packages/scanpy/preprocessing/_simple.py:297: DeprecationWarning: Use is_view instead of isview, isview will be removed in the future.
if isinstance(data, AnnData) and data.isview:
the var_names of adata.raw: adata.raw.var_names.is_unique=: True
/opt/conda/lib/python3.7/site-packages/scanpy/preprocessing/_simple.py:297: DeprecationWarning: Use is_view instead of isview, isview will be removed in the future.
if isinstance(data, AnnData) and data.isview:
/opt/conda/lib/python3.7/site-packages/scanpy/_utils.py:341: DeprecationWarning: Use is_view instead of isview, isview will be removed in the future.
if adata.isview:
The number of training celltypes is: 6
Training the source network
The layer numbers are[128, 32]
The shape of xtrain is:48449:1999
The shape of xtest is:12163:1999
Doing DEC: pretrain
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-15-5f83b1f46491> in <module>
----> 1 clf.fit(lymphoid_train, lymphoid_test, epochs_fit = 100)
/opt/conda/lib/python3.7/site-packages/ItClust/ItClust.py in fit(***failed resolving arguments***)
139 print(":".join(["The shape of xtest is",str(x_test.shape[0]),str(x_test.shape[1])]))
140 assert x_train.shape[1]==x_test.shape[1]
--> 141 dec=DEC(dims=dims,y=y_train,x=x_train,alpha=alpha,init=self.init,pretrain_epochs=self.pretrain_epochs,actinlayer1="tanh",softmax=softmax)
142 dec.compile(optimizer=SGD(lr=0.01,momentum=0.9))
143 #print("dec.init_centroid",type(dec.init_centroid),dec.init_centroid)
/opt/conda/lib/python3.7/site-packages/ItClust/DEC.py in __init__(self, dims, x, y, alpha, init, n_clusters, louvain_resolution, n_neighbors, pretrain_epochs, ae_weights, actinlayer1, is_stacked, transfer_feature, model_weights, y_trans, softmax)
115 self.pretrain_epochs=pretrain_epochs
116 if self.transfer_feature is None:
--> 117 self.pretrain(n_neighbors=n_neighbors,epochs=self.pretrain_epochs,n_clusters=n_clusters)
118 else:
119 self.pretrain_transfer(n_neighbors=n_neighbors,model_weights=self.model_weights,features=transfer_feature,epochs=self.pretrain_epochs,n_clusters=n_clusters,y_trans=self.y_trans)
/opt/conda/lib/python3.7/site-packages/ItClust/DEC.py in pretrain(self, optimizer, epochs, n_neighbors, batch_size, n_clusters)
121 def pretrain(self, optimizer='adam', epochs=200, n_neighbors=10,batch_size=256,n_clusters=None):
122 print("Doing DEC: pretrain")
--> 123 sae=SAE(dims=self.dims,drop_rate=0.2,batch_size=batch_size,actinlayer1=self.actinlayer1)# batch_size
124 print('...Pretraining...')
125 # begin pretraining
/opt/conda/lib/python3.7/site-packages/ItClust/SAE.py in __init__(self, dims, act, drop_rate, batch_size, actinlayer1, init)
38 self.init=init
39 self.batch_size = batch_size
---> 40 self.stacks = [self.make_stack(i) for i in range(self.n_stacks)]
41 self.autoencoders ,self.encoder= self.make_autoencoders()
42 #plot_model(self.autoencoders, show_shapes=True, to_file='autoencoders.png')
/opt/conda/lib/python3.7/site-packages/ItClust/SAE.py in <listcomp>(.0)
38 self.init=init
39 self.batch_size = batch_size
---> 40 self.stacks = [self.make_stack(i) for i in range(self.n_stacks)]
41 self.autoencoders ,self.encoder= self.make_autoencoders()
42 #plot_model(self.autoencoders, show_shapes=True, to_file='autoencoders.png')
/opt/conda/lib/python3.7/site-packages/ItClust/SAE.py in make_stack(self, ith)
82 if ith == self.n_stacks-1:
83 hidden_act = self.actinlayer1 #tanh, or linear
---> 84 model = Sequential()
85 model.add(Dropout(self.drop_rate, input_shape=(in_out_dim,)))
86 model.add(Dense(units=hidden_dim, activation=hidden_act, name='encoder_%d' % ith))
/opt/conda/lib/python3.7/site-packages/keras/engine/sequential.py in __init__(self, layers, name)
85
86 def __init__(self, layers=None, name=None):
---> 87 super(Sequential, self).__init__(name=name)
88 self._build_input_shape = None
89
/opt/conda/lib/python3.7/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your `' + object_name + '` call to the ' +
90 'Keras 2 API: ' + signature, stacklevel=2)
---> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper
/opt/conda/lib/python3.7/site-packages/keras/engine/network.py in __init__(self, *args, **kwargs)
94 else:
95 # Subclassed network
---> 96 self._init_subclassed_network(**kwargs)
97
98 def _base_init(self, name=None):
/opt/conda/lib/python3.7/site-packages/keras/engine/network.py in _init_subclassed_network(self, name)
292
293 def _init_subclassed_network(self, name=None):
--> 294 self._base_init(name=name)
295 self._is_graph_network = False
296 self._expects_training_arg = has_arg(self.call, 'training')
/opt/conda/lib/python3.7/site-packages/keras/engine/network.py in _base_init(self, name)
107 if not name:
108 prefix = self.__class__.__name__.lower()
--> 109 name = prefix + '_' + str(K.get_uid(prefix))
110 self.name = name
111
/opt/conda/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py in get_uid(prefix)
72 """
73 global _GRAPH_UID_DICTS
---> 74 graph = tf.get_default_graph()
75 if graph not in _GRAPH_UID_DICTS:
76 _GRAPH_UID_DICTS[graph] = defaultdict(int)
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
It looks like there is a compatibility issue with Keras and tensorflow, as described here and here. I have followed these solutions but I always get the same error.
Could you share your environment to see if there's an issue with our tensorflow
versions?
Sure thing. Currently, we are running ItClust using 2 environments and both works well. 1) System: Mac OS, keras = 2.2.4, tensorflow = 1.14.0. 2) System: Mac OS, keras = 2.1.5, tensorflow = 1.7.0.
Hi, thanks that solved my issue. I needed to install keras==2.2.4
together with tensorflow==1.14.0
and then it worked.
Hi,
Thanks for making this code available.
I'm having an issue with my training. I have my reference dataset, and I have split like this:
And then I train my model like this:
Then it runs and everything seems to go well, until it reaches this point
The shape of cluster_center is (5, 32)
:Which gives the following error message:
Any ideas on how to deal with this will be much appreciated!