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变成列表,可迭代


目录
相关文章
|
6月前
|
机器学习/深度学习 监控 数据可视化
【已解决】 ‘Conv2d’ object has no attribute ‘register_full_backward_hook’
【已解决】 ‘Conv2d’ object has no attribute ‘register_full_backward_hook’
|
算法框架/工具
Keras报错:TypeError: (‘Keyword argument not understood:‘, ‘offset‘)
Keras报错:TypeError: (‘Keyword argument not understood:‘, ‘offset‘)
180 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)
成功解决TypeError: __init__() got an unexpected keyword argument 'serialized_options'
成功解决TypeError: __init__() got an unexpected keyword argument 'serialized_options'
|
TensorFlow 算法框架/工具
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
272 0
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
Duplicate methods named spliterator with the parameters () and () are inherited from the types Colle
Duplicate methods named spliterator with the parameters () and () are inherited from the types Colle
73 0
|
PyTorch 算法框架/工具
问题解决:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'
问题解决:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'
272 0
成功解决KeyError: “Passing list-likes to .loc or [] with any missing labels is no longer supported. The
成功解决KeyError: “Passing list-likes to .loc or [] with any missing labels is no longer supported. The
Changing scope values asynchronously - updates don't propagate without .apply()
Changing scope values asynchronously - updates don't propagate without .apply()
Changing scope values asynchronously - updates don't propagate without .apply()