1010*/
1111
1212import * as tf from '@tensorflow/tfjs' ;
13+ import axios from "axios" ;
1314import callCallback from '../utils/callcallback' ;
1415import p5Utils from '../utils/p5Utils' ;
1516
@@ -28,13 +29,11 @@ class Cvae {
2829 this . ready = false ;
2930 this . model = { } ;
3031 this . latentDim = tf . randomUniform ( [ 1 , 16 ] ) ;
31- this . modelPath = modelPath ;
32- this . modelPathPrefix = '' ;
3332
34- this . jsonLoader ( ) . then ( val => {
35- this . modelPathPrefix = this . modelPath . split ( 'manifest.json' ) [ 0 ]
36- this . ready = callCallback ( this . loadCVAEModel ( this . modelPathPrefix + val . model ) , callback ) ;
37- this . labels = val . labels ;
33+ const [ modelPathPrefix ] = modelPath . split ( 'manifest.json' ) ;
34+ axios . get ( modelPath ) . then ( ( { data } ) => {
35+ this . ready = callCallback ( this . loadCVAEModel ( modelPathPrefix + data . model ) , callback ) ;
36+ this . labels = data . labels ;
3837 // get an array full of zero with the length of labels [0, 0, 0 ...]
3938 this . labelVector = Array ( this . labels . length + 1 ) . fill ( 0 ) ;
4039 } ) ;
@@ -114,21 +113,6 @@ class Cvae {
114113 return { src, raws, image } ;
115114 }
116115
117- async jsonLoader ( ) {
118- return new Promise ( ( resolve , reject ) => {
119- const xhr = new XMLHttpRequest ( ) ;
120- xhr . open ( 'GET' , this . modelPath ) ;
121-
122- xhr . onload = ( ) => {
123- const json = JSON . parse ( xhr . responseText ) ;
124- resolve ( json ) ;
125- } ;
126- xhr . onerror = ( error ) => {
127- reject ( error ) ;
128- } ;
129- xhr . send ( ) ;
130- } ) ;
131- }
132116}
133117
134118const CVAE = ( model , callback ) => new Cvae ( model , callback ) ;
0 commit comments