在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输出的顺序有关。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...