Mask R-CNN pytorch implements code testing and interpretation

  1. https://github.com/facebookresearch/detectron2 (PyTorch implementation)
  2. https://github.com/matterport/Mask_RCNN (Tensorflow implementation). Much of this repository was built using this repository as a reference

Related installation

It is recommended to create an anaconda environment according to the tutorial to avoid conflicts.

Environment and library file installation

Installation requirements and steps, directly execute:

https://github.com/facebookresearch/maskrcnn-benchmark/blob/master/INSTALL.md

 
  1. conda create --name maskrcnn_benchmark

  2. conda activate maskrcnn_benchmark

  3.  
  4. conda install ipython

  5.  
  6. pip install ninja yacs cython matplotlib tqdm

  7.  
  8. #This step is not recommended, it is best to install directly offline

  9. conda install -c pytorch pytorch-nightly torchvision cudatoolkit=9.0

  10.  
  11. export INSTALL_DIR=$PWD

  12.  
  13. cd $INSTALL_DIR

  14. git clone https://github.com/cocodataset/cocoapi.git

  15. cd cocoapi/PythonAPI

  16. python setup.py build_ext install

  17.  
  18. cd $INSTALL_DIR

  19. git clone https://github.com/facebookresearch/maskrcnn-benchmark.git

  20. cd maskrcnn-benchmark

  21.  
  22. python setup.py build develop

  23.  
  24. unset INSTALL_DIR

(The installation of pytorch 1.0 is very slow, and it is not necessary to use the author's nightly version after testing, just install 1.0 directly with the offline package)

Note: After this build is compiled and installed, maskrcn will be pretended to be a pip library for reference. If the compilation fails, an error will be reported from maskrcnn_benchmark.config import cfg because the library file cannot be found. The conda list will be displayed after installation.

 

Weight file download

The author of the weight file is integrated in the code, automatically downloads, and the speed is relatively fast, just use his directly. When running the demo, it will automatically detect whether the corresponding location has a value file, if not, it will download, the download path is very strange, and it is embedded in the hidden folder of torch:

Cd into the folder to view the downloaded ResNet-50 and ResNet-101 models and the weight of the network:

 

Run demo

Two ways to use ready-made parameter inference

Webcam camera detection segmentation

Enter the demo folder and run it directly:

python webcam.py

Image detection segmentation

The original document is not clearly written, just slightly change it and add a file by yourself, create a new demo.py, which is written as follows:

 
  1. from maskrcnn_benchmark.config import cfg

  2. from predictor import COCODemo

  3. import torch

  4. import cv2

  5. import ipdb

  6.  
  7. ipdb.set_trace(context=35)

  8.  
  9. config_file = "../configs/caffe2/e2e_mask_rcnn_R_101_FPN_1x_caffe2.yaml"

  10. cfg.merge_from_file(config_file)

  11. cfg.merge_from_list(["MODEL.DEVICE", "cpu"])

  12. coco_demo = COCODemo(

  13. cfg,

  14. min_image_size=800,

  15. confidence_threshold=0.7,

  16. )

  17. image = cv2.imread('/py/pic/2.jpg')

  18. predictions = coco_demo.run_on_opencv_image(image)

  19. cv2.imshow("COCO detections", predictions)

  20. cv2.waitKey(0)

Just change the picture path, resnet-101 used here in config, if the video memory is not enough, change it to 50 (700M is very small). Note: config recommends using the caffe path, the outside will download the pre-training weights, which cannot be detected, and are reserved for training.

Just run:

python demo.py

 

Pre-training models provided by pytroch official website: resnet18: resnet18-5c106cde.pth and resnet50: resnet50-19c8e357.pth (the two files are packaged together)
Related download links:

 

Intelligent Recommendation

Training and testing in the Mask R-CNN-MXnet frame

Because before Faster R-CNN compiled trained, so use the same source code under mxnet framework:https://github.com/TuSimple/mx-maskrcnn mxnet installation, seeClick on the link to open Faster R-CNN co...

[Pytorch] Use Mask R-CNN for instance segmentation

Paper address:Mask R-CNN The Mask R-CNN + ResNet50 pre-trained model is used....

pytorch learning: run Mask R-CNN routines

table of Contents 1 Four must-use links for learning pytorch for image processing: 2 Problems when running Mask R-CNN routines 2.1 Where can I download engine.py transforms.py utils.py? How to downloa...

Mask R-CNN (12): Code understanding coco.py

First, the guide package, set global variables Second, the configuration Third, the data set 3.1 Loading the coco data set 3.2 Automatically downloading data sets 3.3 Loading the mask Fourth, COCO ass...

More Recommendation

Mask R-CNN (fourteen): Code understanding utils.py

First, the guide package Second, Bounding Boxes IoU, the cross-section, is equivalent to the overlap of two regions divided by the collection of two regions. For the principle of the non-maximum suppr...

Mask R-CNN (9): code understanding inspect_data.ipynb

1. Guide package First, import the package. Second, the configuration Configuration information. Third, the data set Four, visualization Visualize data set information and mask. 5. Bounding Boxes This...

Mask R-CNN (eight): code understanding demo.ipynb

First, import the package. Here we will use a model trained on the MS_COCO dataset. The configuration information of this model is located in the CocoConfig class of the coco.py file. When making pred...

Mask R-CNN (11): code understanding inspect_model.ipynb

1. Guide package Second, the configuration 3. Notebook Preferences Fourth, load the verification data set Five, load the model Sixth, running detection 6.1 Precision-Recall 6.2 Calculate mAP @ IoU = 5...

Mask R-CNN (ten): code understanding inspect_weights.ipynb

1. Guide package Second, the configuration 3. Notebook Preferences Three, load the Model Below are some weights. 4. Histogram of Weights...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top