提交 7d37cfb5 编写于 作者: W wuzewu

update run commmand

上级 e216f355
python ../../paddlehub/commands/hub.py run hub_module_lac/ --signature lexical_analysis --config resources/test/test.yml --input_file resources/test/test.csv python ../../paddlehub/commands/hub.py run hub_module_lac/ --signature lexical_analysis --config resources/test/test.yml --input_file resources/test/test.txt
...@@ -31,8 +31,8 @@ def infer_with_input_file(): ...@@ -31,8 +31,8 @@ def infer_with_input_file():
key = list(data_format.keys())[0] key = list(data_format.keys())[0]
# parse input file # parse input file
test_csv = os.path.join("resources", "test", "test.csv") test_file = os.path.join("resources", "test", "test.txt")
test_text = hub.io.reader.csv_reader.read(test_csv)["TEXT_INPUT"] test_text = hub.io.parser.txt_parser.parse(test_file)
# set input dict # set input dict
input_dict = {key: test_text} input_dict = {key: test_text}
...@@ -43,4 +43,4 @@ def infer_with_input_file(): ...@@ -43,4 +43,4 @@ def infer_with_input_file():
if __name__ == "__main__": if __name__ == "__main__":
infer_with_input_text() infer_with_input_file()
python ../../paddlehub/commands/hub.py run hub_module_senta/ --signature sentiment_classify --config resources/test/test.yml --dataset resources/test/test.csv python ../../paddlehub/commands/hub.py run hub_module_senta/ --signature sentiment_classify --config resources/test/test.yml --input_file resources/test/test.txt
...@@ -31,8 +31,8 @@ def infer_with_input_file(): ...@@ -31,8 +31,8 @@ def infer_with_input_file():
key = list(data_format.keys())[0] key = list(data_format.keys())[0]
# parse input file # parse input file
test_csv = os.path.join("resources", "test", "test.csv") test_file = os.path.join("resources", "test", "test.txt")
test_text = hub.io.reader.csv_reader.read(test_csv)["TEXT_INPUT"] test_text = hub.io.parser.txt_parser.parse(test_file)
# set input dict # set input dict
input_dict = {key: test_text} input_dict = {key: test_text}
......
TEXT_INPUT
这部电影真的很赞 这部电影真的很赞
售后太差! 售后太差!
python ../../paddlehub/commands/hub.py run hub_module_ssd/ --signature object_detection --config resources/test/test.yml --dataset resources/test/test.csv python ../../paddlehub/commands/hub.py run hub_module_ssd/ --signature object_detection --config resources/test/test.yml --input_file resources/test/test.txt
...@@ -30,8 +30,8 @@ def infer_with_input_file(): ...@@ -30,8 +30,8 @@ def infer_with_input_file():
key = list(data_format.keys())[0] key = list(data_format.keys())[0]
# parse input file # parse input file
test_csv = os.path.join("resources", "test", "test.csv") test_file = os.path.join("resources", "test", "test.txt")
test_images = hub.io.reader.csv_reader.read(test_csv)["IMAGE_PATH"] test_images = hub.io.parser.txt_parser.parse(test_file)
# set input dict # set input dict
input_dict = {key: test_images} input_dict = {key: test_images}
......
IMAGE_PATH
./resources/test/test_img_sheep.jpg ./resources/test/test_img_sheep.jpg
./resources/test/test_img_cat.jpg ./resources/test/test_img_cat.jpg
./resources/test/test_img_bird.jpg ./resources/test/test_img_bird.jpg
...@@ -21,7 +21,7 @@ import os ...@@ -21,7 +21,7 @@ import os
from paddlehub.common.logger import logger from paddlehub.common.logger import logger
from paddlehub.commands.base_command import BaseCommand, ENTRY from paddlehub.commands.base_command import BaseCommand, ENTRY
from paddlehub.io.reader import csv_reader, yaml_reader from paddlehub.io.parser import yaml_parser, txt_parser
from paddlehub.module.manager import default_module_manager from paddlehub.module.manager import default_module_manager
from paddlehub.common import utils from paddlehub.common import utils
from paddlehub.common.arg_helper import add_argument, print_arguments from paddlehub.common.arg_helper import add_argument, print_arguments
...@@ -112,7 +112,8 @@ class RunCommand(BaseCommand): ...@@ -112,7 +112,8 @@ class RunCommand(BaseCommand):
input_data_key = list(expect_data_format.keys())[0] input_data_key = list(expect_data_format.keys())[0]
origin_data = {input_data_key: [self.args.data]} origin_data = {input_data_key: [self.args.data]}
elif self.args.dataset: elif self.args.dataset:
origin_data = csv_reader.read(self.args.dataset) input_data_key = list(expect_data_format.keys())[0]
origin_data = {input_data_key: txt_parser.parse(self.args.dataset)}
else: else:
print("ERROR! Please specify data to predict.\n") print("ERROR! Please specify data to predict.\n")
print("Summary:\n %s\n" % module.summary) print("Summary:\n %s\n" % module.summary)
...@@ -127,7 +128,7 @@ class RunCommand(BaseCommand): ...@@ -127,7 +128,7 @@ class RunCommand(BaseCommand):
input_data = {input_data_key: origin_data[origin_data_key]} input_data = {input_data_key: origin_data[origin_data_key]}
config = {} config = {}
else: else:
yaml_config = yaml_reader.read(self.args.config) yaml_config = yaml_parser.parse(self.args.config)
if len(expect_data_format) == 1: if len(expect_data_format) == 1:
origin_data_key = list(origin_data.keys())[0] origin_data_key = list(origin_data.keys())[0]
input_data_key = list(expect_data_format.keys())[0] input_data_key = list(expect_data_format.keys())[0]
......
...@@ -28,7 +28,6 @@ import tarfile ...@@ -28,7 +28,6 @@ import tarfile
from paddlehub.common import utils from paddlehub.common import utils
from paddlehub.common.logger import logger from paddlehub.common.logger import logger
from paddlehub.io.reader import csv_reader
__all__ = ['Downloader'] __all__ = ['Downloader']
FLUSH_INTERVAL = 0.1 FLUSH_INTERVAL = 0.1
......
...@@ -22,7 +22,7 @@ import re ...@@ -22,7 +22,7 @@ import re
from paddlehub.common import utils from paddlehub.common import utils
from paddlehub.common.downloader import default_downloader from paddlehub.common.downloader import default_downloader
from paddlehub.io.reader import yaml_reader from paddlehub.io.parser import yaml_parser
import paddlehub as hub import paddlehub as hub
RESOURCE_LIST_FILE = "resource_list_file.yml" RESOURCE_LIST_FILE = "resource_list_file.yml"
...@@ -51,7 +51,7 @@ class HubServer: ...@@ -51,7 +51,7 @@ class HubServer:
if now_time - file_create_time >= CACHE_TIME: if now_time - file_create_time >= CACHE_TIME:
os.remove(self.resource_list_file_path()) os.remove(self.resource_list_file_path())
return False return False
for resource in yaml_reader.read( for resource in yaml_parser.parse(
self.resource_list_file_path())['resource_list']: self.resource_list_file_path())['resource_list']:
for key in resource: for key in resource:
if key not in self.resource_list_file: if key not in self.resource_list_file:
......
...@@ -15,14 +15,14 @@ ...@@ -15,14 +15,14 @@
import yaml import yaml
class CSVReader: class CSVFileParser:
def __init__(self): def __init__(self):
pass pass
def _check(self): def _check(self):
pass pass
def read(self, csv_file): def parse(self, csv_file):
with open(csv_file, "r") as file: with open(csv_file, "r") as file:
content = file.read() content = file.read()
content = content.split('\n') content = content.split('\n')
...@@ -42,18 +42,32 @@ class CSVReader: ...@@ -42,18 +42,32 @@ class CSVReader:
return self.content return self.content
class YAMLReader: class YAMLFileParser:
def __init__(self): def __init__(self):
pass pass
def _check(self): def _check(self):
pass pass
def read(self, yaml_file): def parse(self, yaml_file):
with open(yaml_file, "r") as file: with open(yaml_file, "r") as file:
content = file.read() content = file.read()
return yaml.load(content) return yaml.load(content)
yaml_reader = YAMLReader() class TextFileParser:
csv_reader = CSVReader() def __init__(self):
pass
def _check(self):
pass
def parse(self, yaml_file):
with open(yaml_file, "r") as file:
contents = file.read().split("\n")
return [content for content in contents if content]
csv_parser = CSVFileParser()
yaml_parser = YAMLFileParser()
txt_parser = TextFileParser()
...@@ -35,7 +35,7 @@ from paddlehub.module.signature import Signature, create_signature ...@@ -35,7 +35,7 @@ from paddlehub.module.signature import Signature, create_signature
from paddlehub.module.checker import ModuleChecker from paddlehub.module.checker import ModuleChecker
from paddlehub.module.manager import default_module_manager from paddlehub.module.manager import default_module_manager
from paddlehub.module.base_processor import BaseProcessor from paddlehub.module.base_processor import BaseProcessor
from paddlehub.io.reader import yaml_reader from paddlehub.io.parser import yaml_parser
from paddlehub import version from paddlehub import version
__all__ = ['Module', 'create_module'] __all__ = ['Module', 'create_module']
...@@ -267,7 +267,7 @@ class Module(object): ...@@ -267,7 +267,7 @@ class Module(object):
if not utils.is_yaml_file(module_info): if not utils.is_yaml_file(module_info):
logger.critical("module info file should in yaml format") logger.critical("module info file should in yaml format")
exit(1) exit(1)
self.module_info = yaml_reader.read(module_info) self.module_info = yaml_parser.parse(module_info)
self.author = self.module_info.get('author', 'UNKNOWN') self.author = self.module_info.get('author', 'UNKNOWN')
self.author_email = self.module_info.get('author_email', 'UNKNOWN') self.author_email = self.module_info.get('author_email', 'UNKNOWN')
self.summary = self.module_info.get('summary', 'UNKNOWN') self.summary = self.module_info.get('summary', 'UNKNOWN')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册