Skip to content

TypeError: forward() takes 2 positional arguments but 3 were given,flownetc_flow2 = self.flownetc(x)[0].why!!!! #286

Description

@zzk1212

截图 2024-03-15 17-50-21
截图 2024-03-15 17-53-06
I spent a lot of time and still couldn't solve this problem. Has anyone encountered this problem? Can you provide a solution? Thank you so much!

### Tasks

import argparse

parser = argparse.ArgumentParser(description='Calculate volume of a cylinder')
parser.add_argument("--rgb_max", default=1)
parser.add_argument("--fp16", default=True)
args = parser.parse_args() # 获取所有参数

flownet2 = FlowNet2(args=args)

获取 conv1 的第一个子模块

first_module = flownet2.flownetc.conv1[0] # 假设 conv1 是一个包含一个子模块的 Sequential 对象

获取第一个子模块的输入通道数

expected_channels = first_module.in_channels
print("模型的期望输入通道数:", expected_channels)

创建符合期望通道数的随机输入张量

batch_size = 1
channels = 3
height = 64
width = 64
inputs = torch.randn(batch_size, channels, height, width) # 随机生成一个输入张量

将输入张量传递给模型获取输出

output = flownet2(inputs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions