Skip to content

train_ada.py has deprecated implementation of torch.autograd.Function #3

@dkafkes

Description

@dkafkes

Error is thrown in line 282 when calculating transfer_loss during training. To fix, update Adversarial Layer class in network.py with static decorator and context:

class AdversarialLayer(torch.autograd.Function):

  @staticmethod  
  def forward(ctx, input, iter_num=0, alpha=10, low=0.0, high=1.0, max_iter=10000.0):
      iter_num += 1
      ctx.save_for_backward(input) 
      ctx.intermediate_results = (iter_num, alpha, low, high, max_iter)
      output = input * 1.0
      return output

   @staticmethod 
   def backward(ctx, gradOutput):
      input = ctx.saved_tensors
      iter_num, alpha, low, high, max_iter = ctx.intermediate_results
      coeff = np.float(2.0 * (high - low) / (1.0 + np.exp(-alpha*iter_num / max_iter)) - (high - low) + low)
      return -coeff * gradOutput

Then, update first line of PADA function in loss.py as:

ad_out, _ = ad_net(grl_layer.apply(features))

Unrelated to this issue, but also update line 288 in train_ada.py:

classifier_loss = class_criterion(source_logits, labels_source.long())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions