Please use Yolov8 on Python 3.11 and not Python 3.12. At the time of writing, TFjs has issues in Python 3.12 which prevents successful conversion of the model to TF.js
$ pip install ultralytics
The data for model training was combined from two Kaggle datasets and can be found here
The modeling steps were performed on Pycharm, while the web deployment was performed on Visual Studio Code.
Run this code to train the model based on the pretrained weights yolov8n from COCO.
$ yolo detect train data=coco8.yaml model=path/to/yaml epochs=100 imgsz=640
To train the on a custom dataset, on your custom data file, replace path/to/yaml with the path from you current directory to the yaml with your data file.
After training, you can get the model weights from runs/detect/your most recent run/best.pt
To export the model to TFjs format, make sure tensorflow and all its depedencies are installed and run
$ yolo export model=path/to/best.pt format=tfjs
The model will be ran on
To test the models performance, you can run
$ yolo detect val model=path/to/best.pt
To test it on the testing dataset, change the validation path in the yaml to your testing path
Clone this repository
Copy nameofyourwebmodel
to ./public
Update modelName
in App.jsx
to new model name
...
// model configs
const modelName = "nameofyourwebmodel"; // change to new model name
...
Scripts for testing/building
Make sure you change the base parameter in the vite.config.js file to the name of your github repository or else the source page will look for the wrong file
yarn start # Start dev server
yarn build # Build for productions
The starting model used is modified from the Ultralytics model. Thanks to Hyuto, for his creation of the initial javascript implementation.