Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detection cropping+saving feature addition for detect.py and PyTorch Hub #2827

Merged
merged 16 commits into from
Apr 20, 2021
Prev Previous commit
Next Next commit
Update detect.py
  • Loading branch information
glenn-jocher authored Apr 20, 2021
commit e1f8617116b6396d0ea3fa585a2568b93a539754
13 changes: 7 additions & 6 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ def detect():
with open(txt_path + '.txt', 'a') as f:
f.write(('%g ' * len(line)).rstrip() % line + '\n')

if save_img or opt.save_crop or view_img: # Add bbox to image
label = f'{names[int(cls)]} {conf:.2f}'
plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=3)
if opt.save_crop:
save_one_box(xyxy, im0s, file=save_dir / 'crops' / names[int(cls)] / f'{p.stem}.jpg')
if save_img or opt.save_crops or view_img: # Add bbox to image
c = int(cls) # integer class
label = f'{names[c]} {conf:.2f}'
plot_one_box(xyxy, im0, label=label, color=colors[c], line_thickness=3)
if opt.save_crops:
save_one_box(xyxy, im0s, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)

# Print time (inference + NMS)
print(f'{s}Done. ({t2 - t1:.3f}s)')
Expand Down Expand Up @@ -159,7 +160,7 @@ def detect():
parser.add_argument('--view-img', action='store_true', help='display results')
parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
parser.add_argument('--save-crop', action='store_true', help='save cropped prediction boxes')
parser.add_argument('--save-crops', action='store_false', help='save cropped prediction boxes')
parser.add_argument('--nosave', action='store_true', help='do not save images/videos')
parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
Expand Down