rknn.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. var rknn = rknn || {};
  2. var base = base || require('./base');
  3. var flatbuffers = flatbuffers || require('./flatbuffers');
  4. var json = json || require('./json');
  5. rknn.ModelFactory = class {
  6. match(context) {
  7. return rknn.Container.open(context);
  8. }
  9. open(context, match) {
  10. return context.require('./rknn-schema').then(() => {
  11. rknn.schema = flatbuffers.get('rknn').rknn;
  12. return context.metadata('rknn-metadata.json').then((metadata) => {
  13. const container = match;
  14. const type = container.type;
  15. switch (type) {
  16. case 'json': {
  17. const buffer = container.value;
  18. const reader = json.TextReader.open(buffer);
  19. const model = reader.read();
  20. return new rknn.Model(metadata, type, model, container.next);
  21. }
  22. case 'flatbuffers': {
  23. const buffer = container.value;
  24. const reader = flatbuffers.BinaryReader.open(buffer);
  25. const model = rknn.schema.Model.create(reader);
  26. return new rknn.Model(metadata, type, model, null);
  27. }
  28. case 'openvx': {
  29. const buffer = container.value;
  30. const model = new openvx.Model(buffer);
  31. return new rknn.Model(metadata, type, model, null);
  32. }
  33. default: {
  34. throw new rknn.Error("Unsupported RKNN format '" + container.type + "'.");
  35. }
  36. }
  37. });
  38. });
  39. }
  40. };
  41. rknn.Model = class {
  42. constructor(metadata, type, model, next) {
  43. switch (type) {
  44. case 'json': {
  45. this._format = 'RKNN v' + model.version.split('-').shift();
  46. this._name = model.name || '';
  47. this._producer = model.ori_network_platform || model.network_platform || '';
  48. this._runtime = model.target_platform ? model.target_platform.join(',') : '';
  49. this._graphs = [ new rknn.Graph(metadata, type, model.name || '', model, next) ];
  50. break;
  51. }
  52. case 'flatbuffers': {
  53. const version = model.compiler.split('-').shift();
  54. this._format = 'RKNN Lite' + (version ? ' v' + version : '');
  55. this._runtime = model.runtime;
  56. this._name = model.name || '';
  57. this._graphs = model.graphs.map((graph) => new rknn.Graph(metadata, type, '', graph, null));
  58. this._metadata = [];
  59. this._metadata.push({ name: 'source', value: model.source });
  60. break;
  61. }
  62. case 'openvx': {
  63. this._format = 'RKNN OpenVX';
  64. this._name = model.name || '';
  65. this._graphs = [ new rknn.Graph(metadata, type, '', model, next) ];
  66. break;
  67. }
  68. default: {
  69. throw new rknn.Error("Unsupported RKNN model type '" + type + "'.");
  70. }
  71. }
  72. }
  73. get format() {
  74. return this._format;
  75. }
  76. get name() {
  77. return this._name;
  78. }
  79. get producer() {
  80. return this._producer;
  81. }
  82. get runtime() {
  83. return this._runtime;
  84. }
  85. get metadata() {
  86. return this._metadata;
  87. }
  88. get graphs() {
  89. return this._graphs;
  90. }
  91. };
  92. rknn.Graph = class {
  93. constructor(metadata, type, name, obj, next) {
  94. this._name = name;
  95. this._inputs = [];
  96. this._outputs = [];
  97. this._nodes = [];
  98. switch (type) {
  99. case 'json': {
  100. const model = obj;
  101. const args = new Map();
  102. for (const const_tensor of model.const_tensor) {
  103. const name = 'const_tensor:' + const_tensor.tensor_id.toString();
  104. const shape = new rknn.TensorShape(const_tensor.size);
  105. const type = new rknn.TensorType(const_tensor.dtype, shape);
  106. const tensor = new rknn.Tensor(type, const_tensor.offset, next.value);
  107. const argument = new rknn.Argument(name, type, tensor);
  108. args.set(name, argument);
  109. }
  110. for (const virtual_tensor of model.virtual_tensor) {
  111. const name = virtual_tensor.node_id.toString() + ':' + virtual_tensor.output_port.toString();
  112. const argument = new rknn.Argument(name, null, null);
  113. args.set(name, argument);
  114. }
  115. for (const norm_tensor of model.norm_tensor) {
  116. const name = 'norm_tensor:' + norm_tensor.tensor_id.toString();
  117. const shape = new rknn.TensorShape(norm_tensor.size);
  118. const type = new rknn.TensorType(norm_tensor.dtype, shape);
  119. const argument = new rknn.Argument(name, type, null);
  120. args.set(name, argument);
  121. }
  122. const arg = (name) => {
  123. if (!args.has(name)) {
  124. const argument = new rknn.Argument(name, null, null);
  125. args.set(name, argument);
  126. }
  127. return args.get(name);
  128. };
  129. for (const node of model.nodes) {
  130. node.input = [];
  131. node.output = [];
  132. }
  133. for (const connection of model.connection) {
  134. switch (connection.left) {
  135. case 'input':
  136. model.nodes[connection.node_id].input.push(connection);
  137. if (connection.right_node) {
  138. model.nodes[connection.right_node.node_id].output[connection.right_node.tensor_id] = connection;
  139. }
  140. break;
  141. case 'output':
  142. model.nodes[connection.node_id].output.push(connection);
  143. break;
  144. default:
  145. throw new rknn.Error("Unsupported left connection '" + connection.left + "'.");
  146. }
  147. }
  148. for (const graph of model.graph) {
  149. const key = graph.right + ':' + graph.right_tensor_id.toString();
  150. const argument = arg(key);
  151. const name = graph.left + (graph.left_tensor_id === 0 ? '' : graph.left_tensor_id.toString());
  152. const parameter = new rknn.Parameter(name, [ argument ]);
  153. switch (graph.left) {
  154. case 'input':
  155. this._inputs.push(parameter);
  156. break;
  157. case 'output':
  158. this._outputs.push(parameter);
  159. break;
  160. default:
  161. throw new rknn.Error("Unsupported left graph connection '" + graph.left + "'.");
  162. }
  163. }
  164. this._nodes = model.nodes.map((node) => new rknn.Node(metadata, type, node, arg, next));
  165. break;
  166. }
  167. case 'flatbuffers': {
  168. const graph = obj;
  169. const args = graph.tensors.map((tensor) => new rknn.Argument(tensor.name));
  170. const arg = (index) => {
  171. if (index >= args.length) {
  172. throw new rknn.Error("Invalid tensor index '" + index.toString() + "'.");
  173. }
  174. return args[index];
  175. };
  176. this._nodes = graph.nodes.map((node) => new rknn.Node(metadata, type, node, arg, next));
  177. break;
  178. }
  179. case 'openvx': {
  180. const model = obj;
  181. this._nodes = model.nodes.map((node) => new rknn.Node(metadata, type, node, null, next));
  182. break;
  183. }
  184. default: {
  185. throw new rknn.Error("Unsupported RKNN graph type '" + type + "'.");
  186. }
  187. }
  188. }
  189. get name() {
  190. return this._name;
  191. }
  192. get inputs() {
  193. return this._inputs;
  194. }
  195. get outputs() {
  196. return this._outputs;
  197. }
  198. get nodes() {
  199. return this._nodes;
  200. }
  201. };
  202. rknn.Parameter = class {
  203. constructor(name, args) {
  204. this._name = name;
  205. this._arguments = args;
  206. }
  207. get name() {
  208. return this._name;
  209. }
  210. get visible() {
  211. return true;
  212. }
  213. get arguments() {
  214. return this._arguments;
  215. }
  216. };
  217. rknn.Argument = class {
  218. constructor(name, type, initializer) {
  219. if (typeof name !== 'string') {
  220. throw new rknn.Error("Invalid argument identifier '" + JSON.stringify(name) + "'.");
  221. }
  222. this._name = name;
  223. this._type = type || null;
  224. this._initializer = initializer || null;
  225. }
  226. get name() {
  227. return this._name;
  228. }
  229. get type() {
  230. return this._type;
  231. }
  232. get initializer() {
  233. return this._initializer;
  234. }
  235. };
  236. rknn.Node = class {
  237. constructor(metadata, type, node, arg, next) {
  238. switch (type) {
  239. case 'json': {
  240. this._name = node.name || '';
  241. if (node.op === 'VSI_NN_OP_NBG' && next && next.type === 'openvx') {
  242. const buffer = next.value;
  243. const model = new openvx.Model(buffer);
  244. this._type = new rknn.Graph(metadata, next.type, 'NBG', model, null);
  245. }
  246. else if (node.op === 'RKNN_OP_NNBG' && next && next.type === 'flatbuffers') {
  247. const buffer = next.value;
  248. const reader = flatbuffers.BinaryReader.open(buffer);
  249. const model = rknn.schema.Model.create(reader);
  250. this._type = new rknn.Graph(metadata, next.type, 'NNBG', model.graphs[0], null);
  251. }
  252. else {
  253. this._type = Object.assign({}, metadata.type(node.op) || { name: node.op });
  254. for (const prefix of [ 'VSI_NN_OP_', 'RKNN_OP_' ]) {
  255. this._type.name = this._type.name.startsWith(prefix) ? this._type.name.substring(prefix.length) : this._type.name;
  256. }
  257. }
  258. this._inputs = [];
  259. this._outputs = [];
  260. this._attributes = [];
  261. node.input = node.input || [];
  262. for (let i = 0; i < node.input.length; ) {
  263. const input = this._type && this._type.inputs && i < this._type.inputs.length ? this._type.inputs[i] : { name: i === 0 ? 'input' : i.toString() };
  264. const count = input.list ? node.input.length - i : 1;
  265. const list = node.input.slice(i, i + count).map((input) => {
  266. if (input.right_tensor) {
  267. return arg(input.right_tensor.type + ':' + input.right_tensor.tensor_id.toString());
  268. }
  269. if (input.right_node) {
  270. return arg(input.right_node.node_id.toString() + ':' + input.right_node.tensor_id.toString());
  271. }
  272. throw new rknn.Error('Invalid input argument.');
  273. });
  274. this._inputs.push(new rknn.Parameter(input.name, list));
  275. i += count;
  276. }
  277. node.output = node.output || [];
  278. for (let i = 0; i < node.output.length; ) {
  279. const output = this._metadata && this._metadata.outputs && i < this._metadata.outputs.length ? this._metadata.outputs[i] : { name: i === 0 ? 'output' : i.toString() };
  280. const count = output.list ? node.output.length - i : 1;
  281. const list = node.output.slice(i, i + count).map((output) => {
  282. if (output.right_tensor) {
  283. return arg(output.right_tensor.type + ':' + output.right_tensor.tensor_id.toString());
  284. }
  285. if (output.right_node) {
  286. return arg(output.right_node.node_id.toString() + ':' + output.right_node.tensor_id.toString());
  287. }
  288. throw new rknn.Error('Invalid output argument.');
  289. });
  290. this._outputs.push(new rknn.Parameter(output.name, list));
  291. i += count;
  292. }
  293. if (node.nn) {
  294. const nn = node.nn;
  295. for (const key of Object.keys(nn)) {
  296. const params = nn[key];
  297. for (const name of Object.keys(params)) {
  298. const value = params[name];
  299. this._attributes.push(new rknn.Attribute(name, value));
  300. }
  301. }
  302. }
  303. break;
  304. }
  305. case 'flatbuffers': {
  306. this._name = node.name;
  307. this._type = metadata.type(node.type);
  308. this._inputs = Array.from(node.inputs).map((input, index) => {
  309. const argument = arg(input);
  310. return new rknn.Parameter(index.toString(), [ argument ]);
  311. });
  312. this._outputs = Array.from(node.outputs).map((output, index) => {
  313. const argument = arg(output);
  314. return new rknn.Parameter(index.toString(), [ argument ]);
  315. });
  316. this._attributes = [];
  317. break;
  318. }
  319. case 'openvx': {
  320. this._name = '';
  321. this._type = metadata.type(node.type);
  322. this._inputs = [];
  323. this._outputs = [];
  324. this._attributes = [];
  325. break;
  326. }
  327. default: {
  328. throw new rknn.Error("Unsupported RKNN node type '" + type + "'.");
  329. }
  330. }
  331. }
  332. get name() {
  333. return this._name;
  334. }
  335. get type() {
  336. return this._type;
  337. }
  338. get inputs() {
  339. return this._inputs;
  340. }
  341. get outputs() {
  342. return this._outputs;
  343. }
  344. get attributes() {
  345. return this._attributes;
  346. }
  347. };
  348. rknn.Attribute = class {
  349. constructor(name, value) {
  350. this._name = name;
  351. this._value = value;
  352. }
  353. get name() {
  354. return this._name;
  355. }
  356. get value() {
  357. return this._value;
  358. }
  359. };
  360. rknn.Tensor = class {
  361. constructor(type, offset, weights) {
  362. this._type = type;
  363. let size = 0;
  364. switch (this._type.dataType) {
  365. case 'uint8': size = 1; break;
  366. case 'int8': size = 1; break;
  367. case 'int16': size = 2; break;
  368. case 'int32': size = 4; break;
  369. case 'int64': size = 8; break;
  370. case 'float16': size = 2; break;
  371. case 'float32': size = 4; break;
  372. case 'float64': size = 8; break;
  373. case 'vdata': size = 1; break;
  374. default: throw new rknn.Error("Unsupported tensor data type '" + this._type.dataType + "'.");
  375. }
  376. const shape = type.shape.dimensions;
  377. size = size * shape.reduce((a, b) => a * b, 1);
  378. if (size > 0) {
  379. this._data = weights.slice(offset, offset + size);
  380. }
  381. }
  382. get type() {
  383. return this._type;
  384. }
  385. get state() {
  386. return this._context().state || null;
  387. }
  388. get value() {
  389. const context = this._context();
  390. if (context.state) {
  391. return null;
  392. }
  393. context.limit = Number.MAX_SAFE_INTEGER;
  394. return this._decode(context, 0);
  395. }
  396. toString() {
  397. const context = this._context();
  398. if (context.state) {
  399. return '';
  400. }
  401. context.limit = 10000;
  402. const value = this._decode(context, 0);
  403. return JSON.stringify(value, '', ' ');
  404. }
  405. _context() {
  406. const context = {};
  407. if (!this._type.dataType) {
  408. context.state = 'Tensor data type is not implemented.';
  409. return context;
  410. }
  411. if (!this._data) {
  412. context.state = 'Tensor data is empty.';
  413. return context;
  414. }
  415. context.index = 0;
  416. context.count = 0;
  417. context.shape = this._type.shape.dimensions;
  418. context.dataType = this._type.dataType;
  419. context.view = new DataView(this._data.buffer, this._data.byteOffset, this._data.byteLength);
  420. return context;
  421. }
  422. _decode(context, dimension) {
  423. const shape = context.shape.length !== 0 ? context.shape : [ 1 ];
  424. const results = [];
  425. const size = shape[dimension];
  426. if (dimension == shape.length - 1) {
  427. for (let i = 0; i < size; i++) {
  428. if (context.count > context.limit) {
  429. results.push('...');
  430. return results;
  431. }
  432. switch (context.dataType) {
  433. case 'float16':
  434. results.push(context.view.getFloat16(context.index, true));
  435. context.index += 2;
  436. context.count++;
  437. break;
  438. case 'float32':
  439. results.push(context.view.getFloat32(context.index, true));
  440. context.index += 4;
  441. context.count++;
  442. break;
  443. case 'float64':
  444. results.push(context.view.getFloat64(context.index, true));
  445. context.index += 8;
  446. context.count++;
  447. break;
  448. case 'uint8':
  449. results.push(context.view.getUint8(context.index, true));
  450. context.index++;
  451. context.count++;
  452. break;
  453. case 'int8':
  454. results.push(context.view.getInt8(context.index, true));
  455. context.index += 1;
  456. context.count++;
  457. break;
  458. case 'int16':
  459. results.push(context.view.getInt16(context.index, true));
  460. context.index += 2;
  461. context.count++;
  462. break;
  463. case 'int32':
  464. results.push(context.view.getInt32(context.index, true));
  465. context.index += 4;
  466. context.count++;
  467. break;
  468. case 'int64':
  469. results.push(context.view.getInt64(context.index, true));
  470. context.index += 8;
  471. context.count++;
  472. break;
  473. default:
  474. throw new rknn.Error("Unsupported tensor data type '" + context.dataType + "'.");
  475. }
  476. }
  477. }
  478. else {
  479. for (let j = 0; j < size; j++) {
  480. if (context.count > context.limit) {
  481. results.push('...');
  482. return results;
  483. }
  484. results.push(this._decode(context, dimension + 1));
  485. }
  486. }
  487. if (context.shape.length == 0) {
  488. return results[0];
  489. }
  490. return results;
  491. }
  492. };
  493. rknn.TensorType = class {
  494. constructor(dataType, shape) {
  495. const type = dataType.vx_type.startsWith('VSI_NN_TYPE_') ? dataType.vx_type.split('_').pop().toLowerCase() : dataType.vx_type;
  496. switch (type) {
  497. case 'uint8':
  498. case 'int8':
  499. case 'int16':
  500. case 'int32':
  501. case 'int64':
  502. case 'float16':
  503. case 'float32':
  504. case 'float64':
  505. case 'vdata':
  506. this._dataType = type;
  507. break;
  508. default:
  509. if (dataType.vx_type !== '') {
  510. throw new rknn.Error("Invalid data type '" + JSON.stringify(dataType) + "'.");
  511. }
  512. this._dataType = '?';
  513. break;
  514. }
  515. this._shape = shape;
  516. }
  517. get dataType() {
  518. return this._dataType;
  519. }
  520. get shape() {
  521. return this._shape;
  522. }
  523. toString() {
  524. return this.dataType + this._shape.toString();
  525. }
  526. };
  527. rknn.TensorShape = class {
  528. constructor(shape) {
  529. this._dimensions = shape;
  530. }
  531. get dimensions() {
  532. return this._dimensions;
  533. }
  534. toString() {
  535. if (!this._dimensions || this._dimensions.length == 0) {
  536. return '';
  537. }
  538. return '[' + this._dimensions.join(',') + ']';
  539. }
  540. };
  541. rknn.Container = class {
  542. static open(context) {
  543. const stream = context.stream;
  544. const container = new rknn.Container(stream, stream.length);
  545. return container.type ? container : null;
  546. }
  547. constructor(stream, length) {
  548. this._stream = stream;
  549. this._length = length;
  550. this._type = '';
  551. if ((stream.position + 16) <= this._length) {
  552. const signature = [ 0x52, 0x4B, 0x4E, 0x4E ]; // RKNN
  553. if (stream.peek(signature.length).every((value, index) => value === signature[index])) {
  554. this._type = 'json';
  555. }
  556. }
  557. if ((stream.position + 16) <= this._length) {
  558. const signature = [ 0x43, 0x59, 0x50, 0x54, 0x52, 0x4B, 0x4E, 0x4E ]; // RKNN
  559. if (stream.peek(signature.length).every((value, index) => value === signature[index])) {
  560. this._type = 'crypt';
  561. }
  562. }
  563. if ((stream.position + 8) <= this._length) {
  564. const signature = [ 0x52, 0x4B, 0x4E, 0x4E ]; // RKNN
  565. if (stream.peek(8).subarray(4, 8).every((value, index) => value === signature[index])) {
  566. this._type = 'flatbuffers';
  567. }
  568. }
  569. if ((stream.position + 8) <= this._length) {
  570. const signature = [ 0x56, 0x50, 0x4D, 0x4E ]; // VPMN
  571. if (stream.peek(signature.length).every((value, index) => value === signature[index])) {
  572. this._type = 'openvx';
  573. }
  574. }
  575. }
  576. get type() {
  577. return this._type;
  578. }
  579. get value() {
  580. this.read();
  581. return this._value;
  582. }
  583. get next() {
  584. this.read();
  585. return this._next;
  586. }
  587. read() {
  588. if (this._stream) {
  589. const stream = this._stream;
  590. delete this._stream;
  591. switch (this._type) {
  592. case 'crypt': {
  593. throw new rknn.Error('Invalid file content. File contains undocumented encrypted RKNN data.');
  594. }
  595. case 'json': {
  596. const uint64 = () => {
  597. const buffer = stream.read(8);
  598. const reader = new base.BinaryReader(buffer);
  599. return reader.uint64();
  600. };
  601. stream.skip(8);
  602. const version = uint64();
  603. const data_size = uint64();
  604. switch (version) {
  605. case 0x0001:
  606. case 0x1001:
  607. break;
  608. case 0x0002:
  609. if (data_size > 0) {
  610. stream.skip(40);
  611. }
  612. break;
  613. default:
  614. throw new rknn.Error("Unsupported container version '" + version + "'.");
  615. }
  616. this._next = new rknn.Container(stream, data_size);
  617. this._next.read();
  618. const value_size = uint64(stream);
  619. this._value = stream.read(value_size);
  620. break;
  621. }
  622. case 'flatbuffers': {
  623. this._value = stream.read(this._length);
  624. this._next = null;
  625. break;
  626. }
  627. case 'openvx': {
  628. this._value = stream.read(this._length);
  629. this._next = null;
  630. break;
  631. }
  632. case '': {
  633. this._value = stream.read(this._length);
  634. this._next = null;
  635. break;
  636. }
  637. default: {
  638. throw new rknn.Error("Unsupported container type '" + this._format + "'.");
  639. }
  640. }
  641. }
  642. }
  643. };
  644. var openvx = openvx || {};
  645. openvx.Model = class {
  646. constructor(buffer) {
  647. const reader = new openvx.BinaryReader(buffer);
  648. reader.skip(4); // signature
  649. const major = reader.uint16();
  650. /* const minor = */ reader.uint16();
  651. reader.skip(4);
  652. this._name = reader.string(64);
  653. this._nodes = new Array(reader.uint32());
  654. if (major > 3) {
  655. reader.skip(296);
  656. }
  657. else if (major > 1) {
  658. reader.skip(288);
  659. }
  660. else {
  661. reader.skip(32);
  662. }
  663. /* const inputOffset = */ reader.uint32();
  664. /* const inputSize = */ reader.uint32();
  665. /* const outputOffset = */ reader.uint32();
  666. /* const outputSize = */ reader.uint32();
  667. const nodeOffset = reader.uint32();
  668. /* const nodeSize = */ reader.uint32();
  669. reader.seek(nodeOffset);
  670. for (let i = 0; i < this._nodes.length; i++) {
  671. const type = reader.string(64);
  672. const node = { type: type };
  673. node.index = reader.uint32();
  674. node.c = reader.uint32();
  675. if (major > 3) {
  676. node.d = reader.uint32();
  677. }
  678. this._nodes[i] = node;
  679. }
  680. }
  681. get name() {
  682. return this._name;
  683. }
  684. get nodes() {
  685. return this._nodes;
  686. }
  687. };
  688. openvx.BinaryReader = class extends base.BinaryReader {
  689. string(length) {
  690. const buffer = this.read(length);
  691. const index = buffer.indexOf(0);
  692. const data = index === -1 ? buffer : buffer.subarray(0, index);
  693. this._decoder = this._decoder || new TextDecoder('ascii');
  694. return this._decoder.decode(data);
  695. }
  696. };
  697. rknn.Error = class extends Error {
  698. constructor(message) {
  699. super(message);
  700. this.name = 'Error loading RKNN model.';
  701. }
  702. };
  703. if (typeof module !== 'undefined' && typeof module.exports === 'object') {
  704. module.exports.ModelFactory = rknn.ModelFactory;
  705. }