我的深度学习模型用于分割CT图像。但是损失值总是很高。为了调试程序,我使用相同的输入图像来观察输出,并且10次迭代的损耗值都相同,这意味着网络的参数完全没有变化。你能告诉我为什么我的模型不能训练吗?是我没有使用DataFrame方法的原因吗? 代码如下:
for ite in range(iteration):
print("=====iteration", ite, "=======")
weights = few_shot_model.conditioner(condition_input)
output = few_shot_model.segmentor(query_input, weights)
# out = F.softmax(output, dim=1)
print("out.shape, y2.shape:", output.shape, y2.shape)
print("y2.unique:", torch.unique(y2))
loss = loss_func(output, y2, binary=True)
optim_s.zero_grad() # clear gradients for this training step
optim_c.zero_grad() #
loss.backward() # backpropagation, compute gradients
if phase == 'train':
if epoch <= warm_up_epoch:
optim_s.step() # apply gradients
optim_c.step()
scheduler_c.step()
scheduler_s.step()
elif epoch > warm_up_epoch and change_model:
optim_n.step()
print("loss.item", loss.item())