python - 如何在tensorflow中使用稀疏矩阵(csr_matrix作为anndata格式)?
问题描述
我正在尝试使用scDeepCluster
框架来处理单个单元格数据。我已经从 github 下载了原始代码并修复了一些版本错误。
但是当我将数据输入模型进行预训练时,出现以下错误。
TypeError: Could not build a TypeSpec for <30000x18896 sparse matrix of type '<class 'numpy.float32'>'
with 4734184 stored elements in Compressed Sparse Row format> with type csr_matrix
During handling of the above exception, another exception occurred:
TypeError: sparse matrix length is ambiguous; use getnnz() or shape[0]
这是代码:
def pretrain(self, x, y, batch_size=256, epochs=200, optimizer='adam', ae_file='ae_weights.h5'):
print('...Pretraining autoencoder...')
self.autoencoder.compile(loss=self.loss, optimizer=optimizer)
es = EarlyStopping(monitor="loss", patience=50, verbose=1)
self.autoencoder.fit(x=x, y=y, batch_size=batch_size, epochs=epochs, callbacks=[es])
self.autoencoder.save_weights(ae_file)
print('Pretrained weights are saved to ./' + str(ae_file))
self.pretrained = True
我使用以下句子调用这些代码,其中adata
是一个AnnData
对象。
scDeepCluster.pretrain(x=[adata.X, adata.obs.size_factors],
y=adata.raw.X,
batch_size=256,
epochs=600,
optimizer=optimizer1,
ae_file='ae_weights.h5')
我已经减少了数据量,但错误仍然存在。错误与模型结构有关吗?或者是否有任何参数可以使用稀疏矩阵设置来拟合模型?
我如何在张量流中使用稀疏矩阵来解决这个问题?非常感谢 :)
解决方案
推荐阅读
- ionic4 - Stenciljs:路由到新内容并且不能更改背景
- java - 在java中使用RC4加密图像
- c# - 发送多个 httpclient 或 httpresponse 时 UI 挂起
- python - 如果进程(文件)由外部程序打开,如何使用 Python 关闭它?
- c# - UWP 如何使用 AudioGraph API 暂停录音?
- r - 如何选择 R 数据框中两列的所有唯一组合?
- node.js - 是否可以在语音通道中映射具有某些权限的人?不和谐.js
- google-data-studio - 对两个不同的数据源使用相同的过滤器控件
- javascript - 带有文本和值下拉列表的 Kendo UI 网格过滤器
- c# - 如何读取文件中的数据并将行保存到二维表中