result: [xc,yc,w,h] range [0,1] to [x1,y1,x2,y2] range [0,w], [0,h]
(result, input_size, img_size, output_height, output_width)
| 75 | return results |
| 76 | |
| 77 | def bbox_postprocess(result, input_size, img_size, output_height, output_width): |
| 78 | """ |
| 79 | result: [xc,yc,w,h] range [0,1] to [x1,y1,x2,y2] range [0,w], [0,h] |
| 80 | """ |
| 81 | if result is None: |
| 82 | return None |
| 83 | |
| 84 | scale = torch.tensor([input_size[1], input_size[0], input_size[1], input_size[0]])[None,:].to(result.device) |
| 85 | result = result.sigmoid() * scale |
| 86 | x1,y1,x2,y2 = result[:,0] - result[:,2]/2, result[:,1] - result[:,3]/2, result[:,0] + result[:,2]/2, result[:,1] + result[:,3]/2 |
| 87 | h,w = img_size |
| 88 | |
| 89 | x1 = x1.clamp(min=0, max=w) |
| 90 | y1 = y1.clamp(min=0, max=h) |
| 91 | x2 = x2.clamp(min=0, max=w) |
| 92 | y2 = y2.clamp(min=0, max=h) |
| 93 | |
| 94 | box = torch.stack([x1,y1,x2,y2]).permute(1,0) |
| 95 | scale = torch.tensor([output_width/w, output_height/h, output_width/w, output_height/h])[None,:].to(result.device) |
| 96 | box = box*scale |
| 97 | return box |
| 98 | |
| 99 | def sem_seg_postprocess(result, img_size, output_height, output_width): |
| 100 | """ |