提交 29d4dc9a 编写于 作者: R root 提交者: Tingquan Gao

fix: rm sys.path.append in main python file

avoid to raising error when there is a foler or python file that has same name in working directory
上级 0b1c8e93
...@@ -2,7 +2,6 @@ include LICENSE.txt ...@@ -2,7 +2,6 @@ include LICENSE.txt
include README.md include README.md
include docs/en/whl_en.md include docs/en/whl_en.md
recursive-include deploy/python *.py recursive-include deploy/python *.py
recursive-include deploy/configs *.yaml recursive-include deploy/utils *.py
recursive-include deploy/utils get_image_list.py config.py logger.py predictor.py recursive-include ppcls/ *.py *.txt
recursive-include deploy/configs *.yaml
recursive-include ppcls/ *.py *.txt \ No newline at end of file
\ No newline at end of file
...@@ -11,21 +11,15 @@ ...@@ -11,21 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os
import sys
__dir__ = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.abspath(os.path.join(__dir__, '../')))
import cv2 import cv2
import numpy as np import numpy as np
from utils import logger from paddleclas.deploy.utils import logger, config
from utils import config from paddleclas.deploy.utils.predictor import Predictor
from utils.predictor import Predictor from paddleclas.deploy.utils.get_image_list import get_image_list
from utils.get_image_list import get_image_list from paddleclas.deploy.python.preprocess import create_operators
from python.preprocess import create_operators from paddleclas.deploy.python.postprocess import build_postprocess
from python.postprocess import build_postprocess
class ClsPredictor(Predictor): class ClsPredictor(Predictor):
......
...@@ -27,9 +27,8 @@ import cv2 ...@@ -27,9 +27,8 @@ import cv2
import numpy as np import numpy as np
import importlib import importlib
from PIL import Image from PIL import Image
from paddle.vision.transforms import ToTensor, Normalize
from python.det_preprocess import DetNormalizeImage, DetPadStride, DetPermute, DetResize from .det_preprocess import DetNormalizeImage, DetPadStride, DetPermute, DetResize
def create_operators(params): def create_operators(params):
...@@ -54,14 +53,13 @@ def create_operators(params): ...@@ -54,14 +53,13 @@ def create_operators(params):
class UnifiedResize(object): class UnifiedResize(object):
def __init__(self, interpolation=None, backend="cv2", return_numpy=True): def __init__(self, interpolation=None, backend="cv2"):
_cv2_interp_from_str = { _cv2_interp_from_str = {
'nearest': cv2.INTER_NEAREST, 'nearest': cv2.INTER_NEAREST,
'bilinear': cv2.INTER_LINEAR, 'bilinear': cv2.INTER_LINEAR,
'area': cv2.INTER_AREA, 'area': cv2.INTER_AREA,
'bicubic': cv2.INTER_CUBIC, 'bicubic': cv2.INTER_CUBIC,
'lanczos': cv2.INTER_LANCZOS4, 'lanczos': cv2.INTER_LANCZOS4
'random': (cv2.INTER_LINEAR, cv2.INTER_CUBIC)
} }
_pil_interp_from_str = { _pil_interp_from_str = {
'nearest': Image.NEAREST, 'nearest': Image.NEAREST,
...@@ -69,26 +67,13 @@ class UnifiedResize(object): ...@@ -69,26 +67,13 @@ class UnifiedResize(object):
'bicubic': Image.BICUBIC, 'bicubic': Image.BICUBIC,
'box': Image.BOX, 'box': Image.BOX,
'lanczos': Image.LANCZOS, 'lanczos': Image.LANCZOS,
'hamming': Image.HAMMING, 'hamming': Image.HAMMING
'random': (Image.BILINEAR, Image.BICUBIC)
} }
def _cv2_resize(src, size, resample): def _pil_resize(src, size, resample):
if isinstance(resample, tuple): pil_img = Image.fromarray(src)
resample = random.choice(resample)
return cv2.resize(src, size, interpolation=resample)
def _pil_resize(src, size, resample, return_numpy=True):
if isinstance(resample, tuple):
resample = random.choice(resample)
if isinstance(src, np.ndarray):
pil_img = Image.fromarray(src)
else:
pil_img = src
pil_img = pil_img.resize(size, resample) pil_img = pil_img.resize(size, resample)
if return_numpy: return np.asarray(pil_img)
return np.asarray(pil_img)
return pil_img
if backend.lower() == "cv2": if backend.lower() == "cv2":
if isinstance(interpolation, str): if isinstance(interpolation, str):
...@@ -96,12 +81,11 @@ class UnifiedResize(object): ...@@ -96,12 +81,11 @@ class UnifiedResize(object):
# compatible with opencv < version 4.4.0 # compatible with opencv < version 4.4.0
elif interpolation is None: elif interpolation is None:
interpolation = cv2.INTER_LINEAR interpolation = cv2.INTER_LINEAR
self.resize_func = partial(_cv2_resize, resample=interpolation) self.resize_func = partial(cv2.resize, interpolation=interpolation)
elif backend.lower() == "pil": elif backend.lower() == "pil":
if isinstance(interpolation, str): if isinstance(interpolation, str):
interpolation = _pil_interp_from_str[interpolation.lower()] interpolation = _pil_interp_from_str[interpolation.lower()]
self.resize_func = partial( self.resize_func = partial(_pil_resize, resample=interpolation)
_pil_resize, resample=interpolation, return_numpy=return_numpy)
else: else:
logger.warning( logger.warning(
f"The backend of Resize only support \"cv2\" or \"PIL\". \"f{backend}\" is unavailable. Use \"cv2\" instead." f"The backend of Resize only support \"cv2\" or \"PIL\". \"f{backend}\" is unavailable. Use \"cv2\" instead."
...@@ -109,8 +93,6 @@ class UnifiedResize(object): ...@@ -109,8 +93,6 @@ class UnifiedResize(object):
self.resize_func = cv2.resize self.resize_func = cv2.resize
def __call__(self, src, size): def __call__(self, src, size):
if isinstance(size, list):
size = tuple(size)
return self.resize_func(src, size) return self.resize_func(src, size)
...@@ -155,8 +137,7 @@ class ResizeImage(object): ...@@ -155,8 +137,7 @@ class ResizeImage(object):
size=None, size=None,
resize_short=None, resize_short=None,
interpolation=None, interpolation=None,
backend="cv2", backend="cv2"):
return_numpy=True):
if resize_short is not None and resize_short > 0: if resize_short is not None and resize_short > 0:
self.resize_short = resize_short self.resize_short = resize_short
self.w = None self.w = None
...@@ -170,18 +151,10 @@ class ResizeImage(object): ...@@ -170,18 +151,10 @@ class ResizeImage(object):
'both 'size' and 'resize_short' are None") 'both 'size' and 'resize_short' are None")
self._resize_func = UnifiedResize( self._resize_func = UnifiedResize(
interpolation=interpolation, interpolation=interpolation, backend=backend)
backend=backend,
return_numpy=return_numpy)
def __call__(self, img): def __call__(self, img):
if isinstance(img, np.ndarray): img_h, img_w = img.shape[:2]
# numpy input
img_h, img_w = img.shape[:2]
else:
# PIL image input
img_w, img_h = img.size
if self.resize_short is not None: if self.resize_short is not None:
percent = float(self.resize_short) / min(img_w, img_h) percent = float(self.resize_short) / min(img_w, img_h)
w = int(round(img_w * percent)) w = int(round(img_w * percent))
......
...@@ -17,7 +17,7 @@ import copy ...@@ -17,7 +17,7 @@ import copy
import argparse import argparse
import yaml import yaml
from utils import logger from . import logger
__all__ = ['get_config'] __all__ = ['get_config']
......
...@@ -16,7 +16,6 @@ import os ...@@ -16,7 +16,6 @@ import os
import sys import sys
__dir__ = os.path.dirname(__file__) __dir__ = os.path.dirname(__file__)
sys.path.append(os.path.join(__dir__, "")) sys.path.append(os.path.join(__dir__, ""))
sys.path.append(os.path.join(__dir__, "deploy"))
from typing import Union, Generator from typing import Union, Generator
import argparse import argparse
...@@ -33,12 +32,16 @@ from tqdm import tqdm ...@@ -33,12 +32,16 @@ from tqdm import tqdm
from prettytable import PrettyTable from prettytable import PrettyTable
import paddle import paddle
import ppcls.arch.backbone as backbone
from ppcls.utils import logger
from deploy.python.predict_cls import ClsPredictor from deploy.python.predict_cls import ClsPredictor
from deploy.utils.get_image_list import get_image_list from deploy.utils.get_image_list import get_image_list
from deploy.utils import config from deploy.utils import config
import ppcls.arch.backbone as backbone import deploy
from ppcls.utils import logger import ppcls
# 'deploy.python', 'deploy.utils', 'ppcls.arch', 'ppcls.utils'
# for building model with loading pretrained weights from backbone # for building model with loading pretrained weights from backbone
logger.init_logger() logger.init_logger()
......
...@@ -33,7 +33,7 @@ setup( ...@@ -33,7 +33,7 @@ setup(
package_dir={'paddleclas': ''}, package_dir={'paddleclas': ''},
include_package_data=True, include_package_data=True,
entry_points={ entry_points={
"console_scripts": ["paddleclas= paddleclas.paddleclas:main"] "console_scripts": ["paddleclas=paddleclas.paddleclas:main"]
}, },
version='0.0.0', version='0.0.0',
install_requires=requirements, install_requires=requirements,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册