{"cells":[{"metadata":{"id":"YpBf8xgkBdow"},"cell_type":"markdown","source":"## At first install pixellib library","execution_count":null},{"metadata":{"id":"0E_FZ30KBjcf","outputId":"9a95904e-73c9-46a9-d419-371e05dd6b0f","trusted":true},"cell_type":"code","source":"! pip install pixellib","execution_count":null,"outputs":[]},{"metadata":{"id":"3oN2rNxsBnWn"},"cell_type":"markdown","source":"## Download mask rcnn coco weights","execution_count":null},{"metadata":{"id":"vhsvjYPZBZc1","trusted":true},"cell_type":"code","source":"!wget --quiet https://github.com/matterport/Mask_RCNN/releases/download/v2.0/mask_rcnn_coco.h5","execution_count":null,"outputs":[]},{"metadata":{"id":"nEKpScAVELP5"},"cell_type":"markdown","source":"## Show Input Image","execution_count":null},{"metadata":{"id":"MkzC4Ez9D-6i","outputId":"a666326a-affc-4dca-c1f9-668861ac155f","trusted":true},"cell_type":"code","source":"import cv2\nimport matplotlib.pyplot as plt\nplt.rcParams[\"figure.figsize\"] = (50,10)\nimage=cv2.imread(\"/kaggle/input/open-images-instance-segmentation-rvc-2020/test/00000b4dcff7f799.jpg\")\nplt.imshow(image)","execution_count":null,"outputs":[]},{"metadata":{"id":"dFTjrsMJBtPS"},"cell_type":"markdown","source":"## Import Libraries and Use pixellib built in function to create object and load model","execution_count":null},{"metadata":{"id":"IYVW3XToAwdS","outputId":"47a88a71-3716-400d-c936-dbb680ce1f74","trusted":true},"cell_type":"code","source":"import pixellib\nfrom pixellib.instance import instance_segmentation\nsegment_image = instance_segmentation()\nsegment_image.load_model(\"/kaggle/working/mask_rcnn_coco.h5\") ","execution_count":null,"outputs":[]},{"metadata":{"id":"NZYpT4JLErQJ"},"cell_type":"markdown","source":"## Image Segementation and Object Detection","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"Use segmentImage function for image segmentation, pass input image and output image name, and make show_bboxes parameter True for bounding box object detection","execution_count":null},{"metadata":{"id":"xl8V_-KWCAQl","outputId":"331a0250-16e3-4800-8ab5-f63c52b05d64","trusted":true},"cell_type":"code","source":"segment_image.segmentImage(\"/kaggle/input/open-images-instance-segmentation-rvc-2020/test/00000b4dcff7f799.jpg\", output_image_name = \"/kaggle/working/output_1.jpg\",show_bboxes = True)\nimage=cv2.imread(\"/kaggle/working/output_1.jpg\")\nplt.rcParams[\"figure.figsize\"] = (50,10)\nplt.imshow(image)","execution_count":null,"outputs":[]},{"metadata":{"id":"3fXyXSpUFb3n"},"cell_type":"markdown","source":"## Image Segementation and Object Detection","execution_count":null},{"metadata":{"id":"93z7zvBDAwdj","outputId":"42b2ef54-6cb9-4426-f52e-0cc5e8d6e0b3","trusted":true},"cell_type":"code","source":"segment_image.segmentImage(\"/kaggle/input/open-images-instance-segmentation-rvc-2020/test/0005339c44e6071b.jpg\", output_image_name = \"output_2.jpg\",show_bboxes = True)\nimage=cv2.imread(\"output_2.jpg\")\nplt.imshow(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"segment_image.segmentImage(\"/kaggle/input/open-images-instance-segmentation-rvc-2020/test/00246c2940caa984.jpg\", output_image_name = \"output_3.jpg\",show_bboxes = True)\nimage=cv2.imread(\"output_3.jpg\")\nplt.imshow(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"segment_image.segmentImage(\"/kaggle/input/open-images-instance-segmentation-rvc-2020/test/006a3b0fc42143a4.jpg\", output_image_name = \"output_4.jpg\",show_bboxes = True)\nimage=cv2.imread(\"output_4.jpg\")\nplt.imshow(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"segment_image.segmentImage(\"/kaggle/input/open-images-instance-segmentation-rvc-2020/test/00841769515cc799.jpg\", output_image_name = \"output_5.jpg\",show_bboxes = True)\nimage=cv2.imread(\"output_5.jpg\")\nplt.imshow(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"segment_image.segmentImage(\"/kaggle/input/open-images-instance-segmentation-rvc-2020/test/004e5f92f9ebedad.jpg\", output_image_name = \"output_6.jpg\",show_bboxes = True)\nimage=cv2.imread(\"output_6.jpg\")\nplt.imshow(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"segment_image.segmentImage(\"/kaggle/input/open-images-instance-segmentation-rvc-2020/test/01150a01bfc01532.jpg\", output_image_name = \"output_7.jpg\",show_bboxes = True)\nimage=cv2.imread(\"output_7.jpg\")\nplt.imshow(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"segment_image.segmentImage(\"/kaggle/input/open-images-instance-segmentation-rvc-2020/test/013f7c87a409c900.jpg\", output_image_name = \"output_8.jpg\",show_bboxes = True)\nimage=cv2.imread(\"output_8.jpg\")\nplt.imshow(image)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## If you like this notebook, please upvote.","execution_count":null}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}