diff --git a/models/cv/segmentation/mask_rcnn/ixrt/README.md b/models/cv/segmentation/mask_rcnn/ixrt/README.md index 8b2bd2b7689b50dfdad9f526d80b880eb19eed70..ab86e0886d58ed6a8bd77e50eca92c68f3acafae 100644 --- a/models/cv/segmentation/mask_rcnn/ixrt/README.md +++ b/models/cv/segmentation/mask_rcnn/ixrt/README.md @@ -4,45 +4,60 @@ Mask R-CNN (Mask Region-Based Convolutional Neural Network) is an extension of the Faster R-CNN model, which is itself an improvement over R-CNN and Fast R-CNN. Developed by Kaiming He et al., Mask R-CNN is designed for object instance segmentation tasks, meaning it not only detects objects within an image but also generates high-quality segmentation masks for each instance. -## Setup +## Prepare + +```bash +# go to current model home path +cd ${PROJ_ROOT}/models/cv/segmentation/mask_rcnn/ixrt +``` + +Prepare weights and datasets referring to below steps: + +"maskrcnn.wts" [export method](https://github.com/wang-xinyu/tensorrtx/tree/master/rcnn#how-to-run) -Prepare on MR GPU +- use the [script](https://github.com/wang-xinyu/tensorrtx/blob/master/rcnn/gen_wts.py) +- use the [config file](https://github.com/facebookresearch/detectron2/blob/main/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_1x.yaml) +- use [weights](https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_1x/137259246/model_final_9243eb.pkl) ```bash -cd PATH/TO/scripts -bash init.sh +# put maskrcnn.wts in "python/maskrcnn.wts" +wget -P python/ http://files.deepspark.org.cn:880/deepspark/wts/maskrcnn.wts ``` -Prepare on NV GPU +Visit [COCO site](https://cocodataset.org/) and get COCO2017 datasets + +- images directory: coco/images/val2017/*.jpg +- annotations directory: coco/annotations/instances_val2017.json + +## Setup ```bash -cd PATH/TO/scripts -bash init_nv.sh +cd scripts/ ``` -### Model Conversion +### Prepare on MR GPU -Prepare weights and datasets referring to below steps: +```bash +bash init.sh +``` + +### Prepare on NV GPU -- "maskrcnn.wts" [export method](https://github.com/wang-xinyu/tensorrtx/tree/master/rcnn#how-to-run), use the [script](https://github.com/wang-xinyu/tensorrtx/blob/master/rcnn/gen_wts.py), use the [config file](https://github.com/facebookresearch/detectron2/blob/main/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_1x.yaml), use [weights](https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_1x/137259246/model_final_9243eb.pkl) - - put maskrcnn.wts in "python/maskrcnn.wts" -- Visit [COCO site](https://cocodataset.org/) and get COCO2017 datasets - - images directory: coco/images/val2017/*.jpg - - annotations directory: coco/annotations/instances_val2017.json +```bash +bash init_nv.sh +``` ## Inference ### FP16 Performance ```bash -cd PATH/TO/scripts bash infer_maskrcnn_fp16_performance.sh ``` ### FP16 Accuracy ```bash -cd PATH/TO/scripts bash infer_maskrcnn_fp16_acc.sh ``` diff --git a/models/cv/segmentation/mask_rcnn/ixrt/python/maskrcnn.py b/models/cv/segmentation/mask_rcnn/ixrt/python/maskrcnn.py index 6362d01167e0f3a8490b9d16875a12d39d83c7b2..75484195b0424a3ef852e620fb1dea2390048700 100644 --- a/models/cv/segmentation/mask_rcnn/ixrt/python/maskrcnn.py +++ b/models/cv/segmentation/mask_rcnn/ixrt/python/maskrcnn.py @@ -206,12 +206,12 @@ def get_maskrcnn_perf(config): # Process I/O and execute the network cuda.memcpy_htod(inputs[0]["allocation"], data_batch) - # warm up + # warm up print("Warmup start ...") for i in range(5): context.execute_v2(allocations) print("Warmup done !\nStart forward ...") - # run + # run forward_time = 0 for i in range(20): start_time = time.time() @@ -268,12 +268,12 @@ def get_maskrcnn_acc(config): # Prepare the output data output = np.zeros(outputs[0]["shape"], outputs[0]["dtype"]) - # warm up + # warm up print("Warmup start ...") for i in range(3): context.execute_v2(allocations) print("Warmup done !\nStart forward ...") - + # run start_time = time.time() for batch_data, batch_img_shape, batch_img_id, batched_paddings, paths in tqdm(dataloader): @@ -287,7 +287,7 @@ def get_maskrcnn_acc(config): # cpu -> gpu batch_data = np.ascontiguousarray(batch_data) cuda.memcpy_htod(inputs[0]["allocation"], batch_data) - + context.execute_v2(allocations) # gpu -> cpu @@ -318,17 +318,17 @@ def get_maskrcnn_acc(config): print(F"E2E time : {end2end_time:.3f} seconds") print("Forward done !") - + tmp_result_name = "pred_results.json" if os.path.exists(tmp_result_name): os.remove(tmp_result_name) with open(tmp_result_name, "w") as f: json.dump(json_result, f) - + anno = COCO(anno_json) # init annotations api pred = anno.loadRes(tmp_result_name) # init predictions api - + eval = COCOeval(anno, pred, "bbox") eval.evaluate() eval.accumulate() @@ -344,11 +344,11 @@ def get_maskrcnn_acc(config): _, map50 = eval.stats[:2] print("bbox mAP@0.5 : ", map50) print(f"bbox Accuracy Check : Test {map50} >= target {config.map_target}") - + _, segm_map50 = segm_eval.stats[:2] print("segm mAP@0.5 : ", segm_map50) print(f"segm Accuracy Check : Test {segm_map50} >= target {config.segm_map_target}") - + if map50 >= config.map_target and segm_map50 >= config.segm_map_target: print("pass!") else: diff --git a/models/cv/segmentation/mask_rcnn/ixrt/scripts/init.sh b/models/cv/segmentation/mask_rcnn/ixrt/scripts/init.sh index 7b699195a5bdf40b74f2d610a51bb5b17e5415ef..bd1fe1177a797dc149968f82017ee25877667c00 100644 --- a/models/cv/segmentation/mask_rcnn/ixrt/scripts/init.sh +++ b/models/cv/segmentation/mask_rcnn/ixrt/scripts/init.sh @@ -14,13 +14,14 @@ # under the License. # build plugin -cd ../plugins +pushd ../plugins rm -rf build mkdir build cd build -cmake .. -DIXRT_HOME=/usr/local/corex -# cmake .. -DIXRT_HOME=/opt/sw_home/local +cmake .. -D CMAKE_C_COMPILER="/usr/local/corex/bin/clang" -D CMAKE_CXX_COMPILER="/usr/local/corex/bin/clang++" -DIXRT_HOME=/usr/local/corex + make -j8 +popd ## install packages @@ -28,10 +29,10 @@ bash prepare_system_env.sh # pip whl #pip3 install opencv-python==4.6.0.66 -pip3 install pycocotools==2.0.2 +pip3 install pycocotools==2.0.7 pip3 install tqdm # build engine -cd ../../python +cd ../python rm -rf ./maskrcnn.engine python3 maskrcnn.py build_engine --wts_file ./maskrcnn.wts --engine_file ./maskrcnn.engine