Skip to content

Commit

Permalink
0.1.0 - Minor (#50)
Browse files Browse the repository at this point in the history
* 🔨 Reconfigured Register Topic GUI feature to read from .json file in config folder instead of .launch.py file directly.

Signed-off-by: Bey Hao Yun <[email protected]>

* 🔨 Reconfigured GUI to parse and write .json files instead of .txt files.

Signed-off-by: Bey Hao Yun <[email protected]>

* 🔨 Reconfigured session_config and usecase_config from parsing txt to json instead.

Signed-off-by: Bey Hao Yun <[email protected]>

* 🔨 Fix for build error.

Signed-off-by: Bey Hao Yun <[email protected]>

* 🔨 Fix for intrinsic warnings concerning Json::ArrayIndex.

Signed-off-by: Bey Hao Yun <[email protected]>

* 🔨 Reconfigured session_config and useconfig parser from CPP and Python codebase. Verified with unit testing.

Signed-off-by: Bey Hao Yun <[email protected]>

* 🔨 Renabled unit testing to rectify failing CI build.

Signed-off-by: Bey Hao Yun <[email protected]>

* 📖 Updated CHANGELOG.rst in easy_perception_deployment to reflect changes toward v0.1.0.

Signed-off-by: Bey Hao Yun <[email protected]>
  • Loading branch information
cardboardcode authored Aug 1, 2022
1 parent fbb38cd commit 9cc689e
Show file tree
Hide file tree
Showing 30 changed files with 937 additions and 436 deletions.
7 changes: 7 additions & 0 deletions easy_perception_deployment/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ Changelog for package easy_perception_deployment
* Included CHANGELOG.rst in easy_perception_deployment ROS2 package.
* Introduced hotfix for faulty Input Image Topic for Register Topic GUI feature.
* Contributor(s): Bey Hao Yun

0.1.0 (2022-07-31)
-------------------
* Reconfigured Register Topic GUI feature to read from .json file in config folder instead of .launch.py file directly.
* Revamped session_config and use_config parser. easy_perception_deployment now reads config/usecase_config.json as well as config/session_config.json for more robust session configuration.
* Contributor(s): Bey Hao Yun

36 changes: 21 additions & 15 deletions easy_perception_deployment/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ set(onnxruntime_INCLUDE_DIRS
)
find_library(onnxruntime_LIBS NAMES onnxruntime PATHS /usr/local/lib)

# Json CPP libraries
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONCPP jsoncpp)
link_libraries(${JSONCPP_LIBRARIES})

# Include external ROS packages.
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
Expand Down Expand Up @@ -103,59 +108,59 @@ if(BUILD_TESTING)

