You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GETTING_STARTED.md 3.3 kB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ## Getting Started with Detectron2
  2. This document provides a brief intro of the usage of builtin command-line tools in detectron2.
  3. For a tutorial that involves actual coding with the API,
  4. see our [Colab Notebook](https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5)
  5. which covers how to run inference with an
  6. existing model, and how to train a builtin model on a custom dataset.
  7. For more advanced tutorials, refer to our [documentation](https://detectron2.readthedocs.io/tutorials/extend.html).
  8. ### Inference with Pre-trained Models
  9. 1. Pick a model and its config file from
  10. [model zoo](https://github.com/facebookresearch/detectron2/blob/master/MODEL_ZOO.md),
  11. for example, `mask_rcnn_R_50_FPN_3x.yaml`.
  12. 2. Run the demo with
  13. ```
  14. python demo/demo.py --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \
  15. --input input1.jpg input2.jpg \
  16. [--other-options]
  17. --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl
  18. ```
  19. The configs are made for training, therefore we need to specify `MODEL.WEIGHTS` to a model from model zoo for evaluation.
  20. This command will run the inference and show visualizations in an OpenCV window.
  21. For details of the command line arguments, see `demo.py -h`. Some common ones are:
  22. * To run __on your webcam__, replace `--input files` with `--webcam`.
  23. * To run __on a video__, replace `--input files` with `--video-input video.mp4`.
  24. * To run __on cpu__, add `MODEL.DEVICE cpu` after `--opts`.
  25. * To save outputs to a directory (for images) or a file (for webcam or video), use `--output`.
  26. ### Use Detectron2 in Command Line
  27. We provide a script in "tools/train_net.py", that is made to train
  28. all the configs provided in detectron2.
  29. You may want to use it as a reference to write your own training script for a new research.
  30. To train a model with "train_net.py", first
  31. setup the corresponding datasets following
  32. [datasets/README.md](https://github.com/facebookresearch/detectron2/blob/master/datasets/README.md),
  33. then run:
  34. ```
  35. python tools/train_net.py --num-gpus 8 \
  36. --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml
  37. ```
  38. The configs are made for 8-GPU training. To train on 1 GPU, change the batch size with:
  39. ```
  40. python tools/train_net.py \
  41. --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml \
  42. SOLVER.IMS_PER_BATCH 2 SOLVER.BASE_LR 0.0025
  43. ```
  44. For most models, CPU training is not supported.
  45. (Note that we applied the [linear learning rate scaling rule](https://arxiv.org/abs/1706.02677)
  46. when changing the batch size.)
  47. To evaluate this model's performance, use
  48. ```
  49. python tools/train_net.py \
  50. --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml \
  51. --eval-only MODEL.WEIGHTS /path/to/checkpoint_file
  52. ```
  53. For more options, see `python tools/train_net.py -h`.
  54. ### Use Detectron2 in Your Code
  55. See our [Colab Notebook](https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5)
  56. to learn how to use detectron2 APIs to:
  57. 1. run inference with an existing model
  58. 2. train a builtin model on a custom dataset
  59. See [detectron2/projects](https://github.com/facebookresearch/detectron2/tree/master/projects)
  60. for more ways to build your project on detectron2.

No Description