提交 f6a20bbd 编写于 作者: 走神的阿圆's avatar 走神的阿圆 提交者: wuzewu

Add check file (#233)

* add file checking when execute hub run
上级 90b45a00
......@@ -25,6 +25,8 @@ import ast
import six
import pandas
import imghdr
import cv2
import numpy as np
from paddlehub.commands.base_command import BaseCommand, ENTRY
......@@ -159,6 +161,8 @@ class RunCommand(BaseCommand):
self.args.use_strip)
else:
if module_type.startswith("cv"):
if hasattr(self.args, "input_path"):
self.check_file()
input_data[key] = [self.args.input_path]
elif module_type.startswith("nlp"):
input_data[key] = [self.args.input_text]
......@@ -201,6 +205,16 @@ class RunCommand(BaseCommand):
)
raise DataFormatError
def check_file(self):
file_path = self.args.input_path
if not os.path.exists(file_path):
raise RuntimeError("ERROR: File %s is not exist." % file_path)
if imghdr.what(file_path) is not None or \
cv2.VideoCapture(file_path).get(cv2.CAP_PROP_FRAME_COUNT) > 1:
return
raise RuntimeError("ERROR: Format of %s is illegal." % file_path)
def execute(self, argv):
if not argv:
print("ERROR: Please specify a module name.\n")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册