Closed MichaelGou1105 closed 5 years ago
Can you please specify your pytorch version?
Hi
Facing a similar issue, Not able to run the demo.py file.
@ChandanKumarAAI Were you able to get predictions using the demo.py file?
My torch version is 0.4, and I was facing the same issue, so I updated the following code, and now it is working.
def infer(net , img , transform , thresh , cuda , shrink): if shrink != 1: img = cv2.resize(img, None, None, fx=shrink, fy=shrink, interpolation=cv2.INTER_LINEAR) x = torch.from_numpy(transform(img)[0]).permute(2, 0, 1) with torch.no_grad(): x = Variable(x.unsqueeze(0)) if cuda: x = x.cuda()
y = net(x) # forward pass
detections = y.data
# scale each detection back up to the image
scale = torch.Tensor([ img.shape[1]/shrink, img.shape[0]/shrink,
img.shape[1]/shrink, img.shape[0]/shrink] )
det = []
for i in range(detections.size(1)):
j = 0
while detections[0, i, j, 0] >= thresh:
score = detections[0, i, j, 0].cpu().numpy()
#label_name = labelmap[i-1]
pt = (detections[0, i, j, 1:]*scale).cpu().numpy()
#print ("#"*20,type(pt), pt)
coords = (pt[0], pt[1], pt[2], pt[3])
det.append([pt[0], pt[1], pt[2], pt[3], score])
j += 1
if (len(det)) == 0:
det = [ [0.1,0.1,0.2,0.2,0.01] ]
det = np.array(det)
keep_index = np.where(det[:, 4] >= 0)[0]
det = det[keep_index, :]
return det
@DecentMakeover yes I was able to get prediction from demo.py.
Okay let me try this.
@AnberLu @ChandanKumarAAI @DecentMakeover It's mainly caused by torch version. Someone faces this similar problem. The torch version we used is 0.3.1.
when i run
python demo.py
, the issue