我知道'X'右侧是应用 dropout 之前的输入。现在,当您说 时Dropout(0.5)(X),这意味着您将输入中 50% 的神经元的激活随机设为零。
此行Dropout(0.5)表示正在创建 Dropout 类的新对象并在其构造函数中传递 0.5。但是X在它的末尾附加?这在 Python 语法中是什么意思?
这段代码有多种工作方式,我现在想到了两种:
使用类的内置__call__函数
>>> class MyClass:
... def __init__(self, name):
... self.name = name
... def __call__(self, word):
... print(self.name, 'says', word)
...
>>> MyClass('Tom')('hello')
Tom says hello
Run Code Online (Sandbox Code Playgroud)
一个函数返回一个函数
>>> def add(a):
... def f2(b):
... print(a+b)
... return f2
...
>>> add(1)(2)
3
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助
| 归档时间: |
|
| 查看次数: |
671 次 |
| 最近记录: |