params argument given to the optimizer should be an iterable

简介: params argument given to the optimizer should be an iterable

net=nn.Linear(100,1)
optimizer_w=torch.optim.SGD(net.weight,lr=0.03,weight_decay=wd)
>出现问题的原因是SGD函数所需的param参数应该是迭代器或者是张量对应的字典
>但是此时net.weight就是个普通张量
>解决办法:
>optimizer_w=torch.optim.SGD([net.weight],lr=0.03,weight_decay=wd)
>将net.weight变成列表,可迭代


目录
相关文章
|
TensorFlow 算法框架/工具 Python
成功解决AttributeError: module 'numpy' has no attribute 'equal'
成功解决AttributeError: module 'numpy' has no attribute 'equal'
成功解决AttributeError: module 'numpy' has no attribute 'equal'
|
算法框架/工具
Keras报错:TypeError: (‘Keyword argument not understood:‘, ‘offset‘)
Keras报错:TypeError: (‘Keyword argument not understood:‘, ‘offset‘)
186 0
Multiple substitutions specified in non-positional format; did you mean to add BUG(7)
Multiple substitutions specified in non-positional format; did you mean to add BUG(7)
报错 ValueError: too many values to unpack (expected 2)
报错 ValueError: too many values to unpack (expected 2)
207 0
ValueError: not enough values to unpack (expected 3, got 2)
这个错误通常是因为在解包(unpacking)元组(tuple)时,元组中的元素数量与期望不符,导致无法将所有元素正确解包。 例如,在以下代码中,元组中只有两个元素,但我们尝试将其解包为三个变量:
620 0
|
TensorFlow 算法框架/工具
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
277 0
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
|
PyTorch 算法框架/工具
问题解决:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'
问题解决:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'
274 0
|
分布式计算 Spark
Spark - ReturnStatementInClosureException: Return statements aren‘t allowed in Spark closures
Spark 使用 RDD 调用 Filter 函数时,dirver 端卡住,报错 ReturnStatementInClosureException: Return statements aren't allowed in Spark closures,即闭包内无法使用 return 函数。
339 0
Spark - ReturnStatementInClosureException: Return statements aren‘t allowed in Spark closures