Skip to content

Commit

Permalink
[EdgeTpu] Implements Explorer (#1737)
Browse files Browse the repository at this point in the history
* [EdgeTpu] Implement Explorer

This commit Implements Explorer for EdgeTpu Backend

- Implements Explorer for EdgeTpu Backend
- Add Explorer Test code for EdgeTPU Backend

ONE-vscode-DCO-1.0-Signed-off-by: SeungHyunH <[email protected]>
Co-authored-by: Seongwon Im <[email protected]>

* Merge with main branch

ONE-vscode-DCO-1.0-Signed-off-by: Dayoung Lee <[email protected]>

* Fix

ONE-vscode-DCO-1.0-Signed-off-by: Dayoung Lee <[email protected]>

---------

Co-authored-by: SeungHyunH <[email protected]>
Co-authored-by: Seongwon Im <[email protected]>
  • Loading branch information
3 people authored Nov 3, 2023
1 parent 8998348 commit 9bfed0e
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 11 deletions.
42 changes: 36 additions & 6 deletions src/OneExplorer/OneExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,17 @@ class NodeFactory {
undefined,
"Config nodes cannot have attributes"
);
node = new ConfigNode(uri, parent);
const ext = path.extname(fpath);
switch (ext) {
case ".edgetpucfg": {
node = new ConfigNode(uri, parent, "one.editor.edgetpucfg");
break;
}
case ".cfg":
default: {
node = new ConfigNode(uri, parent);
}
}
break;
}
case NodeType.product: {
Expand Down Expand Up @@ -252,6 +262,26 @@ class DirectoryNode extends Node {
super(uri, parent);
}

private isOneBaseModel(fname: string): boolean {
return (
fname.endsWith(".pb") ||
fname.endsWith(".tflite") ||
fname.endsWith(".onnx")
);
}

private isEdgetpuBaseModel(fname: string): boolean {
return fname.endsWith(".tflite")
? !fname.endsWith("_edgetpu.tflite")
: true;
}

/*
Check if the file is a basemodel.
*/
private isBaseModel(fname: string): boolean {
return this.isOneBaseModel(fname) && this.isEdgetpuBaseModel(fname);
}
/**
* Build a sub-tree under the node
*
Expand All @@ -271,11 +301,10 @@ class DirectoryNode extends Node {

if (fstat.isDirectory()) {
const dirNode = NodeFactory.create(NodeType.directory, fpath, this);

if (dirNode && dirNode.getChildren().length > 0) {
this._childNodes!.push(dirNode);
}
} else if (fstat.isFile()) {
} else if (fstat.isFile() && this.isBaseModel(fname)) {
if (fname.endsWith(".pb")) {
const baseModelNode = NodeFactory.create(
NodeType.baseModel,
Expand Down Expand Up @@ -359,15 +388,14 @@ class BaseModelNode extends Node {
*/
_buildChildren = (): void => {
this._childNodes = [];

const configPaths = OneStorage.getCfgs(this.path);

if (!configPaths) {
return;
}

configPaths.forEach((configPath) => {
const configNode = NodeFactory.create(NodeType.config, configPath, this);

if (configNode) {
this._childNodes!.push(configNode);
}
Expand All @@ -378,7 +406,7 @@ class BaseModelNode extends Node {
class ConfigNode extends Node {
readonly type = NodeType.config;

static readonly extList = [".cfg"];
static readonly extList = [".cfg", ".edgetpucfg"];
// Open file with one.editor.cfg as default
static defaultOpenViewType = "one.editor.cfg";
// Display gear icon as default
Expand Down Expand Up @@ -451,6 +479,8 @@ class ProductNode extends Node {
".tv2o",
".json",
".circle.log",
"_edgetpu.tflite",
"_edgetpu.log",
];
// Do not open file as default
static defaultOpenViewType = undefined;
Expand Down
6 changes: 5 additions & 1 deletion src/OneExplorer/OneStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,13 @@ export class OneStorage {
};

try {
const extList = [".cfg", ".edgetpucfg"];

return roots
.map((root) =>
readdirSyncRecursive(root).filter((val) => val.endsWith(".cfg"))
readdirSyncRecursive(root).filter((val) =>
extList.some((ext) => val.endsWith(ext))
)
)
.reduce((prev, cur) => [...prev, ...cur]);
} catch {
Expand Down
23 changes: 23 additions & 0 deletions src/Tests/OneExplorer/OneExplorer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,29 @@ suite("OneExplorer", function () {
}
});

test("create a config node with edgetpucfg", function () {
const configName = "test.edgetpucfg";

// Write a file inside temp directory
testBuilder.writeFileSync(configName, "");

// Get file paths inside the temp directory
const configPath = testBuilder.getPath(configName);

// Validation
{
const configNode = NodeFactory.create(
NodeType.config,
configPath,
undefined
);
assert.strictEqual(configNode.openViewType, "one.editor.edgetpucfg");
assert.strictEqual(configNode.icon, ConfigNode.defaultIcon);
assert.strictEqual(configNode.canHide, ConfigNode.defaultCanHide);
assert.strictEqual(configNode.getChildren().length, 0);
}
});

test("NEG: create a product node with not existing path", function () {
assert.throw(() => {
NodeFactory.create(NodeType.product, "path/not/exist", undefined);
Expand Down
Loading

0 comments on commit 9bfed0e

Please sign in to comment.