Parameter updates

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
We can now use a method to plot the loss surface of the network by projecting the parameter updates into two dimensions. You can find more information on that here. But you can just use the provided code. The contour plot will show how the loss will change if you would follow the two main directions of the past parameter updates. Think about the challenges and the optimization process of this landscape. What could impede the convergence of the net? # project states onto the main directions of the gradient updates using n samples over all steps starting from sample x # the directions are calculated using the last sample as a reference directions, state_ids, loss_coordinates = get_state_directions(states, n_states=10, start_from=0, reference_id=-1) # compute the losses over the main directions of the gradient updates x, y, Z, _ = get_loss_grid(net, data_loader, loss_fn, directions=directions, resolution=(20, 20), scale=loss_coordinates.abs().max().item()) # plot the landscape as a contour plot fig = plot_contour(np.copy(x), np.copy(y), np.copy(Z), scale=True) fig.add_traces(go.Scatter(x=np.copy(loss_coordinates[0].cpu().numpy()), y=np.copy(loss_coordinates[1].cpu().numpy()))) print('loss samples:', np.array(losses)[state_ids]) conf_pltly() init_notebook_mode(connected=False) iplot(fig) --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-62-26d05ea2d790> in <cell line: 3>() 1 # project states onto the main directions of the gradient updates using n samples over all steps starting from sample x 2 # the directions are calculated using the last sample as a reference ----> 3 directions, state_ids, loss_coordinates = get_state_directions(states, n_states=10, start_from=0, reference_id=-1) 4 5 # compute the losses over the main directions of the gradient updates <ipython-input-60-6cc4aad7dcda> in get_state_directions(states, n_states, start_from, reference_id) 15 params.append(param.view(-1)) 16 ---> 17 params = torch.stack(params, dim=0) 18 reference = params[-1] 19 RuntimeError: stack expects each tensor to be equal size, but got [200704] at entry 0 and [256] at entry 1这个错误怎么改
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值