python - tensorflow convolution result to numpy
问题描述
I write a simple code,
import numpy as np
import tensorflow as tf
x_data = np.loadtxt('D:\proj\dnn_lib_cuda\input')
w_data = np.loadtxt('D:\proj\dnn_lib_cuda\weight')
x_tensor = np.reshape(x_data, (1, 3, 224, 224))
w_tensor = np.reshape(w_data, (64, 3, 3, 3))
x_tensor_ch = x_tensor.transpose(0, 2, 3, 1)
w_tensor_ch = w_tensor.transpose(2, 3, 1, 0)
x = tf.placeholder(tf.float32, shape = (1, 224, 224, 3))
w = tf.placeholder(tf.float32, shape = (3, 3, 3, 64))
result = tf.nn.conv2d(input = x, filter = w, strides = [1, 1, 1, 1], padding = 'SAME')
sess = tf.Session()
sess.run(result, feed_dict = {x: x_tensor_ch, w:w_tensor_ch})
print(result)
Now the result is a tensor with shape (1, 224, 224, 64), how can I get the data with numpy format?
解决方案
sess.run(...)
result
给定传递给的数据,返回计算张量的结果feed_dict
。
所以,你想要的是
output = sess.run(result, feed_dict = {x: x_tensor_ch, w:w_tensor_ch})
推荐阅读
- flutter - 每次我在 tabnavigator 中更改页面时,Flutter googlemaps 都会重新加载
- swift - 检测用户是否从文本字段复制文本
- python - 仅将文件 a 中的特定行写入文件 b
- python - 使用 sqlalchemy 的 pandas.read_sql 中的使用错误
- excel - VBA 属性调用 Get 而不是 Let
- ldap - 在 asn1c 中打印 LDAP 协议字段的人类可读值
- java - Java中要数组的文件列表
- python - 属性错误:“str”对象没有属性“desc”
- javascript - jsonschema 未在缺少必需属性时引发错误
- arrays - 从集合视图中的数组中抓取字符串时超出索引范围