Python Forum
Get error message in a GAN neural network tutorial
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get error message in a GAN neural network tutorial
#1
I am taking a tutorial course in Generative Adversarial Networks with Python. I have been following along with the teacher. I have been executing the code in chunks to make sure that everything is working. I have everything working so far in this block of code with the exception of the very last line. I get the following error message:

TypeError: __init__() takes 1 positional argument but 2 were given

I posted a question for the teacher, but he can take a long time to get around to answering questions. Here is the rest of my code. It is the very last line that causes the error.

import torch
import numpy as np
from matplotlib import pyplot as plt

device = torch.device('cpu')

noise_dim = 100

class Generator(torch.nn.Module):
def __init__(self):
super(Generator, self).__init__()
self.fcn = torch.nn.Sequential(
torch.nn.Linear(
in_features=noise_dim,
out_features=1200,
bias=True
),
torch.nn.ReLU(),
torch.nn.Dropout(),
torch.nn.Linear(
in_features=1200,
out_features=1200,
bias=True
),
torch.nn.ReLU(),
torch.nn.Dropout(),
torch.nn.Linear(
in_features=1200,
out_features=1200,
bias=True
),
torch.nn.ReLU(),
torch.nn.Dropout(),
torch.nn.Linear(
in_features=1200,
out_features=1200,
bias=True
),
torch.nn.Sigmoid()
)

def forward(self, batch):
ret=batch.view(batch.size(0), -1)
ret=self.fcn(ret)
return ret

class Maxout(torch.nn.Module):
def __(self, num_pieces):
super(Maxout, self).__init__()
self.num_pieces
def forward(self, x):
assert x.shape[1] % self.num_pieces == 0
ret = x.view(
*x.shape[:1],
x.shape[1] // self.num_pieces,
self.num_pieces,
*x.shape[2:]
)
ret, _ = ret.max(dim=2)
return ret

class Discriminator(torch.nn.Module):
def __init__(self):
super(Discriminator, self).__init__()
self.fcn = torch.nn.Sequential(
torch.nn.Linear(
in_features=784,
out_features=625,
bias=True
),
Maxout(5),
torch.nn.Linear(
in_features=125,
out_features=625,
bias=True
),
Maxout(5),
torch.nn.Linear(
in_features=125,
out_features=1,
bias=True
),
torch.nn.Sigmoid()
)

def forward(self, batch):
ret = batch.view(batch.size(0), -1)
ret = self.fcn(ret)
return ret

import torchvision

class FlattenTransform:
def __call__(self, inputs):
return inputs.view(inputs.shape[0], -1)

data_train = torchvision.datasets.MNIST(
'./data/mnist',
train=True,
download=True,
transform=torchvision.transforms.Compose([
torchvision.transforms.ToTensor(),
FlattenTransform()
])
)

BATCH_SIZE = 32

train_loader = torch.utils.data.DataLoader(
data_train,
batch_size=BATCH_SIZE,
shuffle=True,
num_workers=4
)

generator = Generator().to(device)
discriminator = Discriminator().to(device)

discriminator_optimizer = torch.optim.SGD(
discriminator.parameters(),
lr=0.0002,
momentum=0.5
)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Neural network and data analysis from clients survey result pthon3 2 1,898 Mar-17-2022, 02:21 AM
Last Post: jefsummers
  Multilayer Perceptron Neural Network erdemath 3 2,332 Aug-09-2021, 11:07 PM
Last Post: jefsummers
  Neural Network importance weights / coefficients jkaustin 1 2,060 Nov-10-2020, 07:44 PM
Last Post: jefsummers
  Explain Me Neural Network Ai's Harshil 2 2,010 Oct-22-2020, 04:50 AM
Last Post: Harshil
  construction of Neural Network for solving Differential equations arshad 0 1,617 Jun-04-2020, 09:20 AM
Last Post: arshad
  Neural Network mensagem error Dalpi 2 2,862 May-20-2020, 04:03 PM
Last Post: Dalpi
  coding neural network programmer19890620 4 3,433 Feb-27-2020, 04:26 AM
Last Post: programmer19890620
  Why does this simple neural network not learn? PythonIsGreat 1 2,104 Aug-30-2019, 05:49 PM
Last Post: ThomasL
  Series object error message abhaydd 1 4,885 Aug-11-2019, 01:29 AM
Last Post: boring_accountant
  Error Message - Akainu 2 3,279 May-24-2019, 09:09 PM
Last Post: Akainu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020