ament_add_gtest(epd_test_init test/test_init.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_init OpenCV cv_bridge)
target_link_libraries(epd_test_init ${onnxruntime_LIBS})
target_link_libraries(epd_test_init ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_invalid_usecase test/test_invalid_usecase.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_invalid_usecase OpenCV cv_bridge)
target_link_libraries(epd_test_invalid_usecase ${onnxruntime_LIBS})
target_link_libraries(epd_test_invalid_usecase ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P1_classification_action test/p1u0a.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P1_classification_action OpenCV cv_bridge)
target_link_libraries(epd_test_P1_classification_action ${onnxruntime_LIBS})
target_link_libraries(epd_test_P1_classification_action ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P2_counting_action test/p2u1a.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P2_counting_action OpenCV cv_bridge)
target_link_libraries(epd_test_P2_counting_action ${onnxruntime_LIBS})
target_link_libraries(epd_test_P2_counting_action ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P2_counting_visualize test/p2u1v.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P2_counting_visualize OpenCV cv_bridge)
target_link_libraries(epd_test_P2_counting_visualize ${onnxruntime_LIBS})
target_link_libraries(epd_test_P2_counting_visualize ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P2_colormatch_action test/p2u2a.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P2_colormatch_action OpenCV cv_bridge)
target_link_libraries(epd_test_P2_colormatch_action ${onnxruntime_LIBS})
target_link_libraries(epd_test_P2_colormatch_action ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P3_counting_visualize test/p3u1v.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P3_counting_visualize OpenCV cv_bridge)
target_link_libraries(epd_test_P3_counting_visualize ${onnxruntime_LIBS})
target_link_libraries(epd_test_P3_counting_visualize ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P3_colormatch_visualize test/p3u2v.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P3_colormatch_visualize OpenCV cv_bridge)
target_link_libraries(epd_test_P3_colormatch_visualize ${onnxruntime_LIBS})
target_link_libraries(epd_test_P3_colormatch_visualize ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P3_colormatch_action test/p3u2a.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P3_colormatch_action OpenCV cv_bridge)
target_link_libraries(epd_test_P3_colormatch_action ${onnxruntime_LIBS})
target_link_libraries(epd_test_P3_colormatch_action ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P3_localize_action test/p3u3a.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P3_localize_action OpenCV cv_bridge)
target_link_libraries(epd_test_P3_localize_action ${onnxruntime_LIBS})
target_link_libraries(epd_test_P3_localize_action ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P3_localize_visualize test/p3u3v.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P3_localize_visualize OpenCV cv_bridge)
target_link_libraries(epd_test_P3_localize_visualize ${onnxruntime_LIBS})
target_link_libraries(epd_test_P3_localize_visualize ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P3_tracking_visualize test/p3u4v.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P3_tracking_visualize OpenCV cv_bridge)
target_link_libraries(epd_test_P3_tracking_visualize ${onnxruntime_LIBS})
target_link_libraries(epd_test_P3_tracking_visualize ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_P3_tracking_action test/p3u4a.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_P3_tracking_action OpenCV cv_bridge)
target_link_libraries(epd_test_P3_tracking_action ${onnxruntime_LIBS})
target_link_libraries(epd_test_P3_tracking_action ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

ament_add_gtest(epd_test_easy_perception_deployment test/test_easy_perception_deployment.cpp ${EPD_UTILS})
ament_target_dependencies(epd_test_easy_perception_deployment rclcpp std_msgs sensor_msgs epd_msgs OpenCV cv_bridge message_filters pcl_conversions)
target_link_libraries(epd_test_easy_perception_deployment ${onnxruntime_LIBS})
target_link_libraries(epd_test_easy_perception_deployment ${onnxruntime_LIBS} ${JSONCPP_LIBRARIES})

endif()

Expand All @@ -172,7 +177,7 @@ ament_target_dependencies(
message_filters
pcl_conversions
)
target_link_libraries(easy_perception_deployment ${onnxruntime_LIBS} ${PCL_LIBRARIES})
target_link_libraries(easy_perception_deployment ${onnxruntime_LIBS} ${PCL_LIBRARIES} ${JSONCPP_LIBRARIES})


install(TARGETS
Expand All @@ -182,6 +187,7 @@ install(TARGETS

install(DIRECTORY
launch
config
DESTINATION share/${PROJECT_NAME}/
)

Expand Down
3 changes: 3 additions & 0 deletions easy_perception_deployment/config/input_image_topic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"input_image_topic": "/camera/color/image_raw"
}
6 changes: 6 additions & 0 deletions easy_perception_deployment/config/session_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"path_to_label_list" : "/home/cardboardvoice/epd_workspace/5_linting_epd_ws/src/easy_perception_deployment/easy_perception_deployment/data/label_list/imagenet_classes.txt",
"path_to_model" : "/home/cardboardvoice/epd_workspace/5_linting_epd_ws/src/easy_perception_deployment/easy_perception_deployment/data/model/squeezenet1.1-7.onnx",
"useCPU" : "CPU",
"visualizeFlag" : "robot"
}
3 changes: 3 additions & 0 deletions easy_perception_deployment/config/usecase_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"usecase_mode" : 0
}
155 changes: 78 additions & 77 deletions easy_perception_deployment/gui/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

import os
import json
import subprocess

from trainer.P1Trainer import P1Trainer
Expand All @@ -28,13 +29,28 @@
from datetime import date
from PySide2 import QtCore

# Clear all stored session_config.txt usecase_config.txt
if os.path.exists('../data/session_config.txt') and os.path.exists('../data/session_config.txt'):
p1 = subprocess.Popen(['rm', '../data/session_config.txt'])
# Clear all stored session_config.json usecase_config.txt
if os.path.exists('../config/session_config.json') and os.path.exists('../config/usecase_config.json'):
p1 = subprocess.Popen(['rm', '../config/session_config.json'])
p1.communicate()
p2 = subprocess.Popen(['rm', '../data/usecase_config.txt'])
p2 = subprocess.Popen(['rm', '../config/usecase_config.json'])
p2.communicate()

