-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_script.js
More file actions
131 lines (119 loc) · 3.22 KB
/
test_script.js
File metadata and controls
131 lines (119 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import fs from 'fs';
import WebSocket from 'ws';
const ws = new WebSocket('ws://127.0.0.1:9090');
ws.on('open', () => {
console.log('Connected to backend');
const nodes = [
{
"id": "net1",
"type": "createNet",
"config": {
"vendor": "ncnn",
"paramPath": "demo/NCNN_demo/shufflenet.param",
"modelPath": "",
"emptyWeights": "true",
"inputName": "data",
"outputName": "output",
"inputW": "224",
"inputH": "224",
"inputC": "3",
"numThreads": "2"
}
},
{
"id": "input1",
"type": "inputTensor",
"config": {
"fillMode": "manual",
"tensorText": "1.0, 1.0, 1.0, 1.0"
}
},
{
"id": "infer1",
"type": "inference",
"config": {}
},
{
"id": "out1",
"type": "output",
"config": {}
}
];
const edges = [
{ "source": "net1", "sourceHandle": "net_handle", "target": "infer1", "targetHandle": "net_handle" },
{ "source": "input1", "sourceHandle": "tensor_data", "target": "infer1", "targetHandle": "input_data" },
{ "source": "infer1", "sourceHandle": "output_data", "target": "out1", "targetHandle": "data" }
];
ws.send(JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'workflow.execute',
params: { nodes, edges }
}));
});
let output1 = null;
ws.on('message', (data) => {
const msg = JSON.parse(data.toString());
if (msg.method === 'node.status' && msg.params.node_id === 'out1') {
if (msg.params.output) {
output1 = msg.params.output;
console.log('Run 1 output:', output1.slice(0, 5));
}
}
if (msg.method === 'workflow.complete') {
console.log('Run 1 complete. Now changing input to all 5.0...');
const nodes2 = [
{
"id": "net1",
"type": "createNet",
"config": {
"vendor": "ncnn",
"paramPath": "demo/NCNN_demo/shufflenet.param",
"modelPath": "",
"emptyWeights": "true",
"inputName": "data",
"outputName": "output",
"inputW": "224",
"inputH": "224",
"inputC": "3",
"numThreads": "2"
}
},
{
"id": "input1",
"type": "inputTensor",
"config": {
"fillMode": "manual",
"tensorText": "5.0, 5.0, 5.0, 5.0"
}
},
{
"id": "infer1",
"type": "inference",
"config": {}
},
{
"id": "out2",
"type": "output",
"config": {}
}
];
const edges2 = [
{ "source": "net1", "sourceHandle": "net_handle", "target": "infer1", "targetHandle": "net_handle" },
{ "source": "input1", "sourceHandle": "tensor_data", "target": "infer1", "targetHandle": "input_data" },
{ "source": "infer1", "sourceHandle": "output_data", "target": "out2", "targetHandle": "data" }
];
ws.send(JSON.stringify({
jsonrpc: '2.0',
id: 2,
method: 'workflow.execute',
params: { nodes: nodes2, edges: edges2 }
}));
}
if (msg.method === 'node.status' && msg.params.node_id === 'out2') {
if (msg.params.output) {
console.log('Run 2 output:', msg.params.output.slice(0, 5));
ws.close();
}
}
});