tensorflow - 如何在 tensorflow 中使用 CSR 格式
问题描述
我发现在tensorflow 中有一个 API(DenseToCSRSparseMatrix) tf.raw_ops
。但是,当我尝试进行从密集到 CSR 的简单对话时,它会引发以下异常:
Traceback (most recent call last):
File "/Users/", line 33, in <module>
print(sess.run(b))
File "/Users/mac/sparse-exp/lib/python3.9/site-packages/tensorflow/python/client/session.py", line 967, in run
result = self._run(None, fetches, feed_dict, options_ptr,
File "/Users/mac/sparse-exp/lib/python3.9/site-packages/tensorflow/python/client/session.py", line 1190, in _run
results = self._do_run(handle, final_targets, final_fetches,
File "/Users/mac/sparse-exp/lib/python3.9/site-packages/tensorflow/python/client/session.py", line 1368, in _do_run
return self._do_call(_run_fn, feeds, fetches, targets, options,
File "/Users/mac/sparse-exp/lib/python3.9/site-packages/tensorflow/python/client/session.py", line 1394, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InternalError: Tensorflow type 21 not convertible to numpy dtype.
这是我的示例代码:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
ss = tf.constant([[1, 2, 3, 4, 5], [0, 0, 0, 2, 1]], dtype=tf.float32)
indecies = tf.where(tf.not_equal(ss, 0))
b = tf.raw_ops.DenseToCSRSparseMatrix(dense_input=ss, indices=indecies)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(b))
解决方案
推荐阅读
- ios - 检测 UIKit for Mac (Catalyst) 中的单个修饰符键更改
- python - 为什么我的标签在 QHBoxLayout 中堆叠在一起?
- c# - 在 C# 中,一个类可以返回两种不同类型的对象,需要循环它们
- javascript - 如何在列表中添加空索引并使用 vuejs 和 axios 递增它
- ios - Swift - 过滤带有属性问题的自定义数组
- pyspark - Pyspark:将数据框写入 Cassandra 表不起作用
- php - 嵌入式表单 Symfony
- c# - 用于在工具箱中为自定义控件库添加选项卡的 Visual Studio 扩展
- kubernetes - 错误:无法启动补丁证书循环 mutatingwebhookconfigurations.admissionregistration.k8s.io “istio-sidecar-injector”未找到
- css - dropzone 图标显示在 dropzone 之外