Skip to content

Commit

Permalink
minimal refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sc committed Oct 21, 2019
1 parent 36636b6 commit 24dfdb3
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 21 deletions.
11 changes: 11 additions & 0 deletions convert-model.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set OBJECT_DETECTION_PATH=C:\devsbb\projekte\tf-models\research
set PROJECT_PATH=%CD%
set CKPT_NO=16579
set ASDF=c:\my\paths
set TEST=%ASDF%
echo ">>>>>> Cleaning saved model... <<<<<<"
del /S %PROJECT_PATH%\object_detection\saved_model
echo ">>>>>> Exporting saved model... <<<<<<"
python3 %OBJECT_DETECTION_PATH%\object_detection\export_inference_graph.py --input_type=image_tensor --pipeline_config_path=%PROJECT_PATH%\object_detection\faster_rcnn_inception_v2_coco_2018_01_28\pipeline.config --trained_checkpoint_prefix=%PROJECT_PATH%\object_detection\training\model.ckpt-%CKPT_NO% --output_directory=%PROJECT_PATH%\object_detection\saved_model
echo ">>>>>> Converting saved model to tfjs... <<<<<<"
tensorflowjs_converter --input_format=tf_saved_model --output_format=tensorflowjs --saved_model_tags=serve --output_json=true --output_node_names=detection_boxes,detection_classes,detection_features,detection_multiclass_scores,detection_scores,num_detections,raw_detection_boxes,raw_detection_scores %PROJECT_PATH%\object_detection\saved_model\saved_model %PROJECT_PATH%\src\assets\web_model
35 changes: 35 additions & 0 deletions convert-model.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/bash

set -e

OBJECT_DETECTION_PATH='C:\devsbb\projekte\\tf-models\\research'
PROJECT_PATH=.
CKPT_NO=16579

ASDF=/c/my/paths
TEST=$ASDF

echo ">>>>>> Cleaning saved model... <<<<<<"

rm -rf ${PROJECT_PATH}/object_detection/saved_model

echo ">>>>>> Exporting saved model... <<<<<<"

python3 ${OBJECT_DETECTION_PATH}/object_detection/export_inference_graph.py \
--input_type=image_tensor \
--pipeline_config_path=${PROJECT_PATH}/object_detection/faster_rcnn_inception_v2_coco_2018_01_28/pipeline.config \
--trained_checkpoint_prefix=${PROJECT_PATH}/object_detection/training/model.ckpt-${CKPT_NO} \
--output_directory=${PROJECT_PATH}/object_detection/saved_model

echo ">>>>>> Converting saved model to tfjs... <<<<<<"

# tensorflowjs_converter 0.8.6:

tensorflowjs_converter \
--input_format=tf_saved_model \
--output_format=tensorflowjs\
--saved_model_tags=serve \
--output_json=true \
--output_node_names='detection_boxes,detection_classes,detection_features,detection_multiclass_scores,detection_scores,num_detections,raw_detection_boxes,raw_detection_scores' \
${PROJECT_PATH}/object_detection/saved_model/saved_model \
${PROJECT_PATH}/src/assets/web_model
3 changes: 3 additions & 0 deletions src/command-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface CommandHandler {
handle(command: any): string;
}
20 changes: 8 additions & 12 deletions src/convert-bash.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-ignore
window.process = {env: {NODE_NEV: 'mock'}}; // patch for irrelevant node dependency of bash-parser
import parse from 'bash-parser'
import {RmHandler} from './rm-handler';
import {CpHandler} from './cp-handler';

