Pytorch: 'torch.nn' has no attribute 'TripletMarginLoss'

Created on 10 Apr 2017  ·  3Comments  ·  Source: pytorch/pytorch

Calling

triplet_loss = nn.TripletMarginLoss()

results in:

AttributeError: module 'torch.nn' has no attribute 'TripletMarginLoss'

even with

import torch.nn as nn

Related PR that added introduced TripletMarginLoss: #1165

Work-around for now is to use F.triplet_margin_loss directly, where F is import torch.nn.functional as F.

high priority

Most helpful comment

Hi, similar thing happens when I call m = nn.Upsample(scale_factor=2, mode='bilinear')
AttributeError: 'module' object has no attribute 'Upsample'
But I can successfully call nn.UpsamplingBilinear2d.
Besides, is there any plan to implement the Cubic Upsample~

All 3 comments

Another workaround would be to add from torch.nn.modules.loss import TripletMarginLoss.

fixed in master. will be in next release.

Hi, similar thing happens when I call m = nn.Upsample(scale_factor=2, mode='bilinear')
AttributeError: 'module' object has no attribute 'Upsample'
But I can successfully call nn.UpsamplingBilinear2d.
Besides, is there any plan to implement the Cubic Upsample~

Was this page helpful?
0 / 5 - 0 ratings