└── PixelLib-Tutorial.ipynb /PixelLib-Tutorial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 1. Install and Import Dependencies" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "!pip install tensorflow==2.4.1 tensorflow-gpu==2.4.1 pixellib opencv-python" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "import pixellib\n", 26 | "from pixellib.instance import instance_segmentation\n", 27 | "import cv2" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "# 2. Setup Model" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "segmentation_model = instance_segmentation()\n", 44 | "segmentation_model.load_model('mask_rcnn_coco.h5')" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "# 3. Real Time Capture" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 10, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "cap = cv2.VideoCapture(0)\n", 61 | "while cap.isOpened():\n", 62 | " ret, frame = cap.read()\n", 63 | " \n", 64 | " # Apply instance segmentation\n", 65 | " res = segmentation_model.segmentFrame(frame, show_bboxes=True)\n", 66 | " image = res[1]\n", 67 | " \n", 68 | " cv2.imshow('Instance Segmentation', image)\n", 69 | " \n", 70 | " if cv2.waitKey(10) & 0xFF == ord('q'):\n", 71 | " break\n", 72 | " \n", 73 | "cap.release()\n", 74 | "cv2.destroyAllWindows()" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "segmentation_model.segmentFrame??" 84 | ] 85 | } 86 | ], 87 | "metadata": { 88 | "kernelspec": { 89 | "display_name": "pixellib", 90 | "language": "python", 91 | "name": "pixellib" 92 | }, 93 | "language_info": { 94 | "codemirror_mode": { 95 | "name": "ipython", 96 | "version": 3 97 | }, 98 | "file_extension": ".py", 99 | "mimetype": "text/x-python", 100 | "name": "python", 101 | "nbconvert_exporter": "python", 102 | "pygments_lexer": "ipython3", 103 | "version": "3.7.3" 104 | } 105 | }, 106 | "nbformat": 4, 107 | "nbformat_minor": 2 108 | } 109 | --------------------------------------------------------------------------------