# YOLOv5-RT-TFJS **Repository Path**: CV_Lab/yolov5_rt_tfjs ## Basic Information - **Project Name**: YOLOv5-RT-TFJS - **Description**: ๐Ÿš€ ๅŸบไบŽ TensorFlow.js ็š„ YOLOv5 ๅฎžๆ—ถ็›ฎๆ ‡ๆฃ€ๆต‹้กน็›ฎใ€‚ๆ”ฏๆŒ่‡ชๅฎšไน‰ๆจกๅž‹๏ผŒ่ฝป้‡ๅฎ‰่ฃ…ใ€ไฝฟ็”จๆ–นไพฟใ€ๅฏ็งปๆคๆ€งๅผบใ€‚ - **Primary Language**: JavaScript - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: https://gitee.com/PyCVer - **GVP Project**: No ## Statistics - **Stars**: 111 - **Forks**: 34 - **Created**: 2022-02-23 - **Last Updated**: 2025-05-30 ## Categories & Tags **Categories**: cv **Tags**: YOLOv5, JavaScript, ๅฎžๆ—ถ็›ฎๆ ‡ๆฃ€ๆต‹, ่ฎก็ฎ—ๆœบ่ง†่ง‰, TensorFlow ## README [ไธญๆ–‡็ฎ€ไฝ“](./README.md)|English

Simple Icons

YOLOv5 real-time target detection project based on TensorFlow.js, supports custom models

Lightweight installation, easy to use, and strong portability

code check Releases Version YOLOv5 Version TensorFlow.js Version jQuery Version License

Flask Version FastAPI Version Bottle Version

๐Ÿš€Update Trend

