numpy - 将 Tensorflow 张量转换为 Numpyarray
问题描述
我有一个class 'tensorflow.python.framework.ops.Tensor
作为输出,需要将其转换为一个 numpy 数组。
.numpy()不起作用,因为它不是一个eagerTensor。.eval 也不能正常工作,因为我使用的是tensorflow >2.0
有没有其他方法可以解决这个问题?
img_height=330
img_width=600
img_depth=23
save_model="saved_Models/wheatModel"
prediction_data_path=["data/stacked/MOD13Q1.A2017.2738.tif","data/stacked/MOD13Q1.A2017.889.tif","data/stacked/MOD13Q1.A2017.923.tif"]
prediction_data=dataConv.preparePredictionData(prediction_data_path)
prediction_reshaped=dataConv.reshapeFiles(prediction_data,img_width,img_height,img_depth)
x_ds =tf.stack(prediction_reshaped)
model = tf.keras.models.load_model(save_model)
model.predict(x_ds)
image=model.get_layer(name='prediction_image').output
n,output_width,output_height,output_depth,output_channels=image.shape
print(type(image))
image=tf.reshape(image,(output_width,output_height,output_depth))
print(type(image))
image.numpy()
所以在上面的代码中。
我加载训练有素的模型
预测给定的图像
获取倒数第二层的输出
重塑此数据
现在我想将此张量转换为 numpyarray
解决方案
推荐阅读
- android - 使用 Google 发布 API 修改版本的发行说明
- xml - XML 中值的特定部分/字符
- java - 模拟一个弹簧接口
- java - 如何在 Java 中实现 addFields mongoDB 查询
- node.js - 如果我对一个弹出另一个错误进行排序,则会显示两个错误 TypeError: cart is not a constructor in post method and cart.find is not a function
- excel - ORA-12560:TNS:协议适配器错误问题:Excel 64 位/Windows 10 64 位
- javascript - 选定天数随机排序,查找最早和最晚
- c# - 为什么持有类对象引用的接口类型变量不调用类成员函数?
- sas - 在宏函数之外定义宏变量的优点
- android - 操作栏中的中心图标