尺寸在输出时不匹配

时间:2017-03-19 18:38:17

标签: python tensorflow

我有一个大小为32 * 32 * 3的输入图像,其中3是输入/颜色通道的数量。我正在尝试卷积并最大化结果。

spatial_glimpse_layer.py

class SGN(object):
    def __init__(self, w=32, filter_size=5, num_filters=96):
        self.input_x = tf.placeholder(tf.float32, [None, w, w, 3], name="X_train")
print(self.input_x)

现在在我的控制器中,我将图像传递给SGN并查看结果。

controller.py

import read_data
import tensorflow as tf
import numpy as np
import spatial_glimpse_network

data = read_data.read()

img = next(data)
img = np.expand_dims(np.resize(img, (32, 32, 3)), 0)
with tf.Graph().as_default():
    sess = tf.Session()
    with sess.as_default():
        cnn = spatial_glimpse_network.SGN()
        sess.run(tf.global_variables_initializer())
        pool = sess.run([cnn.input_x], feed_dict={cnn.input_x:img})
        print(img.shape)
        print(np.array(pool).shape)

输出如下: -

Tensor("X_train:0", shape=(?, 32, 32, 3), dtype=float32)
(1, 32, 32, 3)
(1, 1, 32, 32, 3)

我们可以看到输入的形式为1 * 32 * 32 * 3,其中1 =没有批次

最后的输出是不是形式为(1,32,32,3)?

有人可以帮忙吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

我认为原因是package testjava; public class CustomerAccount { int acctBalance; // private static int counter; public CustomerAccount(int initialBalance) { System.out.println("entered"); this.acctBalance=initialBalance; //System.out.println("objects created******************"+counter); } public void debitFood(int amt){ System.out.println("debiting food items::for"+Thread.currentThread().getName()); acctBalance = acctBalance-amt; System.out.println("New acct Balance after food debits::"+acctBalance); } public void debitClothes(int amt){ System.out.println("debiting clothescost::"+Thread.currentThread().getName()); acctBalance = acctBalance-amt; System.out.println("New acct Balance after clotehs debits::"+acctBalance); } public void debitTransport(int amt){ System.out.println("debiting transport::"+Thread.currentThread().getName()); acctBalance = acctBalance-amt; System.out.println("New acct Balance after transport debit::"+acctBalance); } public void debitLoans(int amt){ System.out.println("debiting loans::"+Thread.currentThread().getName()); acctBalance =acctBalance-amt; System.out.println("New acct Balance after Loans debit::"+acctBalance); } public void creditSalary(int salary){ System.out.println("crediting salary for ::"+Thread.currentThread().getName()); acctBalance =acctBalance+salary; System.out.println("New acct Balance after salary credit::"+acctBalance); } public void creditBonus(int salary){ System.out.println("crediting bonus for ::"+Thread.currentThread().getName()); acctBalance =acctBalance+salary; System.out.println("New acct Balance after salary credit::"+acctBalance); } } [],它会返回列表

由于您只有一个参数,您可以使用sess.run([cnn.input_x]),然后结果应该是正确的

如果您有多个参数
sess.run(cnn.input_x)或者 a_val, b_val = sess.run([a, b]) # split by it self