|
1 | 1 | /* eslint new-cap: 0 */
|
2 | 2 |
|
3 |
| -// const { ImageClassifier } = ml5; |
4 |
| - |
5 |
| -// const DEFAULTS = { |
6 |
| -// learningRate: 0.0001, |
7 |
| -// hiddenUnits: 100, |
8 |
| -// epochs: 20, |
9 |
| -// numClasses: 2, |
10 |
| -// batchSize: 0.4, |
11 |
| -// }; |
12 |
| - |
13 |
| -describe('underlying Mobilenet', () => { |
14 |
| - // This is the core issue: Mobilenet itself cannot be initialized |
15 |
| - // in the karma / webpack / etc environment |
16 |
| - // it('Can initialize mobilenet', async () => { |
17 |
| - // await mobilenet.load(); |
18 |
| - // }); |
19 |
| -}); |
| 3 | +const { tf, imageClassifier } = ml5; |
| 4 | + |
| 5 | +const DEFAULTS = { |
| 6 | + learningRate: 0.0001, |
| 7 | + hiddenUnits: 100, |
| 8 | + epochs: 20, |
| 9 | + numClasses: 2, |
| 10 | + batchSize: 0.4, |
| 11 | + topk: 3, |
| 12 | + alpha: 1, |
| 13 | + version: 1, |
| 14 | +}; |
20 | 15 |
|
21 | 16 | describe('Create an image classifier', () => {
|
22 |
| - // let classifier; |
23 |
| - |
24 |
| - |
25 |
| - // beforeEach(async () => { |
26 |
| - // jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; |
27 |
| - // classifier = await imageClassifier('MobileNet', undefined, {}); |
28 |
| - // }); |
29 |
| - |
30 |
| - // it('Should create a classifier with all the defaults', async () => { |
31 |
| - // expect(classifier.version).toBe(MOBILENET_DEFAULTS.version); |
32 |
| - // expect(classifier.alpha).toBe(MOBILENET_DEFAULTS.alpha); |
33 |
| - // expect(classifier.topk).toBe(MOBILENET_DEFAULTS.topk); |
34 |
| - // expect(classifier.ready).toBeTruthy(); |
35 |
| - // }); |
36 |
| - |
37 |
| - // it('Should classify an image', async () => { |
38 |
| - // const img = new Image(); |
39 |
| - // img.crossOrigin = ''; |
40 |
| - // img.src = 'https://ml5js.org/docs/assets/img/bird.jpg'; |
41 |
| - // await new Promise((resolve) => { img.onload = resolve; }); |
42 |
| - // const results = await classifier.predict(img); |
43 |
| - // expect(results[0].className).toBe('robin, American robin, Turdus migratorius'); |
44 |
| - // }); |
| 17 | + let classifier; |
| 18 | + |
| 19 | + beforeEach(async () => { |
| 20 | + jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; |
| 21 | + classifier = await imageClassifier('MobileNet', undefined, {}); |
| 22 | + }); |
| 23 | + |
| 24 | + it('Should create a classifier with all the defaults', async () => { |
| 25 | + expect(classifier.version).toBe(DEFAULTS.version); |
| 26 | + expect(classifier.alpha).toBe(DEFAULTS.alpha); |
| 27 | + expect(classifier.topk).toBe(DEFAULTS.topk); |
| 28 | + expect(classifier.ready).toBeTruthy(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('Should classify an robin, American robin, Turdus migratorius', async () => { |
| 32 | + const img = new Image(); |
| 33 | + img.crossOrigin = ''; |
| 34 | + img.src = 'https://ml5js.org/docs/assets/img/bird.jpg'; |
| 35 | + await new Promise((resolve) => { img.onload = resolve; }); |
| 36 | + classifier.predict(img) |
| 37 | + .then(results => expect(results[0].className).toBe('robin, American robin, Turdus migratorius')); |
| 38 | + }); |
45 | 39 | });
|
0 commit comments