From 174e7d9cccbe01944b30160fbfbbd6a84ffc2587 Mon Sep 17 00:00:00 2001 From: Kentaro Iizuka Date: Wed, 12 Feb 2020 13:39:18 +0900 Subject: [PATCH 1/5] Remove utils in output_template --- .../python/lmnet/utils/__init__.py | 15 -- output_template/python/lmnet/utils/box.py | 1 - output_template/python/lmnet/utils/config.py | 83 --------- output_template/python/lmnet/utils/demo.py | 162 ------------------ output_template/python/lmnet/utils/image.py | 1 - output_template/python/lmnet/utils/output.py | 1 - 6 files changed, 263 deletions(-) delete mode 100644 output_template/python/lmnet/utils/__init__.py delete mode 120000 output_template/python/lmnet/utils/box.py delete mode 100644 output_template/python/lmnet/utils/config.py delete mode 100644 output_template/python/lmnet/utils/demo.py delete mode 120000 output_template/python/lmnet/utils/image.py delete mode 120000 output_template/python/lmnet/utils/output.py diff --git a/output_template/python/lmnet/utils/__init__.py b/output_template/python/lmnet/utils/__init__.py deleted file mode 100644 index 4a9993469..000000000 --- a/output_template/python/lmnet/utils/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 The Blueoil Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================= diff --git a/output_template/python/lmnet/utils/box.py b/output_template/python/lmnet/utils/box.py deleted file mode 120000 index eae833767..000000000 --- a/output_template/python/lmnet/utils/box.py +++ /dev/null @@ -1 +0,0 @@ -../../../../lmnet/lmnet/utils/box.py \ No newline at end of file diff --git a/output_template/python/lmnet/utils/config.py b/output_template/python/lmnet/utils/config.py deleted file mode 100644 index 2307108a7..000000000 --- a/output_template/python/lmnet/utils/config.py +++ /dev/null @@ -1,83 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 The Blueoil Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================= -from __future__ import absolute_import, division, print_function, unicode_literals - -import imp - -import yaml -from easydict import EasyDict - -from lmnet.data_processor import Sequence - - -# derived from LeapMind/lmnet/lmnet/utils/config.py -def load_yaml(config_file): - with open(config_file) as config_file_stream: - config = yaml.load(config_file_stream, Loader=yaml.Loader) - - # use only upper key. - keys = [key for key in config.keys() if key.isupper()] - config_dict = {key: config[key] for key in keys} - config = EasyDict(config_dict) - return config - - -def build_pre_process(pre_processor_config): - module_name = "lmnet/pre_processor" - f, pathname, description = imp.find_module(module_name) - module = imp.load_module(module_name, f, pathname, description) - processors = [] - if pre_processor_config is None: - pre_processor_config = {} - for p in pre_processor_config: - for class_name in p: - class_args = p[class_name] - if class_args is None: - class_args = {} - cls = getattr(module, class_name) - # Create none initialized processor `cls` instance. - processor = cls.__new__(cls) - # Fill processor instance member. - for k in class_args: - v = class_args[k] - processor.__dict__[k] = v - processors.append(processor) - seq = Sequence(processors=processors) - return seq - - -def build_post_process(post_processor_config): - module_name = "lmnet/post_processor" - f, pathname, description = imp.find_module(module_name) - module = imp.load_module(module_name, f, pathname, description) - processors = [] - if post_processor_config is None: - post_processor_config = {} - for p in post_processor_config: - for class_name in p: - class_args = p[class_name] - if class_args is None: - class_args = {} - cls = getattr(module, class_name) - # Create none initialized processor `cls` instance. - processor = cls.__new__(cls) - # Fill processor instance member. - for k in class_args: - v = class_args[k] - processor.__dict__[k] = v - processors.append(processor) - seq = Sequence(processors=processors) - return seq diff --git a/output_template/python/lmnet/utils/demo.py b/output_template/python/lmnet/utils/demo.py deleted file mode 100644 index f4cc3cbf1..000000000 --- a/output_template/python/lmnet/utils/demo.py +++ /dev/null @@ -1,162 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 The Blueoil Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================= -from __future__ import absolute_import, division, print_function, unicode_literals - -import time -from itertools import product as itr_prod -from threading import Thread - -import cv2 -import numpy as np - -# HACK: cross py2-py3 compatible version -try: - from queue import Queue -except ImportError: - from Queue import Queue - - - -COLORS = [tuple(p) for p in itr_prod([0, 180, 255], repeat=3)] -COLORS = COLORS[1:] - - -def ltwh_to__tblr(ltwh): - l, t, w, h = ltwh.tolist() - b = int(t + h) - r = int(l + w) - return t, b, l, r - - -def add_fps(orig, fps): - f_p_s_text = "FPS: {:.1f}".format(fps) - text_color = (255, 144, 30) - orig_h, orig_w = orig.shape[:2] - cv2.putText(orig, f_p_s_text, (10, orig_h - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color, 1) - return orig - - -def check_range(upper, lower, checked_val): - if upper < checked_val: - checked_val = upper - elif lower > checked_val: - checked_val = lower - return checked_val - - -def add_rectangle(classes, orig, preds, pred_shape): - orig_h, orig_w = orig.shape[:2] - locs = [pred[:, 0:4] for pred in preds] - labels_n = np.array([pred[:, 4] for pred in preds]).astype(np.int) # TODO magic-number - labels_n = labels_n.flatten() - - labels = [classes[i_label] for i_label in labels_n] - scores = preds[0][:, 5] - - pred_h, pred_w = pred_shape - w_scale = orig_w / pred_w - h_scale = orig_h / pred_h - locs = (np.array(locs).reshape((-1, 4)) * [w_scale, h_scale, w_scale, h_scale]).astype(int) - for idx, loc in enumerate(locs): - t, b, le, r = ltwh_to__tblr(loc) - - le = check_range(orig_w, 0, le) - r = check_range(orig_w, 0, r) - t = check_range(orig_h, 0, t) - b = check_range(orig_h, 0, b) - - color_r = COLORS[labels_n[idx] % len(COLORS)] - thick = 2 - label_text = "{} : {:.1f}%".format(labels[idx], scores[idx] * 100) - label_size, baseline = cv2.getTextSize(label_text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1) - cv2.rectangle(orig, (le, t), (r, b), color_r, thick) - - max_color = max(color_r) - text_color = (255, 255, 255) if max_color < 255 else (0, 0, 0) - - cv2_filed_config = cv2.cv.CV_FILLED if hasattr(cv2, 'cv') else cv2.FILLED - - cv2.rectangle(orig, (le, t), (le + label_size[0], t + label_size[1]), color_r, cv2_filed_config) - cv2.putText(orig, label_text, (le, t + label_size[1]), cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color) - - return orig - - -class VideoStream: - def __init__(self, video_source, video_width, video_height, video_fps, queue_size=1): - self.video_fps = video_fps - - vc = cv2.VideoCapture(video_source) - - if hasattr(cv2, 'cv'): - vc.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, video_width) - vc.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, video_height) - vc.set(cv2.cv.CV_CAP_PROP_FPS, video_fps) - else: - vc.set(cv2.CAP_PROP_FRAME_WIDTH, video_width) - vc.set(cv2.CAP_PROP_FRAME_HEIGHT, video_height) - vc.set(cv2.CAP_PROP_FPS, video_fps) - - self.stream = vc - self.stopped = False - self.queue = Queue(maxsize=queue_size) - self.thread = Thread(target=self.update, args=()) - self.thread.daemon = True - self.thread.start() - - def update(self): - while True: - if self.stopped: - break - - (flg, frame) = self.stream.read() - if not flg: - Exception("Video capture is wrong") - frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) - - if self.queue.full(): - time.sleep(1/float(self.video_fps)) - else: - if not self.queue.empty(): - self.queue.get() - self.queue.put(frame) - else: - self.queue.put(frame) - - self.stream.release() - - def read(self): - return self.queue.get() - - def release(self): - self.stopped = True - self.thread.join() - - -def run_inference(image, nn, pre_process, post_process): - start = time.clock() - - data = pre_process(image=image)["image"] - data = np.expand_dims(data, axis=0) - - network_only_start = time.clock() - result = nn.run(data) - fps_only_network = 1.0/(time.clock() - network_only_start) - - output = post_process(outputs=result)['outputs'] - - fps = 1.0/(time.clock() - start) - return output, fps, fps_only_network diff --git a/output_template/python/lmnet/utils/image.py b/output_template/python/lmnet/utils/image.py deleted file mode 120000 index 4cc8d9fb7..000000000 --- a/output_template/python/lmnet/utils/image.py +++ /dev/null @@ -1 +0,0 @@ -../../../../lmnet/lmnet/utils/image.py \ No newline at end of file diff --git a/output_template/python/lmnet/utils/output.py b/output_template/python/lmnet/utils/output.py deleted file mode 120000 index ba76856e8..000000000 --- a/output_template/python/lmnet/utils/output.py +++ /dev/null @@ -1 +0,0 @@ -../../../../lmnet/lmnet/utils/predict_output/output.py \ No newline at end of file From 81e1dd5960fd0cb62d1e266bb5c7503910cf4a17 Mon Sep 17 00:00:00 2001 From: Kentaro Iizuka Date: Wed, 12 Feb 2020 13:41:08 +0900 Subject: [PATCH 2/5] Move lmnet/lmnet/utils to blueoil/utils --- {lmnet/lmnet => blueoil}/utils/box.py | 0 {lmnet/lmnet => blueoil}/utils/config.py | 0 {lmnet/lmnet => blueoil}/utils/executor.py | 0 {lmnet/lmnet => blueoil}/utils/horovod.py | 0 {lmnet/lmnet => blueoil}/utils/image.py | 0 {lmnet/lmnet => blueoil}/utils/module_loader.py | 0 {lmnet/lmnet => blueoil}/utils/predict_output/output.py | 0 {lmnet/lmnet => blueoil}/utils/predict_output/writer.py | 0 {lmnet/lmnet => blueoil}/utils/random.py | 0 {lmnet/lmnet => blueoil}/utils/tfds_builders/classification.py | 0 {lmnet/lmnet => blueoil}/utils/tfds_builders/object_detection.py | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename {lmnet/lmnet => blueoil}/utils/box.py (100%) rename {lmnet/lmnet => blueoil}/utils/config.py (100%) rename {lmnet/lmnet => blueoil}/utils/executor.py (100%) rename {lmnet/lmnet => blueoil}/utils/horovod.py (100%) rename {lmnet/lmnet => blueoil}/utils/image.py (100%) rename {lmnet/lmnet => blueoil}/utils/module_loader.py (100%) rename {lmnet/lmnet => blueoil}/utils/predict_output/output.py (100%) rename {lmnet/lmnet => blueoil}/utils/predict_output/writer.py (100%) rename {lmnet/lmnet => blueoil}/utils/random.py (100%) rename {lmnet/lmnet => blueoil}/utils/tfds_builders/classification.py (100%) rename {lmnet/lmnet => blueoil}/utils/tfds_builders/object_detection.py (100%) diff --git a/lmnet/lmnet/utils/box.py b/blueoil/utils/box.py similarity index 100% rename from lmnet/lmnet/utils/box.py rename to blueoil/utils/box.py diff --git a/lmnet/lmnet/utils/config.py b/blueoil/utils/config.py similarity index 100% rename from lmnet/lmnet/utils/config.py rename to blueoil/utils/config.py diff --git a/lmnet/lmnet/utils/executor.py b/blueoil/utils/executor.py similarity index 100% rename from lmnet/lmnet/utils/executor.py rename to blueoil/utils/executor.py diff --git a/lmnet/lmnet/utils/horovod.py b/blueoil/utils/horovod.py similarity index 100% rename from lmnet/lmnet/utils/horovod.py rename to blueoil/utils/horovod.py diff --git a/lmnet/lmnet/utils/image.py b/blueoil/utils/image.py similarity index 100% rename from lmnet/lmnet/utils/image.py rename to blueoil/utils/image.py diff --git a/lmnet/lmnet/utils/module_loader.py b/blueoil/utils/module_loader.py similarity index 100% rename from lmnet/lmnet/utils/module_loader.py rename to blueoil/utils/module_loader.py diff --git a/lmnet/lmnet/utils/predict_output/output.py b/blueoil/utils/predict_output/output.py similarity index 100% rename from lmnet/lmnet/utils/predict_output/output.py rename to blueoil/utils/predict_output/output.py diff --git a/lmnet/lmnet/utils/predict_output/writer.py b/blueoil/utils/predict_output/writer.py similarity index 100% rename from lmnet/lmnet/utils/predict_output/writer.py rename to blueoil/utils/predict_output/writer.py diff --git a/lmnet/lmnet/utils/random.py b/blueoil/utils/random.py similarity index 100% rename from lmnet/lmnet/utils/random.py rename to blueoil/utils/random.py diff --git a/lmnet/lmnet/utils/tfds_builders/classification.py b/blueoil/utils/tfds_builders/classification.py similarity index 100% rename from lmnet/lmnet/utils/tfds_builders/classification.py rename to blueoil/utils/tfds_builders/classification.py diff --git a/lmnet/lmnet/utils/tfds_builders/object_detection.py b/blueoil/utils/tfds_builders/object_detection.py similarity index 100% rename from lmnet/lmnet/utils/tfds_builders/object_detection.py rename to blueoil/utils/tfds_builders/object_detection.py From 16ef8bf488ddc49d0f5d17b7b1878dc28eab97a4 Mon Sep 17 00:00:00 2001 From: Kentaro Iizuka Date: Wed, 12 Feb 2020 13:42:35 +0900 Subject: [PATCH 3/5] Make symbolic link to output_template/python/blueoil/utils --- output_template/python/blueoil/utils | 1 + 1 file changed, 1 insertion(+) create mode 120000 output_template/python/blueoil/utils diff --git a/output_template/python/blueoil/utils b/output_template/python/blueoil/utils new file mode 120000 index 000000000..6eb6b803c --- /dev/null +++ b/output_template/python/blueoil/utils @@ -0,0 +1 @@ +../../../blueoil/utils/ \ No newline at end of file From 8a28354ba0b8af9ab4450be852c9c2c3d6b8733e Mon Sep 17 00:00:00 2001 From: Kentaro Iizuka Date: Wed, 12 Feb 2020 13:46:12 +0900 Subject: [PATCH 4/5] Change import path --- blueoil/cmd/build_tfds.py | 6 +++--- blueoil/cmd/convert_weight_from_darknet.py | 4 ++-- blueoil/cmd/evaluate.py | 6 +++--- blueoil/cmd/export.py | 6 +++--- blueoil/cmd/measure_latency.py | 6 +++--- blueoil/cmd/profile_model.py | 4 ++-- blueoil/cmd/train.py | 2 +- blueoil/cmd/tune_ray.py | 4 ++-- blueoil/datasets/bdd100k.py | 2 +- blueoil/datasets/camvid.py | 2 +- blueoil/datasets/cifar10.py | 2 +- blueoil/datasets/cifar100.py | 2 +- blueoil/datasets/delta_mark.py | 4 ++-- blueoil/datasets/div2k.py | 2 +- blueoil/datasets/ilsvrc_2012.py | 2 +- blueoil/datasets/image_folder.py | 4 ++-- blueoil/datasets/mscoco.py | 2 +- blueoil/datasets/mscoco_2017.py | 2 +- blueoil/datasets/open_images_v4.py | 4 ++-- blueoil/datasets/pascalvoc_2007_2012.py | 2 +- blueoil/datasets/pascalvoc_base.py | 2 +- blueoil/datasets/tfds.py | 4 ++-- blueoil/datasets/widerface.py | 2 +- blueoil/datasets/ytfaces.py | 2 +- blueoil/generate_lmnet_config.py | 2 +- blueoil/utils/predict_output/writer.py | 4 ++-- lmnet/executor/predict.py | 8 ++++---- lmnet/executor/train.py | 8 ++++---- lmnet/lmnet/data_augmentor.py | 2 +- lmnet/lmnet/post_processor.py | 2 +- lmnet/tests/executor_tests/test_build_tfds.py | 2 +- .../networks_tests/classification_test/test_darknet.py | 2 +- .../classification_test/test_lm_resnet_quantize.py | 2 +- .../classification_test/test_lmnet_quantize.py | 2 +- .../keypoint_detection_tests/test_lm_single_pose_v1.py | 2 +- .../networks_tests/object_detection_tests/test_yolo_v1.py | 2 +- .../networks_tests/object_detection_tests/test_yolo_v2.py | 2 +- .../object_detection_tests/test_yolo_v2_quantize.py | 2 +- .../networks_tests/segmentation_tests/test_lm_bisenet.py | 2 +- lmnet/tests/lmnet_tests/test_data_augmentor.py | 4 ++-- .../lmnet_tests/util_tests/predict_output/test_writer.py | 8 ++++---- lmnet/tests/lmnet_tests/util_tests/test_config.py | 2 +- lmnet/tests/lmnet_tests/util_tests/test_predict_output.py | 2 +- lmnet/tests/lmnet_tests/util_tests/test_random.py | 2 +- lmnet/tests/test_configs.py | 2 +- output_template/python/motion_jpeg_server_from_camera.py | 2 +- output_template/python/run.py | 6 +++--- output_template/python/usb_camera_demo.py | 2 +- 48 files changed, 76 insertions(+), 76 deletions(-) diff --git a/blueoil/cmd/build_tfds.py b/blueoil/cmd/build_tfds.py index 7d2f58801..b10ca5668 100644 --- a/blueoil/cmd/build_tfds.py +++ b/blueoil/cmd/build_tfds.py @@ -21,9 +21,9 @@ from blueoil.datasets.base import ObjectDetectionBase, SegmentationBase from blueoil.datasets.tfds import TFDSMixin -from lmnet.utils import config as config_util -from lmnet.utils.tfds_builders.classification import ClassificationBuilder -from lmnet.utils.tfds_builders.object_detection import ObjectDetectionBuilder +from blueoil.utils import config as config_util +from blueoil.utils.tfds_builders.classification import ClassificationBuilder +from blueoil.utils.tfds_builders.object_detection import ObjectDetectionBuilder def _get_tfds_settings(config_file): diff --git a/blueoil/cmd/convert_weight_from_darknet.py b/blueoil/cmd/convert_weight_from_darknet.py index c52a209b9..e45cee793 100644 --- a/blueoil/cmd/convert_weight_from_darknet.py +++ b/blueoil/cmd/convert_weight_from_darknet.py @@ -23,8 +23,8 @@ from lmnet import environment from blueoil.networks.classification.darknet import Darknet from blueoil.networks.object_detection.yolo_v2 import YoloV2 -from lmnet.utils import config as config_util -from lmnet.utils import executor +from blueoil.utils import config as config_util +from blueoil.utils import executor def convert(config, weight_file): diff --git a/blueoil/cmd/evaluate.py b/blueoil/cmd/evaluate.py index bf1f2e27a..c8acbb27d 100644 --- a/blueoil/cmd/evaluate.py +++ b/blueoil/cmd/evaluate.py @@ -25,9 +25,9 @@ from blueoil.datasets.base import ObjectDetectionBase from blueoil.datasets.dataset_iterator import DatasetIterator from blueoil.datasets.tfds import TFDSClassification, TFDSObjectDetection -from lmnet.utils import config as config_util -from lmnet.utils import executor, module_loader -from lmnet.utils.predict_output.writer import save_json +from blueoil.utils import config as config_util +from blueoil.utils import executor, module_loader +from blueoil.utils.predict_output.writer import save_json logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) diff --git a/blueoil/cmd/export.py b/blueoil/cmd/export.py index a9d24914b..51b2c71b3 100644 --- a/blueoil/cmd/export.py +++ b/blueoil/cmd/export.py @@ -22,9 +22,9 @@ import tensorflow as tf from lmnet import environment -from lmnet.utils.image import load_image -from lmnet.utils import config as config_util -from lmnet.utils import executor +from blueoil.utils.image import load_image +from blueoil.utils import config as config_util +from blueoil.utils import executor DEFAULT_INFERENCE_TEST_DATA_IMAGE = os.path.join( os.path.dirname(os.path.realpath(__file__)), diff --git a/blueoil/cmd/measure_latency.py b/blueoil/cmd/measure_latency.py index 0ab269313..be4c6f285 100644 --- a/blueoil/cmd/measure_latency.py +++ b/blueoil/cmd/measure_latency.py @@ -23,9 +23,9 @@ from tensorflow.python.client import device_lib from lmnet import environment -from lmnet.utils.image import load_image -from lmnet.utils import config as config_util -from lmnet.utils import executor +from blueoil.utils.image import load_image +from blueoil.utils import config as config_util +from blueoil.utils import executor # TODO(wakisaka): duplicated function with blueoil/cmd/export.py diff --git a/blueoil/cmd/profile_model.py b/blueoil/cmd/profile_model.py index d1fbc6fd6..6c0b394d9 100644 --- a/blueoil/cmd/profile_model.py +++ b/blueoil/cmd/profile_model.py @@ -22,8 +22,8 @@ import tensorflow as tf from lmnet import environment -from lmnet.utils import config as config_util -from lmnet.utils import executor +from blueoil.utils import config as config_util +from blueoil.utils import executor logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) diff --git a/blueoil/cmd/train.py b/blueoil/cmd/train.py index 0b05c1043..8235ac091 100644 --- a/blueoil/cmd/train.py +++ b/blueoil/cmd/train.py @@ -21,7 +21,7 @@ from blueoil.generate_lmnet_config import generate from executor.train import run as run_train -from lmnet.utils import horovod as horovod_util +from blueoil.utils import horovod as horovod_util def run(blueoil_config_file, experiment_id): diff --git a/blueoil/cmd/tune_ray.py b/blueoil/cmd/tune_ray.py index 2a8d92358..c7260aa5b 100644 --- a/blueoil/cmd/tune_ray.py +++ b/blueoil/cmd/tune_ray.py @@ -26,8 +26,8 @@ from blueoil.datasets.base import ObjectDetectionBase from blueoil.datasets.dataset_iterator import DatasetIterator from blueoil.datasets.tfds import TFDSClassification, TFDSObjectDetection -from lmnet.utils import config as config_util -from lmnet.utils import executor +from blueoil.utils import config as config_util +from blueoil.utils import executor from ray.tune import Trainable, register_trainable, run_experiments from ray.tune.schedulers import AsyncHyperBandScheduler from ray.tune.suggest import HyperOptSearch diff --git a/blueoil/datasets/bdd100k.py b/blueoil/datasets/bdd100k.py index 68da288af..0c01d7a31 100644 --- a/blueoil/datasets/bdd100k.py +++ b/blueoil/datasets/bdd100k.py @@ -7,7 +7,7 @@ import numpy as np from blueoil.datasets.base import ObjectDetectionBase, SegmentationBase -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image class BDD100KObjectDetection(ObjectDetectionBase): diff --git a/blueoil/datasets/camvid.py b/blueoil/datasets/camvid.py index ce4f1b9ad..9b80d8485 100644 --- a/blueoil/datasets/camvid.py +++ b/blueoil/datasets/camvid.py @@ -22,7 +22,7 @@ from lmnet.common import get_color_map from blueoil.datasets.base import SegmentationBase, StoragePathCustomizable -from lmnet.utils.random import shuffle, train_test_split +from blueoil.utils.random import shuffle, train_test_split def get_image(filename, convert_rgb=True, ignore_class_idx=None): diff --git a/blueoil/datasets/cifar10.py b/blueoil/datasets/cifar10.py index 52ef8253f..a9d80f21e 100644 --- a/blueoil/datasets/cifar10.py +++ b/blueoil/datasets/cifar10.py @@ -21,7 +21,7 @@ from lmnet import data_processor from blueoil.datasets.base import Base -from lmnet.utils.random import shuffle +from blueoil.utils.random import shuffle class Cifar10(Base): diff --git a/blueoil/datasets/cifar100.py b/blueoil/datasets/cifar100.py index a992ef46c..9408c4711 100644 --- a/blueoil/datasets/cifar100.py +++ b/blueoil/datasets/cifar100.py @@ -21,7 +21,7 @@ from lmnet import data_processor from blueoil.datasets.base import Base -from lmnet.utils.random import shuffle +from blueoil.utils.random import shuffle class Cifar100(Base): diff --git a/blueoil/datasets/delta_mark.py b/blueoil/datasets/delta_mark.py index eaa51e427..e88cc22aa 100644 --- a/blueoil/datasets/delta_mark.py +++ b/blueoil/datasets/delta_mark.py @@ -22,8 +22,8 @@ from lmnet import data_processor from blueoil.datasets.base import Base, ObjectDetectionBase, StoragePathCustomizable -from lmnet.utils.image import load_image -from lmnet.utils.random import shuffle, train_test_split +from blueoil.utils.image import load_image +from blueoil.utils.random import shuffle, train_test_split @functools.lru_cache(maxsize=None) diff --git a/blueoil/datasets/div2k.py b/blueoil/datasets/div2k.py index 03e05fce4..2ae975aa7 100644 --- a/blueoil/datasets/div2k.py +++ b/blueoil/datasets/div2k.py @@ -18,7 +18,7 @@ from glob import glob from blueoil.datasets.base import Base -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image class Div2k(Base): diff --git a/blueoil/datasets/ilsvrc_2012.py b/blueoil/datasets/ilsvrc_2012.py index 77c53116c..93c261b57 100644 --- a/blueoil/datasets/ilsvrc_2012.py +++ b/blueoil/datasets/ilsvrc_2012.py @@ -21,7 +21,7 @@ import pandas as pd from lmnet import data_processor -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image from blueoil.datasets.base import Base diff --git a/blueoil/datasets/image_folder.py b/blueoil/datasets/image_folder.py index 4773c89aa..ed80e980f 100644 --- a/blueoil/datasets/image_folder.py +++ b/blueoil/datasets/image_folder.py @@ -22,9 +22,9 @@ import numpy as np from lmnet import data_processor -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image from blueoil.datasets.base import Base, StoragePathCustomizable -from lmnet.utils.random import train_test_split +from blueoil.utils.random import train_test_split class ImageFolderBase(StoragePathCustomizable, Base): diff --git a/blueoil/datasets/mscoco.py b/blueoil/datasets/mscoco.py index 7754df172..36a03669e 100644 --- a/blueoil/datasets/mscoco.py +++ b/blueoil/datasets/mscoco.py @@ -19,7 +19,7 @@ import numpy as np from pycocotools.coco import COCO -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image from blueoil.datasets.base import ObjectDetectionBase, SegmentationBase DEFAULT_CLASSES = [ diff --git a/blueoil/datasets/mscoco_2017.py b/blueoil/datasets/mscoco_2017.py index b7bf9bfc7..8b23e8727 100644 --- a/blueoil/datasets/mscoco_2017.py +++ b/blueoil/datasets/mscoco_2017.py @@ -18,7 +18,7 @@ import numpy as np from pycocotools.coco import COCO -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image from blueoil.datasets.base import KeypointDetectionBase diff --git a/blueoil/datasets/open_images_v4.py b/blueoil/datasets/open_images_v4.py index 0438e0133..bd8510ea9 100644 --- a/blueoil/datasets/open_images_v4.py +++ b/blueoil/datasets/open_images_v4.py @@ -25,8 +25,8 @@ from lmnet import data_processor from blueoil.datasets.base import Base, ObjectDetectionBase, StoragePathCustomizable -from lmnet.utils.image import load_image -from lmnet.utils.random import train_test_split +from blueoil.utils.image import load_image +from blueoil.utils.random import train_test_split class OpenImagesV4(Base): diff --git a/blueoil/datasets/pascalvoc_2007_2012.py b/blueoil/datasets/pascalvoc_2007_2012.py index c0b82ad07..5abf84178 100644 --- a/blueoil/datasets/pascalvoc_2007_2012.py +++ b/blueoil/datasets/pascalvoc_2007_2012.py @@ -17,7 +17,7 @@ import numpy as np -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image from blueoil.datasets.base import ObjectDetectionBase from blueoil.datasets.pascalvoc_2007 import Pascalvoc2007 from blueoil.datasets.pascalvoc_2012 import Pascalvoc2012 diff --git a/blueoil/datasets/pascalvoc_base.py b/blueoil/datasets/pascalvoc_base.py index 0ccaa4533..335917735 100644 --- a/blueoil/datasets/pascalvoc_base.py +++ b/blueoil/datasets/pascalvoc_base.py @@ -21,7 +21,7 @@ import numpy as np import pandas as pd -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image from blueoil.datasets.base import ObjectDetectionBase diff --git a/blueoil/datasets/tfds.py b/blueoil/datasets/tfds.py index df77928da..0620ae9c8 100644 --- a/blueoil/datasets/tfds.py +++ b/blueoil/datasets/tfds.py @@ -20,8 +20,8 @@ import tensorflow_datasets as tfds from blueoil.datasets.base import Base, ObjectDetectionBase -from lmnet.utils.tfds_builders.classification import ClassificationBuilder -from lmnet.utils.tfds_builders.object_detection import ObjectDetectionBuilder +from blueoil.utils.tfds_builders.classification import ClassificationBuilder +from blueoil.utils.tfds_builders.object_detection import ObjectDetectionBuilder def _grayscale_to_rgb(record): diff --git a/blueoil/datasets/widerface.py b/blueoil/datasets/widerface.py index 4b69b6b2e..fc7d776be 100644 --- a/blueoil/datasets/widerface.py +++ b/blueoil/datasets/widerface.py @@ -18,7 +18,7 @@ import numpy as np -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image from blueoil.datasets.base import ObjectDetectionBase diff --git a/blueoil/datasets/ytfaces.py b/blueoil/datasets/ytfaces.py index 0669a1d18..19908361d 100644 --- a/blueoil/datasets/ytfaces.py +++ b/blueoil/datasets/ytfaces.py @@ -17,7 +17,7 @@ import numpy as np -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image from blueoil.datasets.base import KeypointDetectionBase diff --git a/blueoil/generate_lmnet_config.py b/blueoil/generate_lmnet_config.py index 4e0b1a779..a83b29d9c 100644 --- a/blueoil/generate_lmnet_config.py +++ b/blueoil/generate_lmnet_config.py @@ -23,7 +23,7 @@ from jinja2 import Environment, FileSystemLoader from tensorflow.io import gfile -from lmnet.utils.module_loader import load_class +from blueoil.utils.module_loader import load_class _TASK_TYPE_TEMPLATE_FILE = { diff --git a/blueoil/utils/predict_output/writer.py b/blueoil/utils/predict_output/writer.py index 83213bff2..2dbd5e294 100644 --- a/blueoil/utils/predict_output/writer.py +++ b/blueoil/utils/predict_output/writer.py @@ -3,8 +3,8 @@ import numpy as np -from lmnet.utils.predict_output.output import ImageFromJson -from lmnet.utils.predict_output.output import JsonOutput +from blueoil.utils.predict_output.output import ImageFromJson +from blueoil.utils.predict_output.output import JsonOutput logger = logging.getLogger(__name__) diff --git a/lmnet/executor/predict.py b/lmnet/executor/predict.py index c7a2b34df..315e0859b 100644 --- a/lmnet/executor/predict.py +++ b/lmnet/executor/predict.py @@ -23,10 +23,10 @@ import tensorflow as tf from lmnet import environment -from lmnet.utils.image import load_image -from lmnet.utils import config as config_util -from lmnet.utils.executor import search_restore_filename -from lmnet.utils.predict_output.writer import OutputWriter +from blueoil.utils.image import load_image +from blueoil.utils import config as config_util +from blueoil.utils.executor import search_restore_filename +from blueoil.utils.predict_output.writer import OutputWriter DUMMY_FILENAME = "DUMMY_FILE" diff --git a/lmnet/executor/train.py b/lmnet/executor/train.py index 1a481eab4..30d278418 100644 --- a/lmnet/executor/train.py +++ b/lmnet/executor/train.py @@ -26,10 +26,10 @@ from blueoil.datasets.base import ObjectDetectionBase from blueoil.datasets.dataset_iterator import DatasetIterator from blueoil.datasets.tfds import TFDSClassification, TFDSObjectDetection -from lmnet.utils import config as config_util -from lmnet.utils import executor -from lmnet.utils import horovod as horovod_util -from lmnet.utils import module_loader +from blueoil.utils import config as config_util +from blueoil.utils import executor +from blueoil.utils import horovod as horovod_util +from blueoil.utils import module_loader def _save_checkpoint(saver, sess, global_step, step): diff --git a/lmnet/lmnet/data_augmentor.py b/lmnet/lmnet/data_augmentor.py index 257269e4e..d64003f4d 100644 --- a/lmnet/lmnet/data_augmentor.py +++ b/lmnet/lmnet/data_augmentor.py @@ -22,7 +22,7 @@ from PIL import Image, ImageEnhance, ImageFilter from lmnet import data_processor, pre_processor -from lmnet.utils.box import fill_dummy_boxes, crop_boxes, iou +from blueoil.utils.box import fill_dummy_boxes, crop_boxes, iou class Blur(data_processor.Processor): diff --git a/lmnet/lmnet/post_processor.py b/lmnet/lmnet/post_processor.py index 678e18857..782345be5 100644 --- a/lmnet/lmnet/post_processor.py +++ b/lmnet/lmnet/post_processor.py @@ -19,7 +19,7 @@ from lmnet.data_augmentor import iou from lmnet.data_processor import Processor -from lmnet.utils.box import format_cxcywh_to_xywh +from blueoil.utils.box import format_cxcywh_to_xywh def _softmax(x): diff --git a/lmnet/tests/executor_tests/test_build_tfds.py b/lmnet/tests/executor_tests/test_build_tfds.py index 9dfc8f299..b81b5779e 100644 --- a/lmnet/tests/executor_tests/test_build_tfds.py +++ b/lmnet/tests/executor_tests/test_build_tfds.py @@ -21,7 +21,7 @@ from lmnet import environment from blueoil.datasets.dataset_iterator import DatasetIterator from blueoil.datasets.tfds import TFDSClassification, TFDSObjectDetection -from lmnet.utils import config as config_util +from blueoil.utils import config as config_util _RUN_AS_A_SCRIPT = False diff --git a/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_darknet.py b/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_darknet.py index fa5966cb0..8b5816a1d 100644 --- a/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_darknet.py +++ b/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_darknet.py @@ -23,7 +23,7 @@ from blueoil.networks.classification.darknet import Darknet from blueoil.datasets.image_folder import ImageFolderBase from lmnet.pre_processor import Resize -from lmnet.utils.executor import prepare_dirs +from blueoil.utils.executor import prepare_dirs # Apply reset_default_graph() in conftest.py to all tests in this file. # Set test environment diff --git a/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_lm_resnet_quantize.py b/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_lm_resnet_quantize.py index 4a9041a6c..1aa60e2d1 100644 --- a/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_lm_resnet_quantize.py +++ b/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_lm_resnet_quantize.py @@ -24,7 +24,7 @@ from blueoil.datasets.image_folder import ImageFolderBase from lmnet.pre_processor import Resize from blueoil.nn.quantizations import binary_mean_scaling_quantizer, linear_mid_tread_half_quantizer -from lmnet.utils.executor import prepare_dirs +from blueoil.utils.executor import prepare_dirs # Apply reset_default_graph() in conftest.py to all tests in this file. # Set test environment diff --git a/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_lmnet_quantize.py b/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_lmnet_quantize.py index 0319f37f4..9f8854a1a 100644 --- a/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_lmnet_quantize.py +++ b/lmnet/tests/lmnet_tests/networks_tests/classification_test/test_lmnet_quantize.py @@ -24,7 +24,7 @@ from blueoil.datasets.image_folder import ImageFolderBase from lmnet.pre_processor import Resize from blueoil.nn.quantizations import binary_mean_scaling_quantizer, linear_mid_tread_half_quantizer -from lmnet.utils.executor import prepare_dirs +from blueoil.utils.executor import prepare_dirs # Apply reset_default_graph() in conftest.py to all tests in this file. # Set test environment diff --git a/lmnet/tests/lmnet_tests/networks_tests/keypoint_detection_tests/test_lm_single_pose_v1.py b/lmnet/tests/lmnet_tests/networks_tests/keypoint_detection_tests/test_lm_single_pose_v1.py index deaa034aa..0c514cbbf 100644 --- a/lmnet/tests/lmnet_tests/networks_tests/keypoint_detection_tests/test_lm_single_pose_v1.py +++ b/lmnet/tests/lmnet_tests/networks_tests/keypoint_detection_tests/test_lm_single_pose_v1.py @@ -21,7 +21,7 @@ from lmnet.common import Tasks from blueoil.networks.keypoint_detection.lm_single_pose_v1 import LmSinglePoseV1Quantize from blueoil.datasets.mscoco_2017 import MscocoSinglePersonKeypoints -from lmnet.utils.executor import prepare_dirs +from blueoil.utils.executor import prepare_dirs from lmnet.pre_processor import ( DivideBy255, ResizeWithJoints, diff --git a/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v1.py b/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v1.py index 6f2878d38..b9160682d 100644 --- a/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v1.py +++ b/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v1.py @@ -24,7 +24,7 @@ from blueoil.networks.object_detection.yolo_v1 import YoloV1 from blueoil.datasets.pascalvoc_2007 import Pascalvoc2007 from lmnet.pre_processor import ResizeWithGtBoxes -from lmnet.utils.executor import prepare_dirs +from blueoil.utils.executor import prepare_dirs # Apply reset_default_graph() in conftest.py to all tests in this file. # Set test environment diff --git a/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v2.py b/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v2.py index 39360fd73..8ea4c30ae 100644 --- a/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v2.py +++ b/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v2.py @@ -26,7 +26,7 @@ from blueoil.datasets.pascalvoc_2007 import Pascalvoc2007 from lmnet.post_processor import NMS, ExcludeLowScoreBox, FormatYoloV2 from lmnet.pre_processor import ResizeWithGtBoxes -from lmnet.utils.executor import prepare_dirs +from blueoil.utils.executor import prepare_dirs # Apply reset_default_graph() in conftest.py to all tests in this file. # Set test environment diff --git a/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v2_quantize.py b/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v2_quantize.py index deab1b377..ad90939ac 100644 --- a/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v2_quantize.py +++ b/lmnet/tests/lmnet_tests/networks_tests/object_detection_tests/test_yolo_v2_quantize.py @@ -24,7 +24,7 @@ from blueoil.datasets.pascalvoc_2007 import Pascalvoc2007 from lmnet.pre_processor import ResizeWithGtBoxes from blueoil.nn.quantizations import binary_channel_wise_mean_scaling_quantizer, linear_mid_tread_half_quantizer -from lmnet.utils.executor import prepare_dirs +from blueoil.utils.executor import prepare_dirs # Apply reset_default_graph() in conftest.py to all tests in this file. # Set test environment diff --git a/lmnet/tests/lmnet_tests/networks_tests/segmentation_tests/test_lm_bisenet.py b/lmnet/tests/lmnet_tests/networks_tests/segmentation_tests/test_lm_bisenet.py index 429a1203d..c7112ed04 100644 --- a/lmnet/tests/lmnet_tests/networks_tests/segmentation_tests/test_lm_bisenet.py +++ b/lmnet/tests/lmnet_tests/networks_tests/segmentation_tests/test_lm_bisenet.py @@ -26,7 +26,7 @@ from blueoil.datasets.camvid import Camvid from lmnet.post_processor import Bilinear, Softmax from lmnet.pre_processor import Resize -from lmnet.utils.executor import prepare_dirs +from blueoil.utils.executor import prepare_dirs # Apply reset_default_graph() and set_test_environment() in conftest.py to all tests in this file. pytestmark = pytest.mark.usefixtures("reset_default_graph", "set_test_environment") diff --git a/lmnet/tests/lmnet_tests/test_data_augmentor.py b/lmnet/tests/lmnet_tests/test_data_augmentor.py index e04c06b19..87a1c00e5 100644 --- a/lmnet/tests/lmnet_tests/test_data_augmentor.py +++ b/lmnet/tests/lmnet_tests/test_data_augmentor.py @@ -21,7 +21,7 @@ import pytest from blueoil.datasets.pascalvoc_2007 import Pascalvoc2007 -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image from blueoil.datasets.dataset_iterator import DatasetIterator from lmnet.pre_processor import ResizeWithGtBoxes from lmnet.data_processor import ( @@ -40,7 +40,7 @@ RandomPatchCut, SSDRandomCrop ) -from lmnet.utils.box import iou, crop_boxes +from blueoil.utils.box import iou, crop_boxes # Apply reset_default_graph() and set_test_environment() in conftest.py to all tests in this file. diff --git a/lmnet/tests/lmnet_tests/util_tests/predict_output/test_writer.py b/lmnet/tests/lmnet_tests/util_tests/predict_output/test_writer.py index fb50b582f..67e1cfed9 100644 --- a/lmnet/tests/lmnet_tests/util_tests/predict_output/test_writer.py +++ b/lmnet/tests/lmnet_tests/util_tests/predict_output/test_writer.py @@ -6,10 +6,10 @@ from PIL import Image from lmnet.common import Tasks -from lmnet.utils.predict_output.writer import OutputWriter -from lmnet.utils.predict_output.writer import save_json -from lmnet.utils.predict_output.writer import save_npy -from lmnet.utils.predict_output.writer import save_materials +from blueoil.utils.predict_output.writer import OutputWriter +from blueoil.utils.predict_output.writer import save_json +from blueoil.utils.predict_output.writer import save_npy +from blueoil.utils.predict_output.writer import save_materials def test_write(temp_dir): diff --git a/lmnet/tests/lmnet_tests/util_tests/test_config.py b/lmnet/tests/lmnet_tests/util_tests/test_config.py index 0fa765cd3..2a3abf10e 100644 --- a/lmnet/tests/lmnet_tests/util_tests/test_config.py +++ b/lmnet/tests/lmnet_tests/util_tests/test_config.py @@ -15,7 +15,7 @@ # ============================================================================= from easydict import EasyDict -from lmnet.utils import config as config_util +from blueoil.utils import config as config_util def test_merge(): diff --git a/lmnet/tests/lmnet_tests/util_tests/test_predict_output.py b/lmnet/tests/lmnet_tests/util_tests/test_predict_output.py index 0a5ca546f..21eabf7ea 100644 --- a/lmnet/tests/lmnet_tests/util_tests/test_predict_output.py +++ b/lmnet/tests/lmnet_tests/util_tests/test_predict_output.py @@ -21,7 +21,7 @@ import PIL.Image from lmnet.common import Tasks -from lmnet.utils.predict_output.output import JsonOutput +from blueoil.utils.predict_output.output import JsonOutput def test_classification_json(): diff --git a/lmnet/tests/lmnet_tests/util_tests/test_random.py b/lmnet/tests/lmnet_tests/util_tests/test_random.py index 35ce45251..154e72424 100644 --- a/lmnet/tests/lmnet_tests/util_tests/test_random.py +++ b/lmnet/tests/lmnet_tests/util_tests/test_random.py @@ -18,7 +18,7 @@ import numpy as np import pytest -from lmnet.utils.random import shuffle, train_test_split +from blueoil.utils.random import shuffle, train_test_split def test_shuffle(): diff --git a/lmnet/tests/test_configs.py b/lmnet/tests/test_configs.py index 284eed5ef..d3ecc8838 100644 --- a/lmnet/tests/test_configs.py +++ b/lmnet/tests/test_configs.py @@ -19,7 +19,7 @@ import pytest from lmnet import environment -from lmnet.utils.config import _load_py, check_config, save_yaml +from blueoil.utils.config import _load_py, check_config, save_yaml pytestmark = pytest.mark.usefixtures("set_test_environment") diff --git a/output_template/python/motion_jpeg_server_from_camera.py b/output_template/python/motion_jpeg_server_from_camera.py index bd7dea9b7..dfaa639fd 100644 --- a/output_template/python/motion_jpeg_server_from_camera.py +++ b/output_template/python/motion_jpeg_server_from_camera.py @@ -29,7 +29,7 @@ import click from lmnet.nnlib import NNLib -from lmnet.utils.config import ( +from blueoil.utils.config import ( load_yaml, build_pre_process, build_post_process, diff --git a/output_template/python/run.py b/output_template/python/run.py index c5d26c3a9..cb67f932a 100644 --- a/output_template/python/run.py +++ b/output_template/python/run.py @@ -22,10 +22,10 @@ from lmnet.nnlib import NNLib as NNLib -from lmnet.utils.image import load_image +from blueoil.utils.image import load_image from lmnet.common import Tasks -from lmnet.utils.output import JsonOutput, ImageFromJson -from lmnet.utils.config import ( +from blueoil.utils.predict_output.output import JsonOutput, ImageFromJson +from blueoil.utils.config import ( load_yaml, build_pre_process, build_post_process, diff --git a/output_template/python/usb_camera_demo.py b/output_template/python/usb_camera_demo.py index 827fde346..80ccd1b16 100644 --- a/output_template/python/usb_camera_demo.py +++ b/output_template/python/usb_camera_demo.py @@ -31,7 +31,7 @@ from lmnet.common import get_color_map from lmnet.nnlib import NNLib -from lmnet.utils.config import ( +from blueoil.utils.config import ( load_yaml, build_pre_process, build_post_process, From 137bb23413afa4bee0fbe132c48be4e9db39fc4e Mon Sep 17 00:00:00 2001 From: Kentaro Iizuka Date: Wed, 12 Feb 2020 13:48:49 +0900 Subject: [PATCH 5/5] Recover a part of output_template/python/lmnet/utils --- blueoil/utils/__init__.py | 0 .../python/lmnet/utils/__init__.py | 15 ++ output_template/python/lmnet/utils/demo.py | 162 ++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 blueoil/utils/__init__.py create mode 100644 output_template/python/lmnet/utils/__init__.py create mode 100644 output_template/python/lmnet/utils/demo.py diff --git a/blueoil/utils/__init__.py b/blueoil/utils/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/output_template/python/lmnet/utils/__init__.py b/output_template/python/lmnet/utils/__init__.py new file mode 100644 index 000000000..4a9993469 --- /dev/null +++ b/output_template/python/lmnet/utils/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 The Blueoil Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= diff --git a/output_template/python/lmnet/utils/demo.py b/output_template/python/lmnet/utils/demo.py new file mode 100644 index 000000000..f4cc3cbf1 --- /dev/null +++ b/output_template/python/lmnet/utils/demo.py @@ -0,0 +1,162 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 The Blueoil Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +from __future__ import absolute_import, division, print_function, unicode_literals + +import time +from itertools import product as itr_prod +from threading import Thread + +import cv2 +import numpy as np + +# HACK: cross py2-py3 compatible version +try: + from queue import Queue +except ImportError: + from Queue import Queue + + + +COLORS = [tuple(p) for p in itr_prod([0, 180, 255], repeat=3)] +COLORS = COLORS[1:] + + +def ltwh_to__tblr(ltwh): + l, t, w, h = ltwh.tolist() + b = int(t + h) + r = int(l + w) + return t, b, l, r + + +def add_fps(orig, fps): + f_p_s_text = "FPS: {:.1f}".format(fps) + text_color = (255, 144, 30) + orig_h, orig_w = orig.shape[:2] + cv2.putText(orig, f_p_s_text, (10, orig_h - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color, 1) + return orig + + +def check_range(upper, lower, checked_val): + if upper < checked_val: + checked_val = upper + elif lower > checked_val: + checked_val = lower + return checked_val + + +def add_rectangle(classes, orig, preds, pred_shape): + orig_h, orig_w = orig.shape[:2] + locs = [pred[:, 0:4] for pred in preds] + labels_n = np.array([pred[:, 4] for pred in preds]).astype(np.int) # TODO magic-number + labels_n = labels_n.flatten() + + labels = [classes[i_label] for i_label in labels_n] + scores = preds[0][:, 5] + + pred_h, pred_w = pred_shape + w_scale = orig_w / pred_w + h_scale = orig_h / pred_h + locs = (np.array(locs).reshape((-1, 4)) * [w_scale, h_scale, w_scale, h_scale]).astype(int) + for idx, loc in enumerate(locs): + t, b, le, r = ltwh_to__tblr(loc) + + le = check_range(orig_w, 0, le) + r = check_range(orig_w, 0, r) + t = check_range(orig_h, 0, t) + b = check_range(orig_h, 0, b) + + color_r = COLORS[labels_n[idx] % len(COLORS)] + thick = 2 + label_text = "{} : {:.1f}%".format(labels[idx], scores[idx] * 100) + label_size, baseline = cv2.getTextSize(label_text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1) + cv2.rectangle(orig, (le, t), (r, b), color_r, thick) + + max_color = max(color_r) + text_color = (255, 255, 255) if max_color < 255 else (0, 0, 0) + + cv2_filed_config = cv2.cv.CV_FILLED if hasattr(cv2, 'cv') else cv2.FILLED + + cv2.rectangle(orig, (le, t), (le + label_size[0], t + label_size[1]), color_r, cv2_filed_config) + cv2.putText(orig, label_text, (le, t + label_size[1]), cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color) + + return orig + + +class VideoStream: + def __init__(self, video_source, video_width, video_height, video_fps, queue_size=1): + self.video_fps = video_fps + + vc = cv2.VideoCapture(video_source) + + if hasattr(cv2, 'cv'): + vc.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, video_width) + vc.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, video_height) + vc.set(cv2.cv.CV_CAP_PROP_FPS, video_fps) + else: + vc.set(cv2.CAP_PROP_FRAME_WIDTH, video_width) + vc.set(cv2.CAP_PROP_FRAME_HEIGHT, video_height) + vc.set(cv2.CAP_PROP_FPS, video_fps) + + self.stream = vc + self.stopped = False + self.queue = Queue(maxsize=queue_size) + self.thread = Thread(target=self.update, args=()) + self.thread.daemon = True + self.thread.start() + + def update(self): + while True: + if self.stopped: + break + + (flg, frame) = self.stream.read() + if not flg: + Exception("Video capture is wrong") + frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + + if self.queue.full(): + time.sleep(1/float(self.video_fps)) + else: + if not self.queue.empty(): + self.queue.get() + self.queue.put(frame) + else: + self.queue.put(frame) + + self.stream.release() + + def read(self): + return self.queue.get() + + def release(self): + self.stopped = True + self.thread.join() + + +def run_inference(image, nn, pre_process, post_process): + start = time.clock() + + data = pre_process(image=image)["image"] + data = np.expand_dims(data, axis=0) + + network_only_start = time.clock() + result = nn.run(data) + fps_only_network = 1.0/(time.clock() - network_only_start) + + output = post_process(outputs=result)['outputs'] + + fps = 1.0/(time.clock() - start) + return output, fps, fps_only_network