theislab / dca

Deep count autoencoder for denoising scRNA-seq data
Apache License 2.0
246 stars 72 forks source link

Value error while running dca with scanpy #37

Closed Yolanda-HT closed 3 years ago

Yolanda-HT commented 4 years ago

I came across this error when running dca(adata) on a scanpy object in python 3.6.3 environment:

View of AnnData object with n_obs × n_vars = 1448 × 20615
    obs: 'cell_type'
    var: 'gene_ids', 'feature_types'
dca: Calculating reconstructions...
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: float() argument must be a string or a number, not 'csr_matrix'

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-6-d4407240a7c2> in <module>
----> 1 dca(adata)

/opt/applications/python/3.6.3/gnu/lib/python3.6/site-packages/dca/api.py in dca(adata, mode, ae_type, normalize_per_cell, scale, log1p, hidden_size, hidden_dropout, batchnorm, activation, init, network_kwds, epochs, reduce_lr, early_stop, batch_size, optimizer, learning_rate, random_state, threads, verbose, training_kwds, return_model, return_info, copy)
    193 
    194     hist = train(adata[adata.obs.dca_split == 'train'], net, **training_kwds)
--> 195     res = net.predict(adata, mode, return_info, copy)
    196     adata = res if copy else adata
    197 

/opt/applications/python/3.6.3/gnu/lib/python3.6/site-packages/dca/network.py in predict(self, adata, mode, return_info, copy, colnames)
    402 
    403         # warning! this may overwrite adata.X
--> 404         super().predict(adata, mode, return_info, copy=False)
    405         return adata if copy else None
    406 

/opt/applications/python/3.6.3/gnu/lib/python3.6/site-packages/dca/network.py in predict(self, adata, mode, return_info, copy)
    200             adata.uns['dca_loss'] = self.model.test_on_batch({'count': adata.X,
    201                                                               'size_factors': adata.obs.size_factors},
--> 202                                                              adata.raw.X)
    203         if mode in ('latent', 'full'):
    204             print('dca: Calculating low dimensional representations...')

/opt/applications/tensorflow/1.15.0/python3.6/gnu/lib/python3.6/site-packages/keras/engine/training.py in test_on_batch(self, x, y, sample_weight)
   1486             ins = x + y + sample_weights
   1487         self._make_test_function()
-> 1488         outputs = self.test_function(ins)
   1489         return unpack_singleton(outputs)
   1490 

/opt/applications/tensorflow/1.15.0/python3.6/gnu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in __call__(self, inputs)
   2977                     return self._legacy_call(inputs)
   2978 
-> 2979             return self._call(inputs)
   2980         else:
   2981             if py_any(is_tensor(x) for x in inputs):

/opt/applications/tensorflow/1.15.0/python3.6/gnu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in _call(self, inputs)
   2915                 array_vals.append(
   2916                     np.asarray(value,
-> 2917                                dtype=tf.as_dtype(tensor.dtype).as_numpy_dtype))
   2918         if self.feed_dict:
   2919             for key in sorted(self.feed_dict.keys()):

/opt/applications/python/3.6.3/gnu/lib/python3.6/site-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
     83 
     84     """
---> 85     return array(a, dtype, copy=False, order=order)
     86 
     87 

ValueError: setting an array element with a sequence.