python - Tensorflow 张量无法转换为 numpy
问题描述
我想转换tensorflow.python.framework.ops.Tensor
为 NumPy。
TensorFlow 版本是2.4.1
我试图搜索一些方法,但没有奏效。
x = tf.reshape(tf.io.decode_raw(x, tf.float64), (3, 4096))
x = x.numpy()
以上结果AttributeError: 'Tensor' object has no attribute 'numpy'
(我tf.executing_eagerly()
明确添加,但没有工作)
我试过x = x.eval(session=tf.compat.v1.Session())
了,但发生了以下错误。
InvalidArgumentError: You must feed a value for placeholder tensor 'args_0' with dtype string
请告诉我好主意。
解决方案
示例工作代码
import tensorflow as tf
x=[["1"],["23"]]
x = tf.reshape(tf.io.decode_raw(tf.constant(x), tf.uint8, fixed_length=4), (2,4))
x = x.numpy()
x
输出
array([[49, 0, 0, 0],
[50, 51, 0, 0]], dtype=uint8)
推荐阅读
- ios - 是否在表格视图单元格上选择没有响应
- android - 为什么显示和隐藏带有底部导航视图的片段不工作?
- php - Laravel 5.6 - Auth::check() 失败
- android - How to go from an Activity to a specific Fragment inside a TabActivity?
- bash - 使用 sed 将文件中的日期替换为另一个日期不起作用
- java - 在 Matlab 中运行时 Java 应用程序进度条颜色发生变化
- css - Firefox 与 Chrome 的 CSS Grid 网格模板列在图像大小上的行为存在差异
- apache-spark - hive / spark中的转换逻辑
- node.js - Angular 6,部署用户 http-server 后路由不起作用
- css - 没有定义列的纯 CSS 砌体布局