Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import argparse
def get_parser():
parser = argparse.ArgumentParser(description="Extract bounding boxes using Detectron2",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
"--config-file",
default="/home/appuser/detectron2_repo/configs/COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml",
metavar="FILE",
help="path to config file",
)
parser.add_argument("--video-input", help="Path to video file.")
parser.add_argument("--videos-input-dir", help="A directory of input videos. It also extracts ROI pooled features from the Faster R-CNN object detector.")
parser.add_argument("--images-input-dir", type=str, help="A directory of input images with extension *.jpg. The file names should be the frame number (e.g. 00000000001.jpg)")
parser.add_argument("--model-weights", type=str, default="detectron2://COCO-Detection/faster_rcnn_R_101_FPN_3x/137851257/model_final_f6e8b1.pkl", help="Detectron2 object detection model.")
parser.add_argument(
"--output",
help="A file or directory to save output visualizations. "
"If not given, will show output in an OpenCV window.",
)
parser.add_argument("--visualise-bbox", action='store_true', help="Save bounding box visualisation.")
parser.add_argument("--visualise-feature", action='store_true', help="Save ROI pooled feature visualisation (but only the first frame of a video).")
parser.add_argument("--divide-job-count", type=int, default=1, help="If there are too many files to process, you may want to divide the job into many processes. This is the number of processes you want to split but the programme doesn't run multiprocess for you. It merely splits the file lists into the number and uses --divide-job-index to assign files to process. Only effective when --videos-input-dir is set.")
parser.add_argument("--divide-job-index", type=int, default=0, help="If there are too many files to process, you may want to divide the job into many processes. This is the index of process.")
parser.add_argument(
"--confidence-threshold",
type=float,
default=0.5,
help="Minimum score for instance predictions to be shown",
)
parser.add_argument(
"--opts",
help="Modify config options using the command-line 'KEY VALUE' pairs",
default=[],
nargs=argparse.REMAINDER,
)
return parser
parser = get_parser()
args = parser.parse_args()
if bool(args.video_input) + bool(args.images_input_dir) + bool(args.videos_input_dir) != 1:
parser.error("--video-input, --video-input-dir and --images-input-dir can't come together and only one must be specified.")
# Save args to json
import json
with open('args.json', 'w') as f:
json.dump(args.__dict__, f, ensure_ascii=False, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment