AdamOptimizer() takes no arguments
时间: 2023-09-24 09:03:01 浏览: 110
这个错误提示通常表示在使用 TensorFlow 中的 AdamOptimizer 时,没有正确地为其提供所需的参数。AdamOptimizer() 函数需要至少一个参数——学习速率(learning rate),例如:AdamOptimizer(learning_rate=0.001)。如果你没有提供该参数,就会出现这个错误。
相关问题
Solution() takes no arguments
The error "Solution() takes no arguments" typically occurs when you try to pass an argument to a class that does not accept any arguments in its constructor.
Here's an example code that could generate this error:
```
class Solution:
def __init__(self):
self.score = 0
def update_score(self, new_score):
self.score = new_score
solution = Solution(10) # this will raise "Solution() takes no arguments" error
```
In the above code, the `Solution` class does not accept any arguments in its constructor, yet we are trying to pass an argument of `10` when we create an instance of the class. To fix this error, we need to remove the argument:
```
class Solution:
def __init__(self):
self.score = 0
def update_score(self, new_score):
self.score = new_score
solution = Solution() # no error
```
Now, we can create an instance of the `Solution` class without any arguments.
Bar() takes no arguments
The error message "Bar() takes no arguments" means that you are trying to call a function named "Bar" with one or more arguments, but the function definition does not accept any arguments.
For example:
```
def Bar():
print("Hello, World!")
Bar("John") # This will raise the error "Bar() takes no arguments"
```
To fix this error, you need to either remove the arguments from the function call, or modify the function definition to accept the arguments.
For example:
```
def Bar(name):
print("Hello, " + name + "!")
Bar("John") # This will print "Hello, John!"
```
阅读全文