[Python] Pytorch, TypeError: object() takes no parameters

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    This is probably a beginner question, but nevertheless: When running an image classifier build with pytorch, I get this error:

    Traceback (most recent call last):
    File "/pytorch/kanji_torch.py", line 47, in <module>
    network = Network()
    File "/pytorch/kanji_torch.py", line 113, in __init__
    self.conv1 = nn.Conv2d(1, 32, 5)
    File "/python3.5/site-packages/torch/nn/modules/conv.py", line 233, in __init__
    False, _pair(0), groups, bias)
    File "/python3.5/site-packages/torch/nn/modules/conv.py", line 32, in __init__
    out_channels, in_channels // groups, *kernel_size))
    TypeError: object() takes no parameters


    I define the network class like this:

    class Network(torch.nn.Module):
    def __init__(self):
    super(Network, self).__init__()
    self.conv1 = nn.Conv2d(1, 32, 5)
    self.pool = nn.MaxPool2d(2, 2)
    self.conv2 = nn.Conv2d(32, 64, 5)
    self.pool2 = nn.MaxPool2d(2, 2)
    self.conv3 = nn.Conv2d(64, 64, 5)
    self.pool2 = nn.MaxPool2d(2, 2)
    self.fc1 = nn.Linear(64 * 5 * 5, 512)
    self.fc2 = nn.Linear(512, 640)
    self.fc3 = nn.Linear(640, 3756)


    Pretty sure that I imported all the relevant pytorch library modules correctly. (import torch.nn as nn and
    import torch)

    Any ideas of what I'm doing wrong?

    Thank you!

    Continue reading...

Compartilhe esta Página