【问题标题】:TypeError: __init__() takes exactly 2 arguments (3 given) when I try to permute [closed]TypeError:当我尝试置换时,__init__() 恰好需要 2 个参数(给定 3 个)[关闭]
【发布时间】:2018-02-22 14:02:03
【问题描述】:

在下面的例子中我应该如何正确地排列行和列?

input_shape = (input_dim, input_features)
inputs = Input(input_shape)
net = Reshape(input_shape + (1, ), input_shape=input_shape)(inputs)

net 被传递给 Conv2D。

当我使用 inpute_shape = Permute(2,1) 时出现错误__init__() takes exactly 2 arguments (3 given)

谢谢!

这是我尝试了一些选项后最近的 Traceback:

Traceback (most recent call last):
  File "app.py", line 372, in <module>
    train(model_filename=args.model, epochs=args.epochs, dim=args.dim)
  File "app.py", line 61, in train
    output_classes=reader.CLASSES)
  File "/home/ubuntu/calypso_v2/model.py", line 53, in build_model
    net = Permute(3,2)(net)
TypeError: __init__() takes exactly 2 arguments (3 given)

【问题讨论】:

  • Permute 的文档说参数应该是什么?
  • 这是我传递给 CNN 的二维矩阵。在此之前,我要添加第三个维度。
  • 您应该发布完整的 Traceback。你明白异常是什么意思吗?如果您还没有,请阅读How to Askminimal reproducible example
  • 我已将 Traceback 添加到帖子中。

标签: python tensorflow keras-layer


【解决方案1】:

Permute() 将元组作为其唯一的位置参数。您指定了两个整数 21,而不是元组 (2,1)

试试这个:

inpute_shape = Permute((2,1))

【讨论】:

  • 看起来它是正确的答案,但抛出'Permute' object is not iterable
  • 它可能不会从 this 行产生该错误。如果我已经回答了您的问题,请接受我的回答,然后打开一个新问题。但在您这样做之前,请阅读并理解minimal reproducible example。然后,在您的新问题中,请提供一个简短的完整程序来演示错误。
  • 问题已解决。谢谢!
【解决方案2】:

答案是

net = Permute((2,1,3))(net)

【讨论】:

    猜你喜欢
    • 2012-03-15
    • 1970-01-01
    • 2014-08-26
    • 1970-01-01
    • 2013-08-15
    • 2018-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多