UNET

Illustration of a background masked behind a person

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

  1. // load your model...
  2. const uNet = ml5.uNet('face');
  3. // assuming you have an HTMLVideo feed...
  4. uNet.segment(video, gotResult);
  5. function gotResult(error, result) {
  6. // if there's an error return it
  7. if (error) {
  8. console.error(error);
  9. return;
  10. }
  11. // log your result
  12. console.log(result);
  13. }

Usage

Initialize

  1. 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

  1. 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.

    1. {
    2. segmentation: mask,
    3. blob: {
    4. featureMask: *Blob*,
    5. backgroundMask: *Blob*,
    6. },
    7. tensor: {
    8. featureMask: *Tensor*,
    9. backgroundMask: *Tensor*,
    10. },
    11. raw: {
    12. featureMask: *ImageData*,
    13. backgroundMask: *ImageData*,
    14. },
    15. // returns if p5 is available
    16. featureMask: *p5Image*,
    17. backgroundMask: *p5Image*,
    18. mask: *p5Image*,
    19. };

Examples

p5.js

p5 web editor

plain javascript

Demo

No demos yet - contribute one today!

Tutorials

No tutorials yet - contribute one today!

Acknowledgements

Contributors:

Credits:

Source Code

BodyPix](#/reference/bodypix)

[

NEXT UNET - 图3

FaceApi

](#/reference/face-api)