location: "models/yolo_layer.py", line 438,error: obj_mask[b, a, j, i] = 1 IndexError: index 40 is out of bounds for dimension 0 with size 40
BucolicWind opened this issue · comments
could you tell me how can i solve this problem?what happend to this code?THX
for ti in range(best_n.shape[0]):
if best_n_mask[ti] == 1:
i, j = truth_i[ti], truth_j[ti]
a = best_n[ti]
obj_mask[b, a, j, i] = 1
tgt_mask[b, a, j, i, :] = 1
target[b, a, j, i, 0] = truth_x_all[b, ti] - \
truth_x_all[b, ti].to(torch.int16).to(torch.float)
target[b, a, j, i, 1] = truth_y_all[b, ti] - \
truth_y_all[b, ti].to(torch.int16).to(torch.float)
target[b, a, j, i, 2] = torch.log(
truth_w_all[b, ti] / torch.Tensor(self.masked_anchors)[best_n[ti], 0] + 1e-16)
target[b, a, j, i, 3] = torch.log(
truth_h_all[b, ti] / torch.Tensor(self.masked_anchors)[best_n[ti], 1] + 1e-16)
target[b, a, j, i, 4] = 1
target[b, a, j, i, 5 + labels[b, ti,
0].to(torch.int16).numpy()] = 1
tgt_scale[b, a, j, i, :] = torch.sqrt(
2 - truth_w_all[b, ti] * truth_h_all[b, ti] / fsize / fsize)
I try to change this code to train my data, error occurred during the code above.
Hi,
The dimension 0 of obj_mask should be batchsize and 'b' stands for the current batch number in the for loop.
obj_mask = torch.ones(batchsize, self.n_anchors,
fsize, fsize).type(dtype)
for b in range(batchsize):
...
obj_mask[b, a, j, i] = 1
So b changes from 0 to 39 if your batchsize is 40.
Which part of yolo_layer.py have you changed?
@BucolicWind
Please put your reply on this thread.
Hi, I simply copy your code and run,but i will also meet this problem.i changed the bctchsize to 8 >when training in the visdrone dataset,
If you train on visdrone, you should have changed something - dataloader, config,.. and so on.
And
location: "models/yolo_layer.py", line 438
The original yolo_layer.py does not have 438th line. Please let us know if you customized the code.
Thank you.