提交 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():
key = list(data_format.keys())[0]
# parse input file
test_csv = os.path.join("resources", "test", "test.csv")
test_text = hub.io.reader.csv_reader.read(test_csv)["TEXT_INPUT"]
test_file = os.path.join("resources", "test", "test.txt")
test_text = hub.io.parser.txt_parser.parse(test_file)
# set input dict
input_dict = {key: test_text}
......@@ -43,4 +43,4 @@ def infer_with_input_file():
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():
key = list(data_format.keys())[0]
# parse input file
test_csv = os.path.join("resources", "test", "test.csv")
test_text = hub.io.reader.csv_reader.read(test_csv)["TEXT_INPUT"]
test_file = os.path.join("resources", "test", "test.txt")
test_text = hub.io.parser.txt_parser.parse(test_file)
# set input dict
input_dict = {key: test_text}
......
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():
key = list(data_format.keys())[0]
# parse input file
test_csv = os.path.join("resources", "test", "test.csv")
test_images = hub.io.reader.csv_reader.read(test_csv)["IMAGE_PATH"]
test_file = os.path.join("resources", "test", "test.txt")
test_images = hub.io.parser.txt_parser.parse(test_file)
# set input dict
input_dict = {key: test_images}
......
IMAGE_PATH
./resources/test/test_img_sheep.jpg
./resources/test/test_img_cat.jpg
./resources/test/test_img_bird.jpg
......@@ -21,7 +21,7 @@ import os
from paddlehub.common.logger import logger
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.common import utils
from paddlehub.common.arg_helper import add_argument, print_arguments
......@@ -112,7 +112,8 @@ class RunCommand(BaseCommand):
input_data_key = list(expect_data_format.keys())[0]
origin_data = {input_data_key: [self.args.data]}
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:
print("ERROR! Please specify data to predict.\n")
print("Summary:\n %s\n" % module.summary)
......@@ -127,7 +128,7 @@ class RunCommand(BaseCommand):
input_data = {input_data_key: origin_data[origin_data_key]}
config = {}
else:
yaml_config = yaml_reader.read(self.args.config)
yaml_config = yaml_parser.parse(self.args.config)
if len(expect_data_format) == 1:
origin_data_key = list(origin_data.keys())[0]
input_data_key = list(expect_data_format.keys())[0]
......
......@@ -28,7 +28,6 @@ import tarfile
from paddlehub.common import utils
from paddlehub.common.logger import logger
from paddlehub.io.reader import csv_reader
__all__ = ['Downloader']
FLUSH_INTERVAL = 0.1
......
......@@ -22,7 +22,7 @@ import re
from paddlehub.common import utils
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
RESOURCE_LIST_FILE = "resource_list_file.yml"
......@@ -51,7 +51,7 @@ class HubServer:
if now_time - file_create_time >= CACHE_TIME:
os.remove(self.resource_list_file_path())
return False
for resource in yaml_reader.read(
for resource in yaml_parser.parse(
self.resource_list_file_path())['resource_list']:
for key in resource:
if key not in self.resource_list_file:
......
......@@ -15,14 +15,14 @@
import yaml
class CSVReader:
class CSVFileParser:
def __init__(self):
pass
def _check(self):
pass
def read(self, csv_file):
def parse(self, csv_file):
with open(csv_file, "r") as file:
content = file.read()
content = content.split('\n')
......@@ -42,18 +42,32 @@ class CSVReader:
return self.content
class YAMLReader:
class YAMLFileParser:
def __init__(self):
pass
def _check(self):
pass
def read(self, yaml_file):
def parse(self, yaml_file):
with open(yaml_file, "r") as file:
content = file.read()
return yaml.load(content)
yaml_reader = YAMLReader()
csv_reader = CSVReader()
class TextFileParser:
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
from paddlehub.module.checker import ModuleChecker
from paddlehub.module.manager import default_module_manager
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
__all__ = ['Module', 'create_module']
......@@ -267,7 +267,7 @@ class Module(object):
if not utils.is_yaml_file(module_info):
logger.critical("module info file should in yaml format")
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_email = self.module_info.get('author_email', '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.
先完成此消息的编辑!
想要评论请 注册