fork download
  1. embedding_norm = F.normalize(x)*self.s
  2. weight_norm = F.normalize(self.weight)
  3. zy = F.linear(embedding_norm, weight_norm)
  4. cosine_t = zy/self.s
  5. sine_t = torch.sqrt(1.0 - cosine_t*cosine_t)
  6. cos_phi = (cosine_t * self.cos_m - sine_t * self.sin_m)*self.s
  7.  
  8. if self.easy_margin:
  9. cos_phi = torch.where(cosine_t > 0, cos_phi, zy)
  10. else:
  11. cos_phi = torch.where(cosine_t > self.threshold, cos_phi, zy - self.s * self.mm)
  12.  
  13. # --------------------------- convert label to one-hot ---------------------------
  14. one_hot = torch.zeros(cosine_t.size(), device='cuda')
  15. # one_hot = one_hot.cuda() if cosine.is_cuda else one_hot
  16. one_hot.scatter_(1, label.view(-1, 1).long(), 1)
  17. output = (one_hot * cos_phi) + ((1.0 - one_hot) * zy)
  18. #output = one_hot*(cos_phi-zy) + zy
  19. return output
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "/usr/lib/python3.7/py_compile.py", line 143, in compile
    _optimize=optimize)
  File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "./prog.py", line 19
    return output
    ^
SyntaxError: 'return' outside function

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.7/py_compile.py", line 147, in compile
    raise py_exc
py_compile.PyCompileError:   File "./prog.py", line 19
    return output
                ^
SyntaxError: 'return' outside function

stdout
Standard output is empty