Skip to content

Commit 430a870

Browse files
committed
Merge branch 'EonYang-adding-testjs-for-UNET' into development
2 parents 1f69115 + 3022243 commit 430a870

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

src/UNET/index.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ Image Classifier using pre-trained networks
1010
import * as tf from '@tensorflow/tfjs';
1111
import callCallback from '../utils/callcallback';
1212
import { array3DToImage } from '../utils/imageUtilities';
13-
import Video from '../utils/Video';
1413
import p5Utils from '../utils/p5Utils';
1514

1615
const URL = 'https://raw.githubusercontent.com/zaidalyafeai/HostedModels/master/unet-128/model.json';
1716
const imageSize = 128;
1817

19-
class UNET extends Video {
18+
class UNET {
2019
/**
2120
* Create UNET class.
2221
* @param {HTMLVideoElement | HTMLImageElement} video - The video or image to be used for segmentation.
@@ -25,27 +24,17 @@ class UNET extends Video {
2524
* that will be resolved once the model has loaded.
2625
*/
2726
constructor(video, options, callback) {
28-
super(video, imageSize);
2927
this.modelReady = false;
3028
this.isPredicting = false;
3129
this.ready = callCallback(this.loadModel(), callback);
3230
}
3331

3432
async loadModel() {
35-
if (this.videoElt && !this.video) {
36-
this.video = await this.loadVideo();
37-
}
3833
this.model = await tf.loadLayersModel(URL);
3934
this.modelReady = true;
4035
return this;
4136
}
4237

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-
4938
async segment(inputOrCallback, cb) {
5039
await this.ready;
5140
let imgToPredict;
@@ -82,7 +71,10 @@ class UNET extends Video {
8271
async segmentInternal(imgToPredict) {
8372
// Wait for the model to be ready
8473
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+
}
8678
this.isPredicting = true;
8779

8880
const tensor = tf.tidy(() => {

src/UNET/index_test.js

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)