Pytorch: 'torch.nn' 没有属性 'TripletMarginLoss'

创建于 2017-04-10  ·  3评论  ·  资料来源: pytorch/pytorch

打电话

triplet_loss = nn.TripletMarginLoss()

结果是:

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

即使

import torch.nn as nn

添加的相关 PR 引入了 TripletMarginLoss:#1165

现在的解决方法是直接使用F.triplet_margin_loss ,其中Fimport torch.nn.functional as F

high priority

最有用的评论

嗨,当我打电话给m = nn.Upsample(scale_factor=2, mode='bilinear')时会发生类似的事情
AttributeError: 'module' 对象没有属性 'Upsample'
但我可以成功调用nn.UpsamplingBilinear2d
另外,有没有计划实施Cubic Upsample ~

所有3条评论

另一种解决方法是添加from torch.nn.modules.loss import TripletMarginLoss

固定在主人。 将在下一个版本中。

嗨,当我打电话给m = nn.Upsample(scale_factor=2, mode='bilinear')时会发生类似的事情
AttributeError: 'module' 对象没有属性 'Upsample'
但我可以成功调用nn.UpsamplingBilinear2d
另外,有没有计划实施Cubic Upsample ~

此页面是否有帮助?
0 / 5 - 0 等级