dict = {
"path_to_model": './data/model/squeezenet1.1-7.onnx',
"path_to_label_list": './data/label_list/imagenet_classes.txt',
"visualizeFlag": 'visualize',
"useCPU": 'CPU'
}
json_object = json.dumps(dict, indent=4)
with open('../config/session_config.json', 'w') as outfile:
outfile.write(json_object)

dict = {"usecase_mode": 0}
json_object = json.dumps(dict, indent=4)
with open('../config/usecase_config.json', 'w') as outfile:
outfile.write(json_object)


def test_init_MainWindow(qtbot):

Expand Down Expand Up @@ -92,69 +108,70 @@ def test_closeAll_MainWindow(qtbot):

def test_emptySession_emptyUseCase_DeployWindow(qtbot):

widget = DeployWindow()
qtbot.addWidget(widget)

if (os.path.exists('../data/session_config.txt') and
os.path.exists('../data/session_config.txt')):
p1 = subprocess.Popen(['rm', '../data/session_config.txt'])
if (os.path.exists('../config/session_config.json') and
os.path.exists('../config/usecase_config.json')):
p1 = subprocess.Popen(['rm', '../config/session_config.json'])
p1.communicate()
p2 = subprocess.Popen(['rm', '../data/usecase_config.txt'])
p2 = subprocess.Popen(['rm', '../config/usecase_config.json'])
p2.communicate()

widget = DeployWindow()
qtbot.addWidget(widget)

assert widget._path_to_model == 'filepath/to/onnx/model'
assert widget._path_to_label_list == 'filepath/to/classes/list/txt'
assert widget.usecase_mode == 0


def test_invalidSession_invalidUseCase_DeployWindow(qtbot):

test_session_config_content = ['test_filepath_to_model\n',
'test_filepath_to_label_list\n',
'visualize\n']
# If session_config.txt is not present, create one.
outF = open('../data/session_config.txt', 'w+')
for line in test_session_config_content:
outF.write(line)
outF.close()

test_usecase_config_content = ['-1\n']
outF = open('../data/usecase_config.txt', 'w+')
for line in test_usecase_config_content:
outF.write(line)
outF.close()
dict = {
"path_to_model": 'test_filepath_to_model',
"path_to_label_list": 'test_filepath_to_label_list',
"visualizeFlag": 'visualize',
"throwCPU": 'CPU'
}
json_object = json.dumps(dict, indent=4)
with open('../config/session_config.json', 'w') as outfile:
outfile.write(json_object)

dict = {"usecase_mode": -1}
json_object = json.dumps(dict, indent=4)
with open('../config/usecase_config.json', 'w') as outfile:
outfile.write(json_object)

widget = DeployWindow()
qtbot.addWidget(widget)

assert widget._path_to_model == 'filepath/to/onnx/model'
assert widget._path_to_label_list == 'filepath/to/classes/list/txt'
assert widget.usecase_mode == '-1'
assert widget.usecase_mode == 0


def test_validSession_validUseCase_DeployWindow(qtbot):

test_session_config_content = ['./data/model/squeezenet1.1-7.onnx\n',
'/data/label_list/imagenet_classes.txt\n',
'visualize\n',
'CPU\n']
outF = open('../data/session_config.txt', 'w+')
for line in test_session_config_content:
outF.write(line)
outF.close()

test_usecase_config_content = ['0\n']
outF = open('../data/usecase_config.txt', 'w+')
for line in test_usecase_config_content:
outF.write(line)
outF.close()
dict = {
"path_to_model": './data/model/squeezenet1.1-7.onnx',
"path_to_label_list": './data/label_list/imagenet_classes.txt',
"visualizeFlag": 'visualize',
"useCPU": 'CPU'
}
json_object = json.dumps(dict, indent=4)
with open('../config/session_config.json', 'w') as outfile:
outfile.write(json_object)

dict = {"usecase_mode": 0}
json_object = json.dumps(dict, indent=4)
with open('../config/usecase_config.json', 'w') as outfile:
outfile.write(json_object)


