报错 RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation
报错大致意思是不能对在计算图中带梯度的变量进行操作。
·
报错大致意思是不能对在计算图中带梯度的变量进行操作
源代码
def anim(i):
# update SMBLD
cur_beta_idx, cur_step = i // num_steps, i % num_steps
val = shape_range[cur_step]
mesh.multi_betas[0, cur_beta_idx] = val # Update betas
fig.suptitle(f"{name.title()}\nS{cur_beta_idx} : {val:+.2f}", fontsize=50) # update text
return dict(mesh=mesh.get_meshes(), equalize=False)
修改后代码
添加 with torch.no_grad():
即可
def anim(i):
# update SMBLD
cur_beta_idx, cur_step = i // num_steps, i % num_steps
val = shape_range[cur_step]
#print("\ncur_beta_idx:",cur_beta_idx,mesh.multi_betas[0, cur_beta_idx])
with torch.no_grad():###添加
mesh.multi_betas[0, cur_beta_idx] = val # Update betas
fig.suptitle(f"{name.title()}\nS{cur_beta_idx} : {val:+.2f}", fontsize=50) # update text
return dict(mesh=mesh.get_meshes(), equalize=False)
参考文章
yolov5报错:RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place
更多推荐
已为社区贡献3条内容
所有评论(0)