簡體   English   中英

如何針對固定數據大小增加deconv2d過濾器的大小?

[英]How to increase the size of deconv2d filters for a fixed data size?

我正在嘗試調整此DCGAN代碼 ,以便能夠使用2x80數據樣本。

所有生成器層都是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 402 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這里是批量大小)。 任何想法如何解決這個問題?


編輯:編輯DCGANs代碼是在這個倉庫中,DCGAN-tensorflow上設定好后, 以指令中 ,你不得不Data_npy文件夾放到DCGAN-tensorflow/data文件夾中。

然后運行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過濾器中的跨步大小,將conv2ddeconv2d的標頭修改為:

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) 64,1,40,64 (64, 1, 40, 64)形狀產生。 (因為你只有2個值)

你也可以考慮將k_h=5更改為k_h=2因為當你只有2個沒有那么多意義時,將5個元素放在高度上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM