0

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?

1 Answer 1

1

sess.run(...) returns the result of evaluating the tensor result given the data passed to feed_dict.

So, what you want is

output = sess.run(result, feed_dict = {x: x_tensor_ch, w:w_tensor_ch})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.