UNET
Description
The U-Net is a convolutional neural network that was developed for biomedical image segmentation at the Computer Science Department of the University of Freiburg, Germany.[1] The network is based on the fully convolutional network [2] and its architecture was modified and extended to work with fewer training images and to yield more precise segmentations.
UNET allows you to segment an image.
The ml5 unet face
allows you to remove, for example, the background from video of the upper body of person.
Quickstart
// load your model...
const uNet = ml5.uNet('face');
// assuming you have an HTMLVideo feed...
uNet.segment(video, gotResult);
function gotResult(error, result) {
// if there's an error return it
if (error) {
console.error(error);
return;
}
// log your result
console.log(result);
}
Usage
Initialize
const unet = ml5.uNet(model, ?callback);
Parameters
- model: A string to the path of the JSON model.
- callback: Optional. A callback function that is called once the model has loaded. If no callback is provided, it will return a promise that will be resolved once the model has loaded.
Properties
.ready
Boolean. Boolean value that specifies if the model has loaded.
Methods
.segment()
segments the image
unet.segment(?video, ?callback);
📥 Inputs
- video: Optional. A HTML video element or a p5 video element.
- callback: Optional. A function to run once the model has been loaded.
📤 Outputs
Object: Returns an Object.
{
segmentation: mask,
blob: {
featureMask: *Blob*,
backgroundMask: *Blob*,
},
tensor: {
featureMask: *Tensor*,
backgroundMask: *Tensor*,
},
raw: {
featureMask: *ImageData*,
backgroundMask: *ImageData*,
},
// returns if p5 is available
featureMask: *p5Image*,
backgroundMask: *p5Image*,
mask: *p5Image*,
};
Examples
p5.js
p5 web editor
plain javascript
Demo
No demos yet - contribute one today!
Tutorials
No tutorials yet - contribute one today!
Acknowledgements
Contributors:
- Developed by Zaid Alyafeai
- Additional contributions by Joey Lee
Credits:
- UNET ‘face’ was trained by Zaid Alyafeai using mut1ny - Face/Head segmentation dataset.
Source Code
-
[ PREVIOUS
BodyPix](#/reference/bodypix)
[
NEXT
FaceApi
](#/reference/face-api)