Skip to content

Latest commit

 

History

History
169 lines (115 loc) · 6.36 KB

README.md

File metadata and controls

169 lines (115 loc) · 6.36 KB

Object Background Removal Web using YoloV8 with Flask

Python CSS HTML JavaScript OnnxRuntime Markdown Flask Visual Studio Code Windows Docker

Web application for real-time object segmentation using Flask , YOLOv8, AnimeGANv2/v3 model in ONNX weights.

After obtaining images through the camera, it is possible to separate the target and background in the scene, and composite the target with a Web URL/Local Path video background. Additionally, you can change different display styles and save a screenshot.

➤ Contents

  1. Requirements

  2. ONNX-Model

  3. Examples

  4. Docker

  5. Demo

  6. Updates

  7. License

➤ Requirements

  • OpenCV, Flask, gevent, onnxruntime and youtube-dl.

  • Install :

    The requirements.txt file should list all Python libraries that your notebooks depend on, and they will be installed using:

    pip install -r requirements.txt
    
  • Note :

    If you use a YouTube URL as the link to replace your background, please make sure to modify the following.

    1. YouTube Unable to extract uploader id, so you need to revise [Your Path]\site-packages\youtube_dl\extractor\youtube.py :
    • 'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None,

      $\Downarrow$

    • 'uploader_id': self._search_regex(r'/(?:channel/|user/|@)([^/?&#]+)', owner_profile_url, 'uploader id', default=None),

    1. Youtube does no longer have a like/dislike count, so you need to comment out [Your Path]\site-packages\pafy\backend_youtube_dl.py :
    • self._likes = self._ydl_info['like_count']

    • self._dislikes = self._ydl_info['dislike_count']

➤ ONNX-model

You can convert the YOLOv8-seg model to ONNX using the following Google Colab notebook : Open In Colab

  • The License of the models is GPL-3.0 license: License
  • Quantize ONNX models :

    Converting a model to use float16 instead of float32 can decrease the model size.

    python onnxQuantization.py -i <path-of-your-onnx-model>
    

➤ Examples

  • Setting Config :

    model_config = {
        "model_path": 'models/yolov8n-seg-coco.onnx', # model path
        "classes_path" : 'models/coco_label.txt', # classes path
        "box_score" : 0.4,
        "box_nms_iou" : 0.45,
        "box_aspect_ratio" : None,
        "box_stretch" : None,
    }
    
    cam_config = {
        "cam_id" : 0,
        'exposure': -2, # init cam exposure
        'contrast': 50 # init cam contrast
    }

    After running, the config information will appear above the menu :

  • Run :

    python Application.py
    ... 
    The server will be accessible at [ http://localhost:8080 ].
    
    Display Mode Describe
    DisplayType.NONE Just show your webcam image.
    DisplayType.BASIC_MODE Show detect and segmentation target results on image.
    DisplayType.DETECT_MODE Separate the target box and background on image.
    DisplayType.SEMANTIC_MODE Separate the target segmentation and background on image.

➤ Docker

From the root directory, run :

docker build -t <name-of-your-image> -f ./docker/Dockerfile .
docker run --rm --privileged --device="/dev/video0:/dev/video0" -t -p 8080:8080 <name-of-your-image>

➤ Demo

➤ Updates

  • 2023/05/05 - Added images with downloadable transparent backgrounds.
  • 2023/11/22 - Fixed youtube_dl bug, and remove pafy package.
  • 2023/11/26 - Fixed custom diff model size.

➤ License

WiFi Analyzer is licensed under the GNU General Public License v3.0 (GPLv3).

GPLv3 License key requirements :

  • Disclose Source
  • License and Copyright Notice
  • Same License
  • State Changes