Ham*_*ard 5 python neural-network deep-learning activation-function pytorch
如何更改 Pytorch 预训练网络的激活层?这是我的代码:
print("All modules")
for child in net.children():
if isinstance(child,nn.ReLU) or isinstance(child,nn.SELU):
print(child)
print('Before changing activation')
for child in net.children():
if isinstance(child,nn.ReLU) or isinstance(child,nn.SELU):
print(child)
child=nn.SELU()
print(child)
print('after changing activation')
for child in net.children():
if isinstance(child,nn.ReLU) or isinstance(child,nn.SELU):
print(child)
Run Code Online (Sandbox Code Playgroud)
这是我的输出:
All modules
ReLU(inplace=True)
Before changing activation
ReLU(inplace=True)
SELU()
after changing activation
ReLU(inplace=True)
Run Code Online (Sandbox Code Playgroud)
._modules
为我解决了问题。
for name,child in net.named_children():
if isinstance(child,nn.ReLU) or isinstance(child,nn.SELU):
net._modules['relu'] = nn.SELU()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6146 次 |
最近记录: |