function changePath(path: string) {
return path
Expand All @@ -20,6 +22,9 @@ function performExpansions(text?: string, expansions?: any[]): string {
return result;
}

const rmHandler = new RmHandler(convertCommand);
const cpHandler = new CpHandler(convertCommand);

function convertCommand(command: any): string {
let text = performExpansions(command.text, command.expansion);
let pathMatcher = /(\/?[.\w]+(?:[.\w]+\/)*\/?|\b\.\b)/ig;
Expand All @@ -41,18 +46,9 @@ function convertCommand(command: any): string {
return `${command.name.text}${suffix}`;
}
case 'rm':
const paramMatcher = /-\w+/i;
const paramList: any[] = (command.suffix || []).filter((s: any) => s.text.match(paramMatcher));
const argList: any[] = (command.suffix || []).filter((s: any) => !s.text.match(paramMatcher));
const winParams: string[] = [];
paramList.forEach(suffix => {
if (suffix.text.indexOf('-') === 0) {
if (suffix.text.indexOf('r') >= 0) {
winParams.push('/S')
}
}
});
return `del ${winParams.join(' ')} ${argList.map(convertCommand).join(' ')}`; // converting assures paths are fixed..
return rmHandler.handle(command);
case 'cp':
return cpHandler.handle(command);

default:
return `${command.name.text}${suffix}`
Expand Down
19 changes: 19 additions & 0 deletions src/cp-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {CommandHandler} from './command-handler';
import {splitParams} from './util';

export class CpHandler implements CommandHandler {

constructor(private defaultHandler: (command: any) => string) {
}

handle(command: any): string {
const {singleDashParams, doubleDashParams, argList} = splitParams(command);
const winParams: string[] = [];
singleDashParams.forEach(suffix => {
if (suffix.text.indexOf('d') >= 0) {
winParams.push('/L')
}
});
return `copy ${winParams.join(' ')} ${argList.map(this.defaultHandler).join(' ')}`; // converting assures paths are fixed..
}
}
19 changes: 19 additions & 0 deletions src/rm-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {CommandHandler} from './command-handler';
import {splitParams} from './util';

export class RmHandler implements CommandHandler {

constructor(private defaultHandler: (command: any) => string) {
}

handle(command: any): string {
const {singleDashParams, doubleDashParams, argList} = splitParams(command);
const winParams: string[] = [];
singleDashParams.forEach(suffix => {
if (suffix.text.indexOf('r') >= 0) {
winParams.push('/S')
}
});
return `del ${winParams.join(' ')} ${argList.map(this.defaultHandler).join(' ')}`; // converting assures paths are fixed..
}
}
8 changes: 8 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function splitParams(command: any) {
const singleDashParamMatcher = /^-\w+$/i;
const doubleDashParamMatcher = /^--\w+/i;
const singleDashParams: any[] = (command.suffix || []).filter((s: any) => s.text.match(singleDashParamMatcher));
const doubleDashParams: any[] = (command.suffix || []).filter((s: any) => s.text.match(doubleDashParamMatcher));
const argList: any[] = (command.suffix || []).filter((s: any) => !s.text.match(singleDashParamMatcher) && !s.text.match(doubleDashParamMatcher));
return {singleDashParams, doubleDashParams, argList};
}
9 changes: 9 additions & 0 deletions ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
"aot": false,
"assets": [
"src/favicon.ico",
"src/android-chrome-192x192.png",
"src/android-chrome-512x512.png",
"src/apple-touch-icon.png",
"src/favicon-16x16.png",
"src/favicon-32x32.png",
"src/mstile-150x150.png",
"src/browserconfig.xml",
"src/site.webmanifest",
"src/safari-pinned-tab.svg",
"src/assets"
],
"styles": [
Expand Down
Binary file removed ui/favicon.ico
Binary file not shown.
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion ui/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h1>Bash to Bat Converter</h1>
<mat-form-field appearance="outline" floatLabel="always" class="code code-bash" color="primary">
<mat-label>Bash Script</mat-label>
<textarea [formControl]="bashScript" matInput placeholder="Enter Bash script here.." cdkTextareaAutosize
cdkAutosizeMinRows="5"></textarea>
cdkAutosizeMinRows="5" (focus)="textInput.select()" #textInput></textarea>
</mat-form-field>

<mat-form-field appearance="outline" floatLabel="always" class="code code-bat">
Expand Down
11 changes: 8 additions & 3 deletions ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ import {convertBashToWin} from '../../../src/convert-bash';
export class AppComponent implements OnInit, AfterViewInit {

code$: Observable<string>;
bashScript = new FormControl(`SOME_VAR="/c/cygwin/path"
rm -rf $SOME_VAR`);
bashScript = new FormControl(`#!/bin/bash
SOME_VAR="/c/cygwin/path"
rm -rf $SOME_VAR
cp /c/some/file /to/another/file
`);

ngOnInit(): void {

this.code$ = this.bashScript.valueChanges.pipe(
startWith(this.bashScript.value),
map(bash => {
try {
if(!bash) {
if (!bash) {
return 'REM enter bash script :)'
}
return convertBashToWin(bash);
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
Binary file modified ui/src/favicon.ico
Binary file not shown.
10 changes: 5 additions & 5 deletions ui/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<link rel="manifest" href="site.webmanifest">
<link rel="mask-icon" href="safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#a92626">
</head>
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes.

0 comments on commit 24dfdb3

Please sign in to comment.