widget = DeployWindow()
qtbot.addWidget(widget)

assert widget._path_to_model == './data/model/squeezenet1.1-7.onnx'
assert widget._path_to_label_list == './data/label_list/imagenet_classes.txt'
assert widget.usecase_mode == '0'
assert widget.usecase_mode == 0


def test_deployPackage_DeployWindow(qtbot):
Expand Down Expand Up @@ -202,35 +219,16 @@ def test_setUseCase_DeployWindow(qtbot):
color_matching_index = i

widget.setUseCase(classification_index)

usecase_config_lines = [line.rstrip('\n') for
line in open('../data/usecase_config.txt')]
assert len(usecase_config_lines) == 1
f = open('../config/usecase_config.json')
data = json.load(f)
usecase_mode = data['usecase_mode']
assert usecase_mode == 0

widget.setUseCase(color_matching_index)
usecase_config_lines = [line.rstrip('\n') for
line in open('../data/usecase_config.txt')]
assert len(usecase_config_lines) == 2


def test_setModel_DeployWindow(qtbot):

widget = DeployWindow(True)
qtbot.addWidget(widget)

qtbot.mouseClick(widget.model_button, QtCore.Qt.LeftButton)

assert widget._path_to_model == 'dummy_model_filepath'


def test_setLabelList_DeployWindow(qtbot):

widget = DeployWindow(True)
qtbot.addWidget(widget)

qtbot.mouseClick(widget.list_button, QtCore.Qt.LeftButton)

assert widget._path_to_label_list == 'dummy_label_list_filepath'
f = open('../config/usecase_config.json')
data = json.load(f)
usecase_mode = data['usecase_mode']
assert usecase_mode == 2


def test_setP1_TrainWindow(qtbot):
Expand Down Expand Up @@ -439,7 +437,7 @@ def test_closeWindow_CountingWindow(qtbot):
def test_writeToUseCaseConfig_CountingWindow(qtbot):

path_to_labellist = '../data/label_list/coco_classes.txt'
path_to_usecase_config = '../data/usecase_config.txt'
path_to_usecase_config = '../config/usecase_config.json'
widget = CountingWindow(path_to_labellist, path_to_usecase_config)
qtbot.addWidget(widget)

Expand All @@ -448,18 +446,21 @@ def test_writeToUseCaseConfig_CountingWindow(qtbot):
widget._select_list = ['person']
qtbot.mouseClick(widget.finish_button, QtCore.Qt.LeftButton)

select_list = [line.rstrip('\n') for
line in open('../data/usecase_config.txt')]
assert select_list[0] == '1'
assert select_list[1] == 'person'
assert widget.isVisible() is False
f = open(path_to_usecase_config)
data = json.load(f)
usecase_mode = data['usecase_mode']
class_list = data['class_list']

assert usecase_mode == 1
assert class_list[0] == 'person'
assert widget.isVisible() is True


def test_addObject_CountingWindow():

path_to_labellist = '../data/label_list/coco_classes.txt'
path_to_usecase_config = '../data/usecase_config.txt'
widget = CountingWindow(path_to_labellist, path_to_usecase_config)
path_to_label_list = './data/label_list/coco_classes.txt'
path_to_usecase_config = './data/usecase_config.txt'
widget = CountingWindow(path_to_label_list, path_to_usecase_config)

widget.addObject(0)
assert len(widget._select_list) == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MODEL:
POOLER_SAMPLING_RATIO: 2
FEATURE_EXTRACTOR: "FPN2MLPFeatureExtractor"
PREDICTOR: "FPNPredictor"
NUM_CLASSES: 4 #Change to your number of objects +2
NUM_CLASSES: 83 #Change to your number of objects +2
DATASETS:
TEST: ("coco_custom_val",)
TRAIN: ("coco_custom_train",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MODEL:
POOLER_SAMPLING_RATIO: 2
FEATURE_EXTRACTOR: "FPN2MLPFeatureExtractor"
PREDICTOR: "FPNPredictor"
NUM_CLASSES: 81 #Change to your number of objects +2
NUM_CLASSES: 83 #Change to your number of objects +2
DATASETS:
TEST: ("coco_custom_val",)
TRAIN: ("coco_custom_train",)
Expand Down
Loading

0 comments on commit 9cc689e

Please sign in to comment.