the model training code as follows:
optimizer.zero_grad()
feat = model_w(x2_w)
loss, p_inds, n_inds, dist_ap, dist_an, dist_mat = global_loss(tri_loss, feat, y_w, normalize_feature= False)
loss.backward()
optimizer.step()
if i add other forward, code as follows:
optimizer.zero_grad()
feat1 = model_w(G_result.detach())
feat = model_w(x2_w)
loss, p_inds, n_inds, dist_ap, dist_an, dist_mat = global_loss(tri_loss, feat, y_w, normalize_feature= False)
loss.backward()
optimizer.step()
the training result is different.
Can anybody confirm that what I’m doing is correct? If it isn’t could someone indicate what the correct way would be?
Thanks!