- Notifications
You must be signed in to change notification settings - Fork88
In-Browser Object Detection using Tiny YOLO on Tensorflow.js
License
ModelDepot/tfjs-yolo-tiny
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Detect objects in images right in your browser usingTensorflow.js! Currently takes ~800msto analyze each frame on Chrome MBP 13" mid-2014.
SupportsTiny YOLO, as of right now,tfjs does not havesupport to run any full YOLO models (and your user's computers probablycan't handle it either).
(You can only get so far with 1 FPS)
yarn add tfjs-yolo-tinynpm install tfjs-yolo-tinyimportyolo,{downloadModel}from'tfjs-yolo-tiny';constmodel=awaitdownloadModel();constinputImage=webcam.capture();constboxes=awaityolo(inputImage,model);// Display detected boxesboxes.forEach(box=>{const{ top, left, bottom, right, classProb, className,}=box;drawRect(left,top,right-left,bottom-top,`${className}${classProb}`)});
| Param | Type | Default | Description |
|---|---|---|---|
| input | tf.Tensor | - | Expected shape (1, 416, 416, 3) Tensor representing input image (RGB 416x416) |
| model | tf.Model | - | Tiny YOLO tf.Model |
| [options] | Object | See Below | Optional, Additional Configs |
If you're using a custom Tiny YOLO model or want to adjust the defaultfiltering cutoffs, you may do so by passing an additional optionsobject.
Example:yolo(inputImage, model, { classProbThreshold: 0.8 });
| Option | Type | Default | Description |
|---|---|---|---|
| [options.classProbThreshold] | Number | 0.4 | Filter out classes below a certain threshold |
| [options.iouThreshold] | Number | 0.4 | Filter out boxes that have an IoU greater than this threadhold (refer to tf.image.nonMaxSuppression) |
| [options.filterBoxesThreshold] | Number | 0.01 | Threshold to filter out box confidence * class confidence |
| [options.maxBoxes] | Number | 2048 | Number of max boxes to return, refer to tf.image.nonMaxSuppression. Note: The model itself can only return so many boxes. |
| [options.yoloAnchors] | tf.Tensor | See src/postprocessing.js | (Advanced) Yolo Anchor Boxes, only needed if retraining on a new dataset |
| [options.width] | Number | 416 | (Advanced) If your model's input width is not 416, only if you're using a custom model |
| [options.height] | Number | 416 | (Advanced) If your model's input height is not 416, only if you're using a custom model |
| [options.numClasses] | Number | 80 | (Advanced) If your model has a different number of classes, only if you're using a custom model |
| [options.classNames] | Array.<String> | See src/coco_classes.js | (Advanced) If your model has non-MSCOCO class names, only if you're using a custom model |
Returns an array of objects.
| Property | Type | Description |
|---|---|---|
| top | Number | Pixels from top of image where bounding box starts |
| left | Number | Pixels from left of image where bounding box starts |
| bottom | Number | Pixels from top of image where box ends. |
| right | Number | Pixels from left of image where box ends. |
| classProb | Number | Probability of the class in the bounding box. |
| className | String | Human name of the class. |
| Param | Type | Default | Description |
|---|---|---|---|
| url | string | See DEFAULT_MODEL_LOCATION | Tiny YOLO Model config path. Seetf.loadModel |
Returns aPromise that can resolve to atf.Model.
PR's are more than welcome! Perf improvement or better test coverageare probably the two biggest areas of immediate need. If you have thoughtson extensibility as well, feel free to open an issue!
yarn installIf you're running tests, make sure toyarn add @tensorflow/tfjs@0.7.0so that you you don't get tfjs package not found errors. If you're developing,make sure to remove tfjs as a dependency, as it'll start using thelocal version oftfjs intead of the peer version.
Note: Test coverage is poor, definitely don't rely on them to catch your errors.
yarn testyarn buildOr during development, use watch mode, you can use thedemo appto test out changes.
yarn watchAbout
In-Browser Object Detection using Tiny YOLO on Tensorflow.js
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.
