Skip to content

Commit

Permalink
[EdgeTpu] Add EdgeTpuConfigSetting.ts to separate config
Browse files Browse the repository at this point in the history
This commit Add EdgeTpuConfigSetting.ts to separate ConfigObject logic of EdgeTpu Config

ONE-vscode-DCO-1.0-Signed-off-by: Seongwon Im <[email protected]>
  • Loading branch information
imsw0529 committed Sep 14, 2023
1 parent ae6025b commit fa301cb
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/OneExplorer/ConfigObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Logger } from "../Utils/Logger";

import { Artifact } from "./ArtifactLocator";
import { OneConfigSetting } from "./OneConfigSetting";
import { EdgeTpuConfigSetting } from "./EdgeTpuConfigSetting";

type Cfg = {
"one-import-tflite": CfgOneImportTflite;
Expand Down Expand Up @@ -216,6 +217,9 @@ export class ConfigObj {
const dir = path.dirname(filePath);

let locatorRunner = OneConfigSetting.getBaseModelsLocatorRunner();
if (path.extname(filePath) === ".edgetpucfg") {
locatorRunner = EdgeTpuConfigSetting.getBaseModelsLocatorRunner();
}

let artifacts: Artifact[] = locatorRunner.run(iniObj, dir);

Expand Down Expand Up @@ -254,6 +258,9 @@ export class ConfigObj {
const dir = path.dirname(filePath);

let locatorRunner = OneConfigSetting.getProductsLocatorRunner();
if (path.extname(filePath) === ".edgetpucfg") {
locatorRunner = EdgeTpuConfigSetting.getProductsLocatorRunner();
}

/**
* When you add a new product type, please append the ext type to
Expand Down
103 changes: 103 additions & 0 deletions src/OneExplorer/EdgeTpuConfigSetting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import * as vscode from "vscode";

import { Locator, LocatorRunner } from "./ArtifactLocator";

// export type OneCfg = {
// "one-import-tflite": CfgOneImportTflite;
// "one-import-onnx": CfgOneImportOnnx;
// "one-import-tf": CfgOneImportTf;
// };
// type CfgOneImportTflite = any;
// type CfgOneImportOnnx = any;
// type CfgOneImportTf = any;

export class EdgeTpuConfigSetting {
static baseModelsLocatorRunner: LocatorRunner;
static productsLocatorRunner: LocatorRunner;
// TODO: make sections for updateBaseModelField method

static getBaseModelsLocatorRunner(): LocatorRunner {
if (!this.baseModelsLocatorRunner) {
this._initBaseModelsLocatorRunner();
}
return this.baseModelsLocatorRunner;
}

static getProductsLocatorRunner(): LocatorRunner {
if (!this.productsLocatorRunner) {
this._initProductsLocatorRunner();
}
return this.productsLocatorRunner;
}

private static _initBaseModelsLocatorRunner() {
let locatorRunner = new LocatorRunner();

locatorRunner.register({
artifactAttr: {
ext: ".tflite",
icon: new vscode.ThemeIcon("symbol-variable"),
},
locator: new Locator((value: string) => {
value += "";
const filterd = value
.split(" ")
.filter((val) => !val.endsWith("_edgetpu.tflite"));
value = filterd.join(" ");
return LocatorRunner.searchWithExt(".tflite", value);
}),
});

this.baseModelsLocatorRunner = locatorRunner;
}

private static _initProductsLocatorRunner() {
let locatorRunner = new LocatorRunner();

/**
* ABOUT ORDERING
*
* The registration order determines the order in the tree view
*/

// NOTE
// Shows <model>_edgetpu.tflite
// <model>_edgetpu.tflite generated by <model>.tflite is product type
locatorRunner.register({
artifactAttr: {
ext: ".tflite",
icon: new vscode.ThemeIcon("symbol-variable"),
},
locator: new Locator((value: string) => {
value += "";
const filterd = value
.split(" ")
.filter((val) => val.endsWith("_edgetpu.tflite"));
value = filterd.join(" ");
return LocatorRunner.searchWithExt(".tflite", value);
}),
});

locatorRunner.register({
// 'default' view type is 'text editor' (vscode.openWith)
artifactAttr: {
ext: ".log",
openViewType: "default",
icon: vscode.ThemeIcon.File,
canHide: true,
},
locator: new Locator((value: string) => {
value += "";
const filterd = value
.split(" ")
.filter((val) => val.endsWith("_edgetpu.tflite"));
value = filterd.join(" ");
return LocatorRunner.searchWithExt(".tflite", value).map((filepath) =>
filepath.replace(".tflite", ".log")
);
}),
});

this.productsLocatorRunner = locatorRunner;
}
}
2 changes: 1 addition & 1 deletion src/OneExplorer/OneExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,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
4 changes: 3 additions & 1 deletion src/OneExplorer/OneStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ export class OneStorage {
try {
return roots
.map((root) =>
readdirSyncRecursive(root).filter((val) => val.endsWith(".cfg"))
readdirSyncRecursive(root).filter(
(val) => val.endsWith(".cfg") || val.endsWith(".edgetpucfg")
)
)
.reduce((prev, cur) => [...prev, ...cur]);
} catch {
Expand Down

0 comments on commit fa301cb

Please sign in to comment.