如何为固定数据大小增加 deconv2d 过滤器的大小?
How to increase the size of deconv2d filters for a fixed data size?
我正在尝试调整此 DCGAN code 以便能够处理 2x80 数据样本。
所有 generator 层都是 tf.nn.deconv2d
除了 h0,它是 ReLu。当前每个级别的生成器过滤器大小为:
Generator: h0: s_h16 x s_w16: 1 x 5
Generator: h1: s_h8 x s_w8: 1 x 10
Generator: h2: s_h4 x s_w4: 1 x 20
Generator: h3: s_h2 x s_w2: 1 x 40
Generator: h4: s_h x s_w: 2 x 80
由于我的数据的性质,我希望它们最初生成为 2 x ...,即过滤器为 2 x 5
、2 x 10
、2 x 20
, 2 x 40
,和 2 x 80
。但是,当我只是手动输入 s_h16 = 2 * s_h16
等等直到 s_h2 = 2 * s_h2
时,我 运行 进入以下错误:
ValueError: Shapes (64, 1, 40, 64) and (64, 2, 40, 64) are not compatible
所以我知道错误发生在 h3 级别,但我无法完全追踪它(这里的 64 是批量大小)。任何想法如何解决这个问题?
编辑: 编辑的 DCGAN 代码是 in this repository, after the DCGAN-tensorflow is set-up as in the instructions 您必须将 Data_npy 文件夹放入 DCGAN-tensorflow/data
文件夹。
然后 运行ning python main.py --dataset Data_npy --input_height=2 --output_height=2 --train
将为您提供我得到的错误。
完整的错误回溯如下:
Traceback (most recent call last):
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_shape.py", line 560, in merge_with
new_dims.append(dim.merge_with(other[i]))
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_shape.py", line 135, in merge_with
self.assert_is_compatible_with(other)
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_shape.py", line 108, in assert_is_compatible_with
% (self, other))
ValueError: Dimensions 1 and 2 are not compatible
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 97, in <module>
tf.app.run()
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "main.py", line 80, in main
dcgan.train(FLAGS)
File "/home/marija/DCGAN-tensorflow/model.py", line 180, in train
.minimize(self.g_loss, var_list=self.g_vars)
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/training/optimizer.py", line 315, in minimize
grad_loss=grad_loss)
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/training/optimizer.py", line 386, in compute_gradients
colocate_gradients_with_ops=colocate_gradients_with_ops)
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/ops/gradients_impl.py", line 580, in gradients
in_grad.set_shape(t_in.get_shape())
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 413, in set_shape
self._shape = self._shape.merge_with(shape)
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_shape.py", line 564, in merge_with
(self, other))
ValueError: Shapes (64, 1, 40, 64) and (64, 2, 40, 64) are not compatible
在您的 ops.py 文件中
你的问题来自你的deconv过滤器中的跨步大小,将conv2d
和deconv2d
的header修改为:
def conv2d(input_, output_dim,
k_h=5, k_w=5, d_h=1, d_w=2, stddev=0.02,
name="conv2d"):
def deconv2d(input_, output_shape,
k_h=5, k_w=5, d_h=1, d_w=2, stddev=0.02,
name="deconv2d", with_w=False):
就这样开始训练我了。不过我没有检查输出。
问题在于考虑输入的形状,在反向传播过程中,将高度调整 2(d_h 的原始值)将导致 (64, 1, 40, 64)
形状。 (因为你只有2个值)
您可能还想将 k_h=5
更改为 k_h=2
,因为当您只有 2 个元素时,在高度上取 5 个元素没有多大意义。
我正在尝试调整此 DCGAN code 以便能够处理 2x80 数据样本。
所有 generator 层都是 tf.nn.deconv2d
除了 h0,它是 ReLu。当前每个级别的生成器过滤器大小为:
Generator: h0: s_h16 x s_w16: 1 x 5
Generator: h1: s_h8 x s_w8: 1 x 10
Generator: h2: s_h4 x s_w4: 1 x 20
Generator: h3: s_h2 x s_w2: 1 x 40
Generator: h4: s_h x s_w: 2 x 80
由于我的数据的性质,我希望它们最初生成为 2 x ...,即过滤器为 2 x 5
、2 x 10
、2 x 20
, 2 x 40
,和 2 x 80
。但是,当我只是手动输入 s_h16 = 2 * s_h16
等等直到 s_h2 = 2 * s_h2
时,我 运行 进入以下错误:
ValueError: Shapes (64, 1, 40, 64) and (64, 2, 40, 64) are not compatible
所以我知道错误发生在 h3 级别,但我无法完全追踪它(这里的 64 是批量大小)。任何想法如何解决这个问题?
编辑: 编辑的 DCGAN 代码是 in this repository, after the DCGAN-tensorflow is set-up as in the instructions 您必须将 Data_npy 文件夹放入 DCGAN-tensorflow/data
文件夹。
然后 运行ning python main.py --dataset Data_npy --input_height=2 --output_height=2 --train
将为您提供我得到的错误。
完整的错误回溯如下:
Traceback (most recent call last):
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_shape.py", line 560, in merge_with
new_dims.append(dim.merge_with(other[i]))
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_shape.py", line 135, in merge_with
self.assert_is_compatible_with(other)
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_shape.py", line 108, in assert_is_compatible_with
% (self, other))
ValueError: Dimensions 1 and 2 are not compatible
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 97, in <module>
tf.app.run()
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "main.py", line 80, in main
dcgan.train(FLAGS)
File "/home/marija/DCGAN-tensorflow/model.py", line 180, in train
.minimize(self.g_loss, var_list=self.g_vars)
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/training/optimizer.py", line 315, in minimize
grad_loss=grad_loss)
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/training/optimizer.py", line 386, in compute_gradients
colocate_gradients_with_ops=colocate_gradients_with_ops)
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/ops/gradients_impl.py", line 580, in gradients
in_grad.set_shape(t_in.get_shape())
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 413, in set_shape
self._shape = self._shape.merge_with(shape)
File "/home/marija/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_shape.py", line 564, in merge_with
(self, other))
ValueError: Shapes (64, 1, 40, 64) and (64, 2, 40, 64) are not compatible
在您的 ops.py 文件中
你的问题来自你的deconv过滤器中的跨步大小,将conv2d
和deconv2d
的header修改为:
def conv2d(input_, output_dim,
k_h=5, k_w=5, d_h=1, d_w=2, stddev=0.02,
name="conv2d"):
def deconv2d(input_, output_shape,
k_h=5, k_w=5, d_h=1, d_w=2, stddev=0.02,
name="deconv2d", with_w=False):
就这样开始训练我了。不过我没有检查输出。
问题在于考虑输入的形状,在反向传播过程中,将高度调整 2(d_h 的原始值)将导致 (64, 1, 40, 64)
形状。 (因为你只有2个值)
您可能还想将 k_h=5
更改为 k_h=2
,因为当您只有 2 个元素时,在高度上取 5 个元素没有多大意义。