【エラー】chainer numpy and cupy arrays are mixed in the forward input


モデル定義部分の__init__の中身を
with self.init_scope():
でやり方に変わってる。
この部分を書き換えたら直った。


```py:旧
class Discriminator(chainer.Chain):
    def __init__(self, input_nc, output_nc, ngf):
        super(Discriminator, self).__init__()
        #input_nc=3, output_nc=3
        #ngf=64
        #Convolution2D(self, in_channels, out_channels, ksize=None, stride=1, pad=0, nobias=False, initialW=None, initial_bias=None)
        self.disconv1 = L.Convolution2D(input_nc + output_nc, ngf, 4, 2, 1)
        self.disconv2 = L.Convolution2D(ngf, ngf * 2, 4, 2, 1)
        self.disconv3 = L.Convolution2D(ngf * 2, ngf * 4, 4, 2, 1)
        self.disconv4 = L.Convolution2D(ngf * 4, ngf * 8, 4, 1, 1)
        self.disconv5 = L.Convolution2D(ngf * 8, 1, 4, 1, 1)
        self.batch_norm2 = L.BatchNormalization(ngf * 2)
        self.batch_norm4 = L.BatchNormalization(ngf * 4)
        self.batch_norm8 = L.BatchNormalization(ngf * 8)

    def __call__(self, input):
        #input_nc=3, output_nc=3
        #ngf=64
        #Convolution2D(self, in_channels, out_channels, ksize=None, stride=1, pad=0, nobias=False, initialW=None, initial_bias=None)

        # input is (nc x 2) x 256 x 256
        h1 = self.disconv1(input)
        # state size is (ndf) x 128 x 128
        h2 = self.batch_norm2(self.disconv2(F.leaky_relu(h1)))
        # state size is (ndf x 2) x 64 x 64
        h3 = self.batch_norm4(self.disconv3(F.leaky_relu(h2)))
        # state size is (ndf x 4) x 32 x 32
        h4 = self.batch_norm8(self.disconv4(F.leaky_relu(h3)))
        # state size is (ndf x 8) x 31 x 31
        h5 = self.disconv5(F.leaky_relu(h4))
        # state size is (ndf) x 30 x 30, corresponds to 70 x 70 receptive
        output = F.sigmoid(h5)
        
        # print(output)
        print(output.shape)
        return output
```



```py:新
class Discriminator(chainer.Chain):
    def __init__(self, input_nc, output_nc, ngf):
      super(Discriminator, self).__init__()
      with self.init_scope():
        #input_nc=3, output_nc=3
        #ngf=64
        #Convolution2D(self, in_channels, out_channels, ksize=None, stride=1, pad=0, nobias=False, initialW=None, initial_bias=None)
        self.disconv1 = L.Convolution2D(input_nc + output_nc, ngf, 4, 2, 1)
        self.disconv2 = L.Convolution2D(ngf, ngf * 2, 4, 2, 1)
        self.disconv3 = L.Convolution2D(ngf * 2, ngf * 4, 4, 2, 1)
        self.disconv4 = L.Convolution2D(ngf * 4, ngf * 8, 4, 1, 1)
        self.disconv5 = L.Convolution2D(ngf * 8, 1, 4, 1, 1)
        self.batch_norm2 = L.BatchNormalization(ngf * 2)
        self.batch_norm4 = L.BatchNormalization(ngf * 4)
        self.batch_norm8 = L.BatchNormalization(ngf * 8)

    def __call__(self, input_disc):
        #input_nc=3, output_nc=3
        #ngf=64
        #Convolution2D(self, in_channels, out_channels, ksize=None, stride=1, pad=0, nobias=False, initialW=None, initial_bias=None)
        # input_disc is (nc x 2) x 256 x 256
        h1 = self.disconv1(input_disc)
        # state size is (ndf) x 128 x 128
        h2 = self.batch_norm2(self.disconv2(F.leaky_relu(h1)))
        # state size is (ndf x 2) x 64 x 64
        h3 = self.batch_norm4(self.disconv3(F.leaky_relu(h2)))
        # state size is (ndf x 4) x 32 x 32
        h4 = self.batch_norm8(self.disconv4(F.leaky_relu(h3)))
        # state size is (ndf x 8) x 31 x 31
        h5 = self.disconv5(F.leaky_relu(h4))
        # state size is (ndf) x 30 x 30, corresponds to 70 x 70 receptive
        output = F.sigmoid(h5)
        
        # print(output)
        print(output.shape)
        return output
```


#参考
https://qiita.com/ys-0-sy/items/404cc5388e9d77e16734