|
15 | 15 | * =============================================================================
|
16 | 16 | */
|
17 | 17 |
|
18 |
| -import {CoralDelegate} from './index'; |
19 |
| -import {loadTFLiteModel} from 'tfjs-tflite-node'; |
20 |
| -import type {TFLiteModel} from 'tfjs-tflite-node/dist/tflite_model'; |
21 |
| -import * as fs from 'fs'; |
22 |
| -import * as tf from '@tensorflow/tfjs-core'; |
23 | 18 | import '@tensorflow/tfjs-backend-cpu';
|
24 |
| -import * as jpeg from 'jpeg-js'; |
| 19 | +import {CoralDelegate} from './index'; |
25 | 20 |
|
26 | 21 | describe('coral delegate', () => {
|
27 |
| - const modelPath = './test_model/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite'; |
28 |
| - let model: TFLiteModel; |
29 |
| - let parrot: tf.Tensor; |
30 |
| - let labels: string[]; |
31 |
| - |
32 |
| - beforeEach(async () => { |
33 |
| - model = await loadTFLiteModel(modelPath, { |
34 |
| - delegates: [new CoralDelegate([['device', 'usb']])], |
35 |
| - }); |
36 |
| - |
37 |
| - // Load the input image of a parrot. |
38 |
| - const parrotJpeg = jpeg.decode( |
39 |
| - fs.readFileSync('./test_model/parrot-small.jpg')); |
| 22 | + it('has the name "CoralDelegate"', () => { |
| 23 | + expect(new CoralDelegate().name).toEqual('CoralDelegate'); |
| 24 | + }); |
40 | 25 |
|
41 |
| - // Create an RGB array of the parrot's pixels (no Alpha channel). |
42 |
| - const {width, height, data} = parrotJpeg; |
43 |
| - const parrotRGB = new Uint8Array(width * height * 3); |
44 |
| - for (let i = 0; i < width * height; i++) { |
45 |
| - const i3 = i * 3; |
46 |
| - const i4 = i * 4; |
47 |
| - parrotRGB[i3] = data[i4]; |
48 |
| - parrotRGB[i3 + 1] = data[i4 + 1]; |
49 |
| - parrotRGB[i3 + 2] = data[i4 + 2]; |
50 |
| - } |
| 26 | + it('stores options', () => { |
| 27 | + const options: Array<[string, string]> = [['foo', 'bar'], ['123', '456']]; |
| 28 | + const coralDelegate = new CoralDelegate(options); |
| 29 | + expect(coralDelegate.options).toEqual(options); |
| 30 | + }); |
51 | 31 |
|
52 |
| - parrot = tf.tensor(parrotRGB, [1, 224, 224, 3]); |
53 |
| - labels = fs.readFileSync('./test_model/inat_bird_labels.txt', 'utf-8') |
54 |
| - .split('\n'); |
| 32 | + it('allows manually setting lib path', () => { |
| 33 | + const libPath = 'some lib path'; |
| 34 | + const coralDelegate = new CoralDelegate([], libPath); |
| 35 | + expect(coralDelegate.node.path).toEqual(libPath); |
55 | 36 | });
|
56 | 37 |
|
57 |
| - it('runs a coral model (will fail without coral device)', () => { |
58 |
| - const prediction = model.predict(parrot); |
59 |
| - const argmax = tf.argMax(prediction as tf.Tensor, 1); |
60 |
| - const label = labels[argmax.dataSync()[0]]; |
61 |
| - expect(label).toEqual('Ara macao (Scarlet Macaw)'); |
| 38 | + it('sets the lib path automatically based on platorm', () => { |
| 39 | + const coralLinux = new CoralDelegate([], undefined, 'linux'); |
| 40 | + const coralMac = new CoralDelegate([], undefined, 'darwin'); |
| 41 | + const coralWindows = new CoralDelegate([], undefined, 'win32'); |
| 42 | + |
| 43 | + expect(coralLinux.node.path).toEqual('libedgetpu.so.1'); |
| 44 | + expect(coralMac.node.path).toEqual('libedgetpu.1.dylib'); |
| 45 | + expect(coralWindows.node.path).toEqual('edgetpu.dll'); |
62 | 46 | });
|
63 | 47 | });
|
0 commit comments