前提・実現したいこと
pix2pixを用いてある画像から予測したある画像を生成したいです。
発生している問題・エラーメッセージ
こちらのGithubを参考にし、自前のデータセットで学習できるよう書き換えをしているのですが、
AssertionError: Height in the output should be positive.
というエラーが出て困っています。
試したこと
調べた際に『画像を畳み込んだら画像がなくなったのでは』と出てきたのでpaddingを調べたのですが、それを行っているConvolution2Dのところを見てもどうしたらいいのかが分からないです…。
class CBR内のL.Convolution2D(ch0, ch1, 4, 2, 1, initialW=w)をL.Convolution2D(ch0, ch1, 4, 1, 1, initialW=w)にしたところ、エラーが表示されなくなりましたが固まったようになり、動きません。
これはうまくいってて学習中なのか、無限ループかなにかに陥っているのかが分かりません。
python
1# -*- coding: utf-8 -*- 2""" 3Created on Wed Jan 9 16:52:30 2019 4 5@author: KNO3 6""" 7 8#!/usr/bin/env python 9 10from __future__ import print_function 11 12import numpy 13 14import chainer 15from chainer import cuda 16import chainer.functions as F 17import chainer.links as L 18 19# U-net https://arxiv.org/pdf/1611.07004v1.pdf 20 21# convolution-batchnormalization-(dropout)-relu 22class CBR(chainer.Chain): 23 def __init__(self, ch0, ch1, bn=True, sample='down', activation=F.relu, dropout=False): 24 self.bn = bn 25 self.activation = activation 26 self.dropout = dropout 27 layers = {} 28 w = chainer.initializers.Normal(0.02) 29 if sample=='down': 30 layers['c'] = L.Convolution2D(ch0, ch1, 4, 2, 1, initialW=w) 31 else: 32 layers['c'] = L.Deconvolution2D(ch0, ch1, 4, 2, 1, initialW=w) 33 if bn: 34 layers['batchnorm'] = L.BatchNormalization(ch1) 35 super(CBR, self).__init__(**layers) 36 37 def __call__(self, x): 38 h = self.c(x) 39 if self.bn: 40 h = self.batchnorm(h) 41 if self.dropout: 42 h = F.dropout(h) 43 if not self.activation is None: 44 h = self.activation(h) 45 return h 46 47class Encoder(chainer.Chain): 48 def __init__(self, in_ch): 49 layers = {} 50 w = chainer.initializers.Normal(0.02) 51 layers['c0'] = L.Convolution2D(in_ch, 64, 3, 1, 1, initialW=w) 52 layers['c1'] = CBR(64, 128, bn=True, sample='down', activation=F.leaky_relu, dropout=False) 53 layers['c2'] = CBR(128, 256, bn=True, sample='down', activation=F.leaky_relu, dropout=False) 54 layers['c3'] = CBR(256, 512, bn=True, sample='down', activation=F.leaky_relu, dropout=False) 55 layers['c4'] = CBR(512, 512, bn=True, sample='down', activation=F.leaky_relu, dropout=False) 56 layers['c5'] = CBR(512, 512, bn=True, sample='down', activation=F.leaky_relu, dropout=False) 57 layers['c6'] = CBR(512, 512, bn=True, sample='down', activation=F.leaky_relu, dropout=False) 58 layers['c7'] = CBR(512, 512, bn=True, sample='down', activation=F.leaky_relu, dropout=False) 59 super(Encoder, self).__init__(**layers) 60 61 def __call__(self, x): 62 hs = [F.leaky_relu(self.c0(x))] 63 for i in range(1,8): 64 hs.append(self['c%d'%i](hs[i-1])) 65 return hs 66 67class Decoder(chainer.Chain): 68 def __init__(self, out_ch): 69 layers = {} 70 w = chainer.initializers.Normal(0.02) 71 layers['c0'] = CBR(512, 512, bn=True, sample='up', activation=F.relu, dropout=True) 72 layers['c1'] = CBR(1024, 512, bn=True, sample='up', activation=F.relu, dropout=True) 73 layers['c2'] = CBR(1024, 512, bn=True, sample='up', activation=F.relu, dropout=True) 74 layers['c3'] = CBR(1024, 512, bn=True, sample='up', activation=F.relu, dropout=False) 75 layers['c4'] = CBR(1024, 256, bn=True, sample='up', activation=F.relu, dropout=False) 76 layers['c5'] = CBR(512, 128, bn=True, sample='up', activation=F.relu, dropout=False) 77 layers['c6'] = CBR(256, 64, bn=True, sample='up', activation=F.relu, dropout=False) 78 layers['c7'] = L.Convolution2D(128, out_ch, 3, 1, 1, initialW=w) 79 super(Decoder, self).__init__(**layers) 80 81 def __call__(self, hs): 82 h = self.c0(hs[-1]) 83 for i in range(1,8): 84 h = F.concat([h, hs[-i-1]]) 85 if i<7: 86 h = self['c%d'%i](h) 87 else: 88 h = self.c7(h) 89 return h 90 91 92class Discriminator(chainer.Chain): 93 def __init__(self, in_ch, out_ch): 94 layers = {} 95 w = chainer.initializers.Normal(0.02) 96 layers['c0_0'] = CBR(in_ch, 32, bn=False, sample='down', activation=F.leaky_relu, dropout=False) 97 layers['c0_1'] = CBR(out_ch, 32, bn=False, sample='down', activation=F.leaky_relu, dropout=False) 98 layers['c1'] = CBR(64, 128, bn=True, sample='down', activation=F.leaky_relu, dropout=False) 99 layers['c2'] = CBR(128, 256, bn=True, sample='down', activation=F.leaky_relu, dropout=False) 100 layers['c3'] = CBR(256, 512, bn=True, sample='down', activation=F.leaky_relu, dropout=False) 101 layers['c4'] = L.Convolution2D(512, 1, 3, 1, 1, initialW=w) 102 super(Discriminator, self).__init__(**layers) 103 104 def __call__(self, x_0, x_1): 105 h = F.concat([self.c0_0(x_0), self.c0_1(x_1)]) 106 h = self.c1(h) 107 h = self.c2(h) 108 h = self.c3(h) 109 h = self.c4(h) 110 #h = F.average_pooling_2d(h, h.data.shape[2], 1, 0) 111 return h 112
補足情報(FW/ツールのバージョンなど)
python 3.6.6のspyderを使用してます。
学習させる画像の大きさはすべて149*115ピクセルです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。