OSV-q grd_x=grd_x[:, :, 0:-1, :]-data_in[:, :, 1:, :]IndexError: too many indices for tensor of d

 input_net, target_net = Variable(batch[0]), Variable(batch[1], requires_grad=False) 
torch.Size([1, 3, 356, 356]) torch.Size([1, 3, 356, 356])
torch.Size([1, 3, 356, 356]) torch.Size([1, 3, 356, 356])
Traceback (most recent call last):
  File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 359, in 
    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
==>> Wed Mar  9 09:41:36 2022 [Iteration 1 Epoch 500]    Loss = 12718.471680
==>> Wed Mar  9 09:41:36 2022 [Iter 1/8]   loss = 12718.471680
====>> Wed Mar  9 09:41:36 2022   Pass time: 0:00:19.132388

Process finished with exit code 1

改成True

input_net, target_net = Variable(batch[0]), Variable(batch[1], requires_grad=True) 
torch.Size([1, 3, 356, 356]) torch.Size([1, 3, 356, 356])
==>> Wed Mar  9 09:27:59 2022 [Iteration 1 Epoch 500]    Loss = 12005.107422
==>> Wed Mar  9 09:27:59 2022 [Iter 1/8]   loss = 12005.107422
====>> Wed Mar  9 09:27:59 2022   Pass time: 0:00:20.932553
Traceback (most recent call last):
  File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 359, in 
    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

好像有不一样,但是又不知道哪不一样

决定从batch 函数往上一个一个推

尝试了好多方法突然想到了一个问题,既然都是梯度函数维度报错,而输入图像和网络输出维度又不一样,就定义了一个新的维度的梯度函数

然后这个问题不报错了代码前进了一行,苦涩......

==>> Wed Mar  9 11:11:56 2022 [Iter 1/8]   loss = 8833.374023
====>> Wed Mar  9 11:11:56 2022   Pass time: 0:00:17.003332
Traceback (most recent call last):
  File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 361, in 
    train(opt)
  File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 289, in train
    lap = -(cmul(fft2(grd_x), cconj(fft2(grd_x), inplace=False)) + cmul(fft2(grd_y), cconj(fft2(grd_y), inplace=False)))
  File "C:/Users/shang/Desktop/STDN_LI/TVGnet/OSV_q.py", line 138, in fft2
    return torch.fft.fft2(t, 2)
AttributeError: 'builtin_function_or_method' object has no attribute 'fft2'

Process finished with exit code 1

你可能感兴趣的:(深度学习,pytorch,人工智能)