Python 动态转置后的卷积(tensorflow)

Python 动态转置后的卷积(tensorflow),python,tensorflow,transpose,Python,Tensorflow,Transpose,我试图实现本文中的体系结构:(在第3页的顶部) 问题是,我的数据集包含不同大小的图像,当尝试在与动态形状转置后应用卷积时,未知形状将导致错误: ValueError: Shape of a new variable (fuse01/weights) must be fully defined, but instead was (3, 3, ?, 10). 这是我的代码: import tensorflow as tf import numpy as np slim = tf.contrib.

我试图实现本文中的体系结构:(在第3页的顶部)

问题是,我的数据集包含不同大小的图像,当尝试在与动态形状转置后应用卷积时,未知形状将导致错误:

ValueError: Shape of a new variable (fuse01/weights) must be fully defined, but instead was (3, 3, ?, 10).
这是我的代码:

import tensorflow as tf
import numpy as np

slim = tf.contrib.slim


def conv(input_batch, nb_kernel, nb_row, nb_col, scope_name, strides=None):
    if strides is None:
        strides = 1
    with slim.arg_scope([slim.conv2d], padding='SAME', stride=strides):
        out = slim.conv2d(input_batch, nb_kernel, [nb_row, nb_col], scope=scope_name)
    return out


def conv_trans(input_batch, nb_kernel, nb_row, nb_col, name_scope, stride, output_like):
    with tf.name_scope(name_scope):
        weights = get_weights([nb_row, nb_col, nb_kernel, input_batch.get_shape()[3].value])
        out_shape = tf.shape(output_like)
        out_shape = [input_batch.get_shape()[0].value, out_shape[1], out_shape[2], nb_kernel]
        output = tf.nn.conv2d_transpose(input_batch, weights, out_shape, [1, stride, stride, 1])
        return output


def get_weights(shape):
    initializer = tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32)
    variable = tf.Variable(initializer(shape=shape), name='weights')
    return variable

a = np.ones([1, 165, 167, 3], np.float32)
x = tf.placeholder(tf.float32, [1, None, None, 3])

net = conv(x, 10, 3, 3, 'conv1')
net = conv(net, 20, 3, 3, 'conv2', strides=2)
skip_01 = net
net = conv(net, 40, 3, 3, 'conv3', strides=2)
skip_02 = net
net = conv(net, 80, 3, 3, 'conv4', strides=2)
skip_03 = net
net = conv(net, 160, 3, 3, 'conv5', strides=2)
up_01 = conv_trans(net, 30, 3, 3, 'test', 2, skip_03) # shape: (?, ?, ?, ?)
fuse_01 = tf.concat([skip_03, up_01], 3) # shape: (1, ?, ?, ?)

init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)

print fuse_01
print sess.run(fuse_01, feed_dict={x: a})

fuse_01 = conv(fuse_01, 10, 3, 3, 'fuse01')  # this will cause error
应用
conv_transpose
后,有没有办法得到张量的具体形状

问题是,我的数据集包含不同大小的图像,在尝试

最简单的方法就是在一开始就将所有图像转换为相同的大小。您正在尝试从图像中删除雨/雪,因此图像的大小应该无关紧要