From f7beae7bd5dba146f7465bf16682ae30002ee5a5 Mon Sep 17 00:00:00 2001 From: hanhxiao Date: Tue, 20 Aug 2019 12:04:02 +0800 Subject: [PATCH] feat(cli): add py_path in parser to load external modules --- gnes/helper.py | 4 +++- gnes/preprocessor/video/ffmpeg.py | 3 ++- gnes/proto/__init__.py | 22 +++------------------- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/gnes/helper.py b/gnes/helper.py index 5455d85e..b52c0f59 100644 --- a/gnes/helper.py +++ b/gnes/helper.py @@ -39,7 +39,9 @@ 'get_perm', 'time_profile', 'set_logger', 'batch_iterator', 'batching', 'yaml', 'profile_logger', 'load_contrib_module', - 'parse_arg', 'profiling', 'FileLock', 'train_required', 'get_first_available_gpu'] + 'parse_arg', 'profiling', 'FileLock', + 'train_required', 'get_first_available_gpu', + 'PathImporter'] def get_first_available_gpu(): diff --git a/gnes/preprocessor/video/ffmpeg.py b/gnes/preprocessor/video/ffmpeg.py index 255ba391..d8239a55 100644 --- a/gnes/preprocessor/video/ffmpeg.py +++ b/gnes/preprocessor/video/ffmpeg.py @@ -164,7 +164,8 @@ def apply(self, doc: 'gnes_pb2.Document') -> None: hash_v = [phash_descriptor(_).hash for _ in frames] hash_v = np.array(hash_v, dtype=np.int32).reshape([len(hash_v), -1]) label_v = KMeans(n_clusters=self.segment_num).fit_predict(hash_v) - sub_videos = [[frames[i] for i, j in enumerate(label_v) if j == _] for _ in range(self.segment_num)] + sub_videos = [[frames[i] for i, j in enumerate(label_v) if j == _] for _ in + range(self.segment_num)] else: sub_videos = [frames] diff --git a/gnes/proto/__init__.py b/gnes/proto/__init__.py index cfd90fcd..314173a8 100644 --- a/gnes/proto/__init__.py +++ b/gnes/proto/__init__.py @@ -13,20 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -import uuid +import ctypes +import random from typing import List from typing import Optional import numpy as np import zmq -import random -import ctypes from termcolor import colored from . import gnes_pb2 from ..helper import batch_iterator -__all__ = ['send_message', 'recv_message', 'blob2array', 'array2blob', 'gnes_pb2', 'add_route'] +__all__ = ['RequestGenerator', 'send_message', 'recv_message', 'blob2array', 'array2blob', 'gnes_pb2', 'add_route'] class RequestGenerator: @@ -106,21 +105,6 @@ def router2str(m: 'gnes_pb2.Message') -> str: return colored('▸', 'green').join([r.service for r in m.envelope.routes]) -def new_envelope(client_id: str, - request_id: str = str(uuid.uuid4()), - num_part: int = 1, - part_id: int = 1, - timeout: int = 5000) -> 'gnes_pb2.Envelope': - evlp = gnes_pb2.Envelope() - evlp.client_id = client_id - evlp.request_id = request_id - evlp.part_id = part_id - evlp.num_part.append(num_part) - evlp.timeout = timeout - add_route(evlp, client_id) - return evlp - - def add_route(evlp: 'gnes_pb2.Envelope', name: str): r = evlp.routes.add() r.service = name