终于进入训练过程了
Load Data: 11
====>> Build Net
====>> Load I model
====>> Train
D:\ProgramData\Anaconda3\envs\python36\lib\site-packages\torch\nn\modules\loss.py:446: UserWarning: Using a target size (torch.Size([1, 1, 3, 320, 320])) that is different to the input size (torch.Size([1, 3, 320, 320])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
return F.mse_loss(input, target, reduction=self.reduction)
先解决这个
之前为了让几个数值的维度统一,给b2参数也加了维度,采用debug测试发现,维度就是那个和别人都不一样的维度,所以把这行代码注释了就好了
b2 = b2.transpose(2, 0, 1)
b2 = b2[np.newaxis,:,:,:] # 给数组增加维度
b2 = np_to_torch(b2).to(device)
==>> Thu Mar 3 16:29:20 2022 [Iteration 1 Epoch 50] Loss = 19851.923828
==>> Thu Mar 3 16:29:21 2022 [Iteration 1 Epoch 100] Loss = 10989.599609
==>> Thu Mar 3 16:29:23 2022 [Iteration 1 Epoch 150] Loss = 7369.253418
==>> Thu Mar 3 16:29:25 2022 [Iteration 1 Epoch 200] Loss = 8838.803711
==>> Thu Mar 3 16:29:26 2022 [Iteration 1 Epoch 250] Loss = 10214.323242
==>> Thu Mar 3 16:29:28 2022 [Iteration 1 Epoch 300] Loss = 8534.051758
==>> Thu Mar 3 16:29:29 2022 [Iteration 1 Epoch 350] Loss = 8817.697266
==>> Thu Mar 3 16:29:31 2022 [Iteration 1 Epoch 400] Loss = 8884.304688
==>> Thu Mar 3 16:29:32 2022 [Iteration 1 Epoch 450] Loss = 9845.090820
==>> Thu Mar 3 16:29:34 2022 [Iteration 1 Epoch 500] Loss = 8570.036133
==>> Thu Mar 3 16:29:34 2022 [Iter 1/8] loss = 8570.036133
====>> Thu Mar 3 16:29:34 2022 Pass time: 0:00:17.553348
Traceback (most recent call last):
File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 358, in <module>
train(opt)
File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 284, in train
grd_x, grd_y = getGrd(img_in)
File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 37, in getGrd
grd_x = data_in.clone()
AttributeError: 'numpy.ndarray' object has no attribute 'clone'
又报错
这个问题真的找不出来,用debug报错是这样的,明天继续改
==>> Sun Mar 6 18:24:10 2022 [Iter 1/8] loss = 7767.667969
====>> Sun Mar 6 18:24:10 2022 Pass time: 0:00:17.678687
Traceback (most recent call last):
File "C:\Program Files\pycharm\PyCharm Community Edition 2021.3.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\pycharm\PyCharm Community Edition 2021.3.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 358, in <module>
train(opt)
File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 284, in train
grd_x, grd_y = getGrd(img_in)
File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 37, in getGrd
grd_x = data_in.clone()
AttributeError: 'numpy.ndarray' object has no attribute 'clone'
Process finished with exit code 1
3.07新进展:传进函数的数据是numpy类型的,而clone收tensor类型的函数,
于是把后面调用的数据改成tensor类型
img_in = torch.from_numpy(img_in)
报错:
self.img_in = torch.from_numpy(np.transpose(img_in, (2, 0, 1)) / 255.0).float()
TypeError: expected np.ndarray (got Tensor)
修改:
为:
又回到梯度的错误了,但是换了一个问题
发现图像输入和网络输入维度不一致,用unsqueeze函数和 .squeeze()给图像改维数,新错误,
哭了。。。心情不太好,决定还是回到前面的问题吧
==>> Mon Mar 7 21:18:55 2022 [Iteration 1 Epoch 450] Loss = 12893.431641
Traceback (most recent call last):
File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 359, in <module>
train(opt)
File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 286, in train
grd_x, grd_y = getGrd(img_in)
File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 37, in getGrd
grd_x = grd_x[:, :, 0:-1, :] - data_in[:, :, 1:, :]
IndexError: too many indices for tensor of dimension 3
==>> Mon Mar 7 21:18:56 2022 [Iteration 1 Epoch 500] Loss = 10786.927734
==>> Mon Mar 7 21:18:57 2022 [Iter 1/8] loss = 10786.927734
====>> Mon Mar 7 21:18:57 2022 Pass time: 0:00:18.375648
Process finished with exit code 1
在网上搜不到具体方法,反正就是维度的问题吧,采用debug查看了维度,输入图像的维度和
input_net, target_net 的维度不一样,明天继续
input_net, target_net = Variable(batch[0]), Variable(batch[1], requires_grad=False)
好吧,是中间batch的维度都不对。