-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tool classification cmake #19
Merged
+158
−51
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e0a00c3
REFACTOR: changed the format of label map and renamed it
sushidelivery 63c4338
ADD: added classifier cmake for labels
sushidelivery 44e8f26
ADD: added python script to load the labels to config
sushidelivery 853ae49
ADD: added classifier label file path
sushidelivery b17c5e9
REMOVE: removed the label map file
sushidelivery 419c99d
REFACTOR: updated the label
sushidelivery 2270968
ADD: added the success log
sushidelivery 4fc12ca
FIX: fixed the indentation
sushidelivery d546ef3
FIX: fixed the config file indentation
sushidelivery 1e42b7e
FIX: fixed the label
sushidelivery 63819f0
FIX: fixed the indentation for labels
sushidelivery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
auger_drill_bit_34_235 | ||
chain_swordsaw_blade_200 | ||
spade_drill_bit_25_150 | ||
brad_point_drill_bit_20_150 | ||
chain_saw_blade_f_250 | ||
self_feeding_bit_40_90 | ||
circular_saw_blade_makita_190 | ||
self_feeding_bit_50_90 | ||
twist_drill_bit_32_165 | ||
saber_saw_blade_makita_t_300 | ||
auger_drill_bit_20_235 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
if(UNIX AND NOT APPLE) | ||
set(LOADER_CMD "${PROJECT_SOURCE_DIR}/util/load_labels_2_config.py") | ||
execute_process( | ||
COMMAND chmod +x ${LOADER_CMD} | ||
COMMAND ${LOADER_CMD} -s ${CMAKE_CURRENT_SOURCE_DIR} -c ${__TTOOL_CONFIG_PATH__} | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import sys | ||
import argparse | ||
|
||
|
||
def _log_process(msg): | ||
print("[PROCESS:util/load_dataset_2_config.py] {}".format(msg)) | ||
def _log_info(msg): | ||
print("\033[95m[INFO:util/load_dataset_2_config.py] {}\033[00m".format(msg)) | ||
def _log_error(msg): | ||
print("\033[91m[ERROR:util/load_dataset_2_config.py] {}\033[00m".format(msg)) | ||
def _log_warning(msg): | ||
print("\033[93m[WARNING:util/load_dataset_2_config.py] {}\033[00m".format(msg)) | ||
def _log_success(msg): | ||
print("\033[92m[SUCCESS:util/load_dataset_2_config.py] {}\033[00m".format(msg)) | ||
|
||
|
||
def main(source_path: str, config_path: str) -> None: | ||
_log_process("Loading the labels file...") | ||
|
||
try: | ||
classifier_labels_path_key: str = 'classifierLabelsPath:' | ||
classifier_labels: str = 'classifierLabels:' | ||
with open(config_path, "r") as f: | ||
config_lines = f.readlines() | ||
|
||
labels_path = None | ||
for line in config_lines: | ||
if classifier_labels_path_key in line: | ||
_, labels_path = line.split(':', 1) | ||
labels_path = labels_path.strip().strip('\"') | ||
break | ||
|
||
if not labels_path: | ||
raise ValueError(f"{classifier_labels_path_key} not found in the configuration file") | ||
|
||
with open(os.path.join(source_path, labels_path), "r") as f: | ||
labels = [line.strip() for line in f if line.strip()] | ||
|
||
start_idx = -1 | ||
end_idx = -1 | ||
for i, line in enumerate(config_lines): | ||
if line.strip() == classifier_labels: | ||
start_idx = i | ||
end_idx = start_idx + 1 | ||
while end_idx < len(config_lines) and config_lines[end_idx].strip().startswith('-'): | ||
end_idx += 1 | ||
break | ||
|
||
new_labels_section = [f'{classifier_labels}\n'] + \ | ||
[f" - \"{label}\"\n" for label in labels] | ||
|
||
if start_idx != -1: | ||
config_lines = config_lines[:start_idx] + new_labels_section + config_lines[end_idx:] | ||
else: | ||
config_lines.extend(['\n'] + new_labels_section) | ||
|
||
with open(config_path, "w") as f: | ||
f.writelines(config_lines) | ||
|
||
_log_success("The labels were successfully loaded into the assets/config.yml file.") | ||
|
||
except FileNotFoundError as e:( | ||
_log_error(f"Error: File not found - {e}")) | ||
except ValueError as e:( | ||
_log_error(f"Error: {e}")) | ||
except Exception as e:( | ||
_log_error(f"An unexpected error occurred: {e}")) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Load the labels into the TTool config.yml file.") | ||
parser.add_argument("-s", "--source", help="Path to the project source directory.") | ||
parser.add_argument("-c", "--config", help="Path to the TTool config.yml file.") | ||
|
||
args = parser.parse_args() | ||
|
||
if not os.path.isdir(args.source): | ||
_log_error("The path to the project source directory is not valid.") | ||
sys.exit() | ||
if not os.path.isfile(args.config): | ||
_log_error("The path to the config file is not valid.") | ||
sys.exit() | ||
|
||
main(source_path=args.source, config_path=args.config) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it would be worth to catch the error if
ai/torchscripts/labels.txt
exists since it is a manually-added file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey ! I am catching the error in the except. So if the file does not exist or the path is wrong, it will be caught! Please, have a look. I also added the success log in 2270968.