- `2023-01-09` **โšก [yolov5-rt-tfjs v0.4.2 release version](https://gitee.com/CV_Lab/yolov5_rt_tfjs/releases/v0.4.2)officially launched** - `2022-08-05` **โšก [yolov5-rt-tfjs v0.4 release version](https://gitee.com/CV_Lab/yolov5_rt_tfjs/releases/v0.4)officially launched** - `2022-03-02` **โšก [yolov5-rt-tfjs v0.3 release version](https://gitee.com/CV_Lab/yolov5_rt_tfjs/releases/v0.3)officially launched** - **โšก [yolov5-rt-tfjs historical version](./v_change)**

๐Ÿ’ŽProject Purpose

### ๐Ÿ”ฅ Custom Object Detection Task

### โค๏ธ Custom Model ๐Ÿ“Œ Modify [yolov5_rt_tfjs.js](./yolov5_rt_tfjs_src/static/js/yolov5_rt_tfjs.js) file, customize **weight file**, **category name** and **model input size** ```javascript // weight file const weights = '../yolov5s_web_model/model.json'; // classification name (English version) const cls_names = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush' ] ``` ### โค๏ธ Custom TensorFlow.js version ๐Ÿ“Œ Modify the [index.html](./yolov5_rt_tfjs_src/index.html) file to customize the version of TensorFlow.js ```html ``` โ— Note: **TensorFlow.js version>=3.9.0**, the current version used in this project is **4.2.0**

๐Ÿ’ก Project Structure

```shell . โ”œโ”€โ”€yolov5_rt_tfjs # project name โ”‚ โ”œโ”€โ”€ yolov5 # YOLOv5 project โ”‚ โ”‚ โ”œโ”€โ”€ yolov5s.pt # yolov5s model file โ”‚ โ”‚ โ”œโ”€โ”€ yolov5s_web_model # pt2tfjs model 01 (used) โ”‚ โ”‚ โ”œโ”€โ”€ yolov5s_saved_model # pt2tfjs model 02 โ”‚ โ”‚ โ”œโ”€โ”€ yolov5s.pb # pt2tfjs model 03 โ”‚ โ”‚ โ””โ”€โ”€ ... # other โ”‚ โ”œโ”€โ”€ yolov5_rt_tfjs_src # Project main directory โ”‚ โ”‚ โ”œโ”€โ”€ yolov5s_web_model # pt2tfjs model 01 โ”‚ โ”‚ โ”œโ”€โ”€ static # static file directory โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ js # JavaScript directory โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ yolov5_rt_tfjs.js # JS main run file โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ css # JavaScript directory โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ main.css # css style file โ”‚ โ”‚ โ””โ”€โ”€ index.html # Project main run file โ”‚ โ”œโ”€โ”€ yolov5_rt_tfjs_hls # Project main directory๏ผˆhls.js version๏ผ‰ โ”‚ โ”‚ โ”œโ”€โ”€ static # static file directory โ”‚ โ”‚ โ”œโ”€โ”€ โ”œโ”€โ”€ yolov5s_web_model # pt2tfjs model 01 โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ js # JavaScript directory โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ yolov5_rt_tfjs.js # JS main run file๏ผˆhls.js version๏ผ‰ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ css # JavaScript directory โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ main.css # css style file โ”‚ โ”‚ โ””โ”€โ”€ index.html # Project main run file โ”‚ โ”œโ”€โ”€ yolov5_rt_tfjs_flask # Flask version main directory โ”‚ โ”‚ โ”œโ”€โ”€ templates # flask template directory โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ index.html # flask html file โ”‚ โ”‚ โ”œโ”€โ”€ server.py # flask server file โ”‚ โ”‚ โ””โ”€โ”€ README.md # Flask version project description โ”‚ โ”œโ”€โ”€ yolov5_rt_tfjs_fastapi # FastAPI version main directory โ”‚ โ”‚ โ”œโ”€โ”€ templates # fastapi template directory โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ index.html # fastapi html file โ”‚ โ”‚ โ”œโ”€โ”€ server.py # fastapi server file โ”‚ โ”‚ โ””โ”€โ”€ README.md # Fastapi version project description โ”‚ โ”œโ”€โ”€ v_change # Version history โ”‚ โ”‚ โ”œโ”€โ”€ v01_change.md # v0.1 version changes โ”‚ โ”‚ โ”œโ”€โ”€ v02_change.md # v0.2 version changes โ”‚ โ”‚ โ””โ”€โ”€ README.md # Historical release notes โ”‚ โ”œโ”€โ”€ setup.sh # install script โ”‚ โ”œโ”€โ”€ setup_flask.sh # install script (flask version) โ”‚ โ”œโ”€โ”€ setup_fastapi.sh # install script๏ผˆfastapi version๏ผ‰ โ”‚ โ”œโ”€โ”€ LICENSE # Project License โ”‚ โ”œโ”€โ”€ CodeCheck.md # code inspection โ”‚ โ”œโ”€โ”€ .gitignore # git ignore files โ”‚ โ”œโ”€โ”€ .gitmodules # git submodule file โ”‚ โ”œโ”€โ”€ README.md # project instruction โ”‚ โ””โ”€โ”€ README.en.md # Project Description (English) ``` โ— Note: Some model files need to be generated after installation

โค๏ธ Version Creativity

๐Ÿ”ฅ yolov5-rt-tfjs v0.2 adopts **bounding box and label decoupling management mode**

๐Ÿ”ฅInstallation Tutorial

### โœ… Method 1: Linux Shell Quick Installation ๐Ÿ“Œ Create a conda environment ```shell conda create -n yolo python==3.8 ``` ๐Ÿ“Œ Execute [bash script](./setup.sh) ```shell bash setup.sh ``` ### โœ… Method 2: Manual installation ๐Ÿ“Œ Create a conda environment ```shell conda create -n yolo python==3.8 conda activate yolo # ่ฟ›ๅ…ฅ็Žฏๅขƒ ``` ๐Ÿ“Œ Install dependencies ```shell pip install -r ./requirements.txt -U pip install tensorflowjs # >=3.9.0 ``` โ— Notice: [tensorflowjs>=3.9.0](https://pypi.org/project/tensorflowjs/) ๐Ÿ“Œ Clone the project (recursive clone) ```shell git clone https://gitee.com/CV_Lab/yolov5_rt_tfjs.git --recursive ``` ๐Ÿ“Œ Add the weight file of yolov5 or **custom weight file** (.pt) to the root directory of yolov5 ๐Ÿ“Œ Convert, take [yolov5s.pt](https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5s.pt) as an example ```shell python export.py --weights yolov5s.pt --include tfjs ``` ๐Ÿ“Œ Add `yolov5s_web_model` directory to `yolov5_rt_tfjs_src`
โค๏ธ This project provides 2 extension demos: Flask version and FastAPI version, which aims to show that the project has good portability. Click on the above logo to learn about the detailed installation and usage tutorials. โ— Note: Before using the following methods, make sure that the `yolov5s_web_model` directory is added to `yolov5_rt_tfjs_src/static`. ### โœ… Method 3: [Flask version](./yolov5_rt_tfjs_flask) ๐Ÿ“Œ Create a conda environment ```shell conda create -n yolo python==3.8 conda activate yolo # into the environment ``` ๐Ÿ“Œ Execute the [setup_flask.sh](./setup_flask.sh) script ```shell bash setup_flask.sh ``` ### โœ… Method 4: [FastAPI version](./yolov5_rt_tfjs_fastapi) ๐Ÿ“Œ Create a conda environment ```shell conda create -n yolo python==3.8 conda activate yolo # into the environment ``` ๐Ÿ“Œ Execute the [setup_fastapi.sh](./setup_fastapi.sh) script ```shell bash setup_fastapi.sh ```

โšกUsage

### ๐Ÿ’ก Method 1: [VSCode](https://code.visualstudio.com/) run ๐Ÿ“Œ Install [Live Server](https://github.com/ritwickdey/vscode-live-server-plus-plus) plugin ๐Ÿ“Œ Run the program with `yolov5_rt_tfjs_src` as the working directory โค๏ธ Universal version ```shell cd yolov5_rt_tfjs_src # enter the working directory code . # open vscode # Right click, select Open with Live Server, run the program ``` โค๏ธ hls.js version ```shell cd yolov5_rt_tfjs_hls # enter the working directory code . # open vscode # Right click, select Open with Live Server, run the program ``` ### ๐Ÿ’ก Method 2: [Flask](https://github.com/pallets/flask) version ๐Ÿ“Œ Run the file [server.py](./yolov5_rt_tfjs_flask/server.py) ```shell python server.py ``` ๐Ÿ“Œ Browser input `http://127.0.0.1:5000/`

### ๐Ÿ’ก Method 3: [FastAPI](https://github.com/tiangolo/fastapi) version ๐Ÿ“Œ Run the file [server.py](./yolov5_rt_tfjs_fastapi/server.py) ```shell python server.py ``` ๐Ÿ“Œ Browser type `http://localhost:8000/`

## ๐ŸทThanks - [YOLOv5](https://github.com/ultralytics/yolov5)Founder: [Glenn Jocher](https://github.com/glenn-jocher) - [Add TensorFlow and TFLite export](https://github.com/ultralytics/yolov5/pull/1127) PR contributor: [Jiacong Fang](https://github.com/zldrobit) - [TensorFlow.jsโ€”Real-Time Object Detection Demo](https://codesandbox.io/s/z364noozrm) author: [Nick Bourdakos](https://github.com/bourdakos1)