如何解决在pytorch / numpy中使用meshgrid
下面的代码是摘自https://blog.paperspace.com/how-to-implement-a-yolo-v3-object-detector-from-scratch-in-pytorch-part-3/的摘录,对于它要实现的目标,我感到困惑。
grid = np.arange(grid_size)
a,b = np.meshgrid(grid,grid)
x_offset = torch.FloatTensor(a).view(-1,1)
y_offset = torch.FloatTensor(b).view(-1,1)
if CUDA:
x_offset = x_offset.cuda()
y_offset = y_offset.cuda()
x_y_offset = torch.cat((x_offset,y_offset),1).repeat(1,num_anchors).view(-1,2).unsqueeze(0)
我尝试了当grid_size = 3时的情况,并输出:
tensor([[0.,1.],[2.,0.],[1.,2.],[0.,2.]])
我不太清楚这里的模式。根据给定链接中的描述,我认为我真的应该期望像这样:
tensor([[0,0],[0,1],2],...]])
解决方法
如果您希望显示第二个输出,只需更改
>>> len(list(boto3.resource('s3').Bucket('example-bucket').objects.all()))
botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied
>>> len(list(boto3.resource('s3').Bucket('example-bucketzz').objects.all()))
botocore.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the ListObjects operation: The specified bucket does not exist
到
x_y_offset = (
torch.cat((x_offset,y_offset),1).repeat(1,num_anchors).view(-1,2).unsqueeze(0)
)
它只与meshgrid输出的顺序有关。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。