@@ -10,13 +10,12 @@ Image Classifier using pre-trained networks
10
10
import * as tf from '@tensorflow/tfjs' ;
11
11
import callCallback from '../utils/callcallback' ;
12
12
import { array3DToImage } from '../utils/imageUtilities' ;
13
- import Video from '../utils/Video' ;
14
13
import p5Utils from '../utils/p5Utils' ;
15
14
16
15
const URL = 'https://raw.githubusercontent.com/zaidalyafeai/HostedModels/master/unet-128/model.json' ;
17
16
const imageSize = 128 ;
18
17
19
- class UNET extends Video {
18
+ class UNET {
20
19
/**
21
20
* Create UNET class.
22
21
* @param {HTMLVideoElement | HTMLImageElement } video - The video or image to be used for segmentation.
@@ -25,27 +24,17 @@ class UNET extends Video {
25
24
* that will be resolved once the model has loaded.
26
25
*/
27
26
constructor ( video , options , callback ) {
28
- super ( video , imageSize ) ;
29
27
this . modelReady = false ;
30
28
this . isPredicting = false ;
31
29
this . ready = callCallback ( this . loadModel ( ) , callback ) ;
32
30
}
33
31
34
32
async loadModel ( ) {
35
- if ( this . videoElt && ! this . video ) {
36
- this . video = await this . loadVideo ( ) ;
37
- }
38
33
this . model = await tf . loadLayersModel ( URL ) ;
39
34
this . modelReady = true ;
40
35
return this ;
41
36
}
42
37
43
- // check if p5js
44
- // static checkP5() {
45
- // if (typeof window !== 'undefined' && window.p5 && window.p5.Image && typeof window.p5.Image === 'function') return true;
46
- // return false;
47
- // }
48
-
49
38
async segment ( inputOrCallback , cb ) {
50
39
await this . ready ;
51
40
let imgToPredict ;
@@ -82,7 +71,10 @@ class UNET extends Video {
82
71
async segmentInternal ( imgToPredict ) {
83
72
// Wait for the model to be ready
84
73
await this . ready ;
85
- await tf . nextFrame ( ) ;
74
+ // skip asking for next frame if it's not video
75
+ if ( imgToPredict instanceof HTMLVideoElement ) {
76
+ await tf . nextFrame ( ) ;
77
+ }
86
78
this . isPredicting = true ;
87
79
88
80
const tensor = tf . tidy ( ( ) => {
0 commit comments