Unsupported operand types(s) for %: 'tuple' and 'int'

username: Ahmad_Nur_Riza
cooked: <p>Hello everybody, I have a problem when I want to train my data using cycle GAN. Following is the list of my code:<br>
input_shape = (opt.channels, opt.img_height, opt.img_width)</p>
<p>print(type(input_shape))</p>
<p>G_AB = Generator(input_shape)<br>
G_BA = Generator(input_shape)<br>
D_A = Discriminator(input_shape)<br>
D_B = Discriminator(input_shape)</p>
<p>And following is my error when I run my code</p>
<p>Traceback (most recent call last):<br>
File “/home/riza/Documents/Cycle_GAN/Cycle_GAN.py”, line 61, in <br>
G_AB = Generator(input_shape)<br>
File “/home/riza/Documents/Cycle_GAN/models.py”, line 44, in <strong>init</strong><br>
nn.Conv2d(input, output, 7),<br>
File “/usr/local/lib/python3.5/dist-packages/torch/nn/modules/conv.py”, line 332, in <strong>init</strong><br>
False, _pair(0), groups, bias, padding_mode)<br>
File “/usr/local/lib/python3.5/dist-packages/torch/nn/modules/conv.py”, line 22, in <strong>init</strong><br>
if in_channels % groups != 0:<br>
TypeError: unsupported operand type(s) for %: ‘tuple’ and ‘int’</p>
<p>Please help to solve my problem. Thank you</p>

username: albanD
cooked: <p>Hi,</p>
<p>I think the problem is that instead of the number of input channels, you give to the convolution constructor a tuple containing the shape of the input. It should be a simple number.</p>

username: Ahmad_Riza
cooked: <p>I also have try to use a simple number, but it is still error</p>

username: albanD
cooked: <p>Could you give a small code sample I can run that reproduces the error please?</p>

username: Ahmad_Riza
cooked: <p>Oke, this is my listing program<br>
This is my small code of Generator Network<br>
class Generator(nn.Module):<br>
def <strong>init</strong>(self, input, residual_block, output=64):<br>
super(Generator, self).<strong>init</strong>()</p>
<pre><code>    model = [
        nn.ReflectionPad2d(1),
        nn.Conv2d(input, output, 7),
        nn.InstanceNorm2d(output),
        nn.ReLU(True),
    ]
</code></pre>
<p>This is my small code of Discriminator Network<br>
class Discriminator(nn.Module):<br>
def <strong>init</strong>(self, input):<br>
super(Discriminator, self).<strong>init</strong>()</p>
<pre><code>    channels, heigh, width = input

    #---calculate output shape of image discriminator (PatchGAN)---
    self.output = (1, heigh//2**4, width//2**4)

    def discriminator_block(in_shape, out_shape, normalize=True):
        """Returnt downsampling layers of each discriminator block"""
        layers = [nn.Conv2d(in_shape, out_shape, 4, stride=2, padding=1)]
        if normalize:
            layers.append(nn.InstanceNorm2d(out_shape))
        layers.append(nn.LeakyReLU(0.2, inplace=True))
        return layers

    self.model = nn.Sequential(
        *discriminator_block(input, 64, normalize=False),
        *discriminator_block(64, 128),
        *discriminator_block(128, 256),
        *discriminator_block(256, 512),
        nn.ZeroPad2d((1, 0, 1, 0)),
        nn.Conv2d(512, 1, 4, padding=1)
    )class Discriminator(nn.Module):
def __init__(self, input):
    super(Discriminator, self).__init__()

    channels, heigh, width = input

    #---calculate output shape of image discriminator (PatchGAN)---
    self.output = (1, heigh//2**4, width//2**4)

    def discriminator_block(in_shape, out_shape, normalize=True):
        """Returnt downsampling layers of each discriminator block"""
        layers = [nn.Conv2d(in_shape, out_shape, 4, stride=2, padding=1)]
        if normalize:
            layers.append(nn.InstanceNorm2d(out_shape))
        layers.append(nn.LeakyReLU(0.2, inplace=True))
        return layers

    self.model = nn.Sequential(
        *discriminator_block(input, 64, normalize=False),
        *discriminator_block(64, 128),
        *discriminator_block(128, 256),
        *discriminator_block(256, 512),
        nn.ZeroPad2d((1, 0, 1, 0)),
        nn.Conv2d(512, 1, 4, padding=1)
    )
</code></pre>
<p>and This is my main program to call the generator and discriminator<br>
G_AB = Generator(3, opt.n_residual_blocks)<br>
G_BA = Generator(3, opt.n_residual_blocks)<br>
D_A = Discriminator(input_shape)<br>
D_B = Discriminator(input_shape)</p>

username: albanD
cooked: <p>Hi,</p>
<p>You can use triple backticks like ``` before and efter your code to format it properly.</p>
<p>This code looks good and long as input shape is a tuple or list of 3 numbers.</p>

username: Ahmad_Nur_Riza
cooked: <p>which part I have to use backticks?</p>

username: albanD
cooked: <p>If you write the following:</p>
<pre><code class="lang-auto">```python
# You code here
```
</code></pre>
<p>You code will be properly indented.</p>

username: Ahmad_Nur_Riza
cooked: <p>Oh I see, oke thank you</p>