您好,我在使用YOLOv3进行目标检测的时候遇到了问题,就是在detect前向的部分有一个4维的x[i](batch,_,ny,nx)转5维(bs,anchors,outputs,ny,nx)的reshape操作,但是我们要求在部署的时候只能支持最高4维的reshape,这样应该如何修改代码呢? 是否应该连同detect和后面的nms都处理成4维?源代码如下
def forward(self, x) :
z = [] # inference output
for i in range(self.nl):
x[i] = self.m[i](x[il) # conv
bs,_,ny, nx = x[il.shape # x(bs,255,20,20) to x(bs,3,20,20,85)
x[i] = x[i].view(bs, self.na, self.no, ny, nx).permute(0, 1, 3,4, 2).contiguous()
我之前尝试对x[i][j]进行reshape(3维转4维),但是不知道是否因为不能对tensor内部进行reshape操作,这样会报错
代码:
for j in range(bs) :
x[i][j]=x[i]lj].view(self.na, self.no, ny,nx).permute(0,2,3,1).contiguous()
报错:
runtime error:expand(torch.FloatTensor{[3,40,40,50]},size=[150,40,40]):the number of sizes provided (3) must be greater or equal to the number of dimensions in the tensor (4)