grad_fnがNoneではないのtensorはleaf variable
https://blog.csdn.net/a1367666195/article/details/105654101
Tensorの確認
print(tensor.is_leaf)
for name, param in model.named_parameters():
if param.requires_grad and name == 'module.model.conv1.weight':
print("module.model.conv1.weight.grad:", param.grad) # Noneが出ると、微分不可
要注意:leaf variableを無効化する操作
view()
代わりに:
x_fused = x_fused.reshape(-1, 5, 3, x_fused.shape[-2], x_fused.shape[-1])
x_fused.retain_grad()