未验证 提交 d8c1d824 编写于 作者: W Walter 提交者: GitHub

Merge pull request #1978 from HydrogenSulfate/add_reid_doc

add reid docs and images
......@@ -27,6 +27,7 @@ import cv2
import numpy as np
import importlib
from PIL import Image
from paddle.vision.transforms import ToTensor, Normalize
from python.det_preprocess import DetNormalizeImage, DetPadStride, DetPermute, DetResize
......@@ -53,13 +54,14 @@ def create_operators(params):
class UnifiedResize(object):
def __init__(self, interpolation=None, backend="cv2"):
def __init__(self, interpolation=None, backend="cv2", return_numpy=True):
_cv2_interp_from_str = {
'nearest': cv2.INTER_NEAREST,
'bilinear': cv2.INTER_LINEAR,
'area': cv2.INTER_AREA,
'bicubic': cv2.INTER_CUBIC,
'lanczos': cv2.INTER_LANCZOS4
'lanczos': cv2.INTER_LANCZOS4,
'random': (cv2.INTER_LINEAR, cv2.INTER_CUBIC)
}
_pil_interp_from_str = {
'nearest': Image.NEAREST,
......@@ -67,13 +69,26 @@ class UnifiedResize(object):
'bicubic': Image.BICUBIC,
'box': Image.BOX,
'lanczos': Image.LANCZOS,
'hamming': Image.HAMMING
'hamming': Image.HAMMING,
'random': (Image.BILINEAR, Image.BICUBIC)
}
def _pil_resize(src, size, resample):
def _cv2_resize(src, size, resample):
if isinstance(resample, tuple):
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)
if return_numpy:
return np.asarray(pil_img)
return pil_img
if backend.lower() == "cv2":
if isinstance(interpolation, str):
......@@ -81,11 +96,12 @@ class UnifiedResize(object):
# compatible with opencv < version 4.4.0
elif interpolation is None:
interpolation = cv2.INTER_LINEAR
self.resize_func = partial(cv2.resize, interpolation=interpolation)
self.resize_func = partial(_cv2_resize, resample=interpolation)
elif backend.lower() == "pil":
if isinstance(interpolation, str):
interpolation = _pil_interp_from_str[interpolation.lower()]
self.resize_func = partial(_pil_resize, resample=interpolation)
self.resize_func = partial(
_pil_resize, resample=interpolation, return_numpy=return_numpy)
else:
logger.warning(
f"The backend of Resize only support \"cv2\" or \"PIL\". \"f{backend}\" is unavailable. Use \"cv2\" instead."
......@@ -93,6 +109,8 @@ class UnifiedResize(object):
self.resize_func = cv2.resize
def __call__(self, src, size):
if isinstance(size, list):
size = tuple(size)
return self.resize_func(src, size)
......@@ -137,7 +155,8 @@ class ResizeImage(object):
size=None,
resize_short=None,
interpolation=None,
backend="cv2"):
backend="cv2",
return_numpy=True):
if resize_short is not None and resize_short > 0:
self.resize_short = resize_short
self.w = None
......@@ -151,10 +170,18 @@ class ResizeImage(object):
'both 'size' and 'resize_short' are None")
self._resize_func = UnifiedResize(
interpolation=interpolation, backend=backend)
interpolation=interpolation,
backend=backend,
return_numpy=return_numpy)
def __call__(self, img):
if isinstance(img, np.ndarray):
# 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:
percent = float(self.resize_short) / min(img_w, img_h)
w = int(round(img_w * percent))
......
此差异已折叠。
此差异已折叠。
......@@ -64,7 +64,7 @@ Optimizer:
by_epoch: True
last_epoch: 0
regularizer:
name: 'L2'
name: "L2"
coeff: 0.0005
# data loader for train and eval
......@@ -79,7 +79,7 @@ DataLoader:
- ResizeImage:
size: [128, 256]
return_numpy: False
interpolation: 'bilinear'
interpolation: "bilinear"
backend: "pil"
- RandFlipImage:
flip_code: 1
......@@ -111,7 +111,7 @@ DataLoader:
- ResizeImage:
size: [128, 256]
return_numpy: False
interpolation: 'bilinear'
interpolation: "bilinear"
backend: "pil"
- ToTensor:
- Normalize:
......@@ -136,7 +136,7 @@ DataLoader:
- ResizeImage:
size: [128, 256]
return_numpy: False
interpolation: 'bilinear'
interpolation: "bilinear"
backend: "pil"
- ToTensor:
- Normalize:
......
......@@ -76,7 +76,7 @@ Optimizer:
by_epoch: True
last_epoch: 0
regularizer:
name: 'L2'
name: "L2"
coeff: 0.0005
# data loader for train and eval
......@@ -91,7 +91,7 @@ DataLoader:
- ResizeImage:
size: [128, 256]
return_numpy: False
interpolation: 'bilinear'
interpolation: "bilinear"
backend: "pil"
- RandFlipImage:
flip_code: 1
......@@ -129,7 +129,7 @@ DataLoader:
- ResizeImage:
size: [128, 256]
return_numpy: False
interpolation: 'bilinear'
interpolation: "bilinear"
backend: "pil"
- ToTensor:
- Normalize:
......@@ -154,7 +154,7 @@ DataLoader:
- ResizeImage:
size: [128, 256]
return_numpy: False
interpolation: 'bilinear'
interpolation: "bilinear"
backend: "pil"
- ToTensor:
- Normalize:
......
......@@ -82,7 +82,7 @@ Optimizer:
by_epoch: True
last_epoch: 0
regularizer:
name: 'L2'
name: "L2"
coeff: 0.0005
- SGD:
scope: CenterLoss
......@@ -102,7 +102,7 @@ DataLoader:
- ResizeImage:
size: [128, 256]
return_numpy: False
interpolation: 'bilinear'
interpolation: "bilinear"
backend: "pil"
- RandFlipImage:
flip_code: 1
......@@ -140,7 +140,7 @@ DataLoader:
- ResizeImage:
size: [128, 256]
return_numpy: False
interpolation: 'bilinear'
interpolation: "bilinear"
backend: "pil"
- ToTensor:
- Normalize:
......@@ -165,7 +165,7 @@ DataLoader:
- ResizeImage:
size: [128, 256]
return_numpy: False
interpolation: 'bilinear'
interpolation: "bilinear"
backend: "pil"
- ToTensor:
- Normalize:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册