|
|
@@ -0,0 +1,49 @@
|
|
|
+/* jshint esversion: 6 */
|
|
|
+/* eslint "indent": [ "error", 4, { "SwitchCase": 1 } ] */
|
|
|
+
|
|
|
+// Experimental
|
|
|
+
|
|
|
+var tensorrt = tensorrt || {};
|
|
|
+
|
|
|
+tensorrt.ModelFactory = class {
|
|
|
+
|
|
|
+ match(context) {
|
|
|
+ const identifier = context.identifier;
|
|
|
+ const extension = identifier.split('.').pop().toLowerCase();
|
|
|
+ if (extension === 'uff' || extension === 'pb') {
|
|
|
+ const tags = context.tags('pb');
|
|
|
+ if (tags.size > 0 &&
|
|
|
+ tags.has(1) && tags.get(1) === 0 &&
|
|
|
+ tags.has(2) && tags.get(2) === 0 &&
|
|
|
+ tags.has(3) && tags.get(3) === 2 &&
|
|
|
+ tags.has(4) && tags.get(4) === 2 &&
|
|
|
+ tags.has(5) && tags.get(5) === 2) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (extension === 'pbtxt') {
|
|
|
+ const tags = context.tags('pbtxt');
|
|
|
+ if (tags.has('version') && tags.has('descriptors') && tags.has('graphs')) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ open(context /*, host */) {
|
|
|
+ const identifier = context.identifier;
|
|
|
+ throw new tensorrt.Error("TensorRT UFF is a proprietary file format in '" + identifier + "'.");
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+tensorrt.Error = class extends Error {
|
|
|
+
|
|
|
+ constructor(message) {
|
|
|
+ super(message);
|
|
|
+ this.name = 'Error loading TensorRT model.';
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+if (typeof module !== 'undefined' && typeof module.exports === 'object') {
|
|
|
+ module.exports.ModelFactory = tensorrt.ModelFactory;
|
|
|
+}
|