Hello.
Three different input: images1, images1_sub(a subset of images1), images2,.
One network: model.
... ...
optimizer.zero_grad()

output1，intermediate_feature_map_1  = model(images1)
# get output and intermediate feature map
output1_sub, intermediate_feature_map_sub1 = model(images1_sub)
# get output and intermediate feature map
output2, intermediate_feature_map2 = model(images2)

# calculate the cross_entropy ce_loss1 for output1
ce_loss1 = cross_entropy(output1, label)
# calculate the cross_entropy ce_loss2 for output2
ce_loss2 = cross_entropy(output2, label)  # the same label
# the distance of intermediate feature map for images_sub1 and images2 
#(the shape of images_sub1 is the same as the shape of images2  )
loss_d =  distance(intermediate_feature_map_sub1, intermediate_feature_map2 )
loss =  ce_loss1 + ce_loss2 + loss_d 
loss.backward()
optimizer.step()

I’d like to sum the loss and backward. Then update parameter for network.
Is there anything wrong with my code?
Appreciated for your help!