Skip to content

Commit 35a003e

Browse files
committed
Remove jsonLoader method in CVAE and use axios instead.
1 parent 0717d2e commit 35a003e

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

src/CVAE/index.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
import * as tf from '@tensorflow/tfjs';
13+
import axios from "axios";
1314
import callCallback from '../utils/callcallback';
1415
import 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

134118
const CVAE = (model, callback) => new Cvae(model, callback);

0 commit comments

Comments
 (0)