Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
b806e3fd
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b806e3fd
编写于
10月 18, 2021
作者:
F
felixhjh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify detection examples preprocess
上级
9da9c19c
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
203 addition
and
105 deletion
+203
-105
python/examples/cascade_rcnn/test_client.py
python/examples/cascade_rcnn/test_client.py
+10
-7
python/examples/detection/faster_rcnn_hrnetv2p_w18_1x/README.md
.../examples/detection/faster_rcnn_hrnetv2p_w18_1x/README.md
+1
-1
python/examples/detection/faster_rcnn_hrnetv2p_w18_1x/test_client.py
...ples/detection/faster_rcnn_hrnetv2p_w18_1x/test_client.py
+9
-6
python/examples/detection/faster_rcnn_r50_fpn_1x_coco/test_client.py
...ples/detection/faster_rcnn_r50_fpn_1x_coco/test_client.py
+11
-8
python/examples/detection/fcos_dcn_r50_fpn_1x_coco/test_client.py
...xamples/detection/fcos_dcn_r50_fpn_1x_coco/test_client.py
+13
-8
python/examples/detection/ppyolo_r50vd_dcn_1x_coco/test_client.py
...xamples/detection/ppyolo_r50vd_dcn_1x_coco/test_client.py
+9
-7
python/examples/detection/ssd_vgg16_300_240e_voc/test_client.py
.../examples/detection/ssd_vgg16_300_240e_voc/test_client.py
+13
-9
python/examples/detection/yolov3_darknet53_270e_coco/test_client.py
...mples/detection/yolov3_darknet53_270e_coco/test_client.py
+10
-7
python/examples/yolov4/test_client.py
python/examples/yolov4/test_client.py
+1
-1
python/paddle_serving_app/reader/image_reader.py
python/paddle_serving_app/reader/image_reader.py
+126
-51
未找到文件。
python/examples/cascade_rcnn/test_client.py
浏览文件 @
b806e3fd
...
...
@@ -17,27 +17,30 @@ import numpy as np
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
cv2
preprocess
=
Sequential
([
File2Image
(),
BGR2RGB
(),
Resize
(
(
608
,
608
),
interpolation
=
cv2
.
INTER_LINEAR
),
Div
(
255.0
),
Transpose
(
(
2
,
0
,
1
))
File2Image
(),
Resize
((
800
,
1333
),
True
,
interpolation
=
2
),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
True
),
Transpose
((
2
,
0
,
1
)),
PadStride
(
32
)
])
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
,
[
608
,
608
]
)
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
)
client
=
Client
()
client
.
load_client_config
(
"serving_client/serving_client_conf.prototxt"
)
client
.
connect
([
'127.0.0.1:9292'
])
im
=
preprocess
(
'000000570688.jpg'
)
im
,
im_info
=
preprocess
(
sys
.
argv
[
1
]
)
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
"im_shape"
:
np
.
array
(
list
(
im
.
shape
[
1
:])).
reshape
(
-
1
),
"scale_factor"
:
np
.
array
([
1.0
,
1.0
]).
reshape
(
-
1
)
,
"scale_factor"
:
im_info
[
'scale_factor'
]
,
},
fetch
=
[
"save_infer_model/scale_0.tmp_1"
],
batch
=
False
)
print
(
fetch_map
)
fetch_map
[
"image"
]
=
'000000570688.jpg'
fetch_map
[
"image"
]
=
sys
.
argv
[
1
]
postprocess
(
fetch_map
)
python/examples/detection/faster_rcnn_hrnetv2p_w18_1x/README.md
浏览文件 @
b806e3fd
...
...
@@ -9,7 +9,7 @@ wget --no-check-certificate https://paddle-serving.bj.bcebos.com/pddet_demo/fast
### Start the service
```
tar xf faster_rcnn_hrnetv2p_w18_1x.tar
tar xf faster_rcnn_hrnetv2p_w18_1x.tar
.gz
python3 -m paddle_serving_server.serve --model serving_server --port 9494 --gpu_ids 0
```
...
...
python/examples/detection/faster_rcnn_hrnetv2p_w18_1x/test_client.py
浏览文件 @
b806e3fd
...
...
@@ -17,24 +17,27 @@ import numpy as np
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
cv2
preprocess
=
Sequential
([
File2Image
(),
BGR2RGB
(),
Resize
(
(
608
,
608
),
interpolation
=
cv2
.
INTER_LINEAR
),
Div
(
255.0
),
Transpose
(
(
2
,
0
,
1
))
File2Image
(),
Resize
((
800
,
1333
),
True
,
interpolation
=
2
),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
True
),
Transpose
((
2
,
0
,
1
)),
PadStride
(
32
)
])
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
,
[
608
,
608
]
)
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
)
client
=
Client
()
client
.
load_client_config
(
"serving_client/serving_client_conf.prototxt"
)
client
.
connect
([
'127.0.0.1:9494'
])
im
=
preprocess
(
sys
.
argv
[
1
])
im
,
im_info
=
preprocess
(
sys
.
argv
[
1
])
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
"im_shape"
:
np
.
array
(
list
(
im
.
shape
[
1
:])).
reshape
(
-
1
),
"scale_factor"
:
np
.
array
([
1.0
,
1.0
]).
reshape
(
-
1
)
,
"scale_factor"
:
im_info
[
'scale_factor'
]
,
},
fetch
=
[
"save_infer_model/scale_0.tmp_1"
],
batch
=
False
)
...
...
python/examples/detection/faster_rcnn_r50_fpn_1x_coco/test_client.py
浏览文件 @
b806e3fd
...
...
@@ -12,15 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
sys
import
numpy
as
np
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
cv2
preprocess
=
Sequential
([
File2Image
(),
BGR2RGB
(),
Div
(
255.0
),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
False
),
Resize
(
640
,
640
),
Transpose
((
2
,
0
,
1
))
File2Image
(),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
True
),
Resize
(
(
800
,
1333
),
True
,
interpolation
=
cv2
.
INTER_LINEAR
),
Transpose
((
2
,
0
,
1
)),
PadStride
(
128
)
])
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
)
...
...
@@ -29,15 +33,14 @@ client = Client()
client
.
load_client_config
(
"serving_client/serving_client_conf.prototxt"
)
client
.
connect
([
'127.0.0.1:9494'
])
im
=
preprocess
(
sys
.
argv
[
1
])
im
,
im_info
=
preprocess
(
sys
.
argv
[
1
])
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
"im_shape"
:
np
.
array
(
list
(
im
.
shape
[
1
:])).
reshape
(
-
1
),
"scale_factor"
:
np
.
array
([
1.0
,
1.0
]).
reshape
(
-
1
)
,
"scale_factor"
:
im_info
[
'scale_factor'
]
,
},
fetch
=
[
"save_infer_model/scale_0.tmp_1"
],
batch
=
False
)
print
(
fetch_map
)
fetch_map
[
"image"
]
=
sys
.
argv
[
1
]
postprocess
(
fetch_map
)
python/examples/detection/fcos_dcn_r50_fpn_1x_coco/test_client.py
浏览文件 @
b806e3fd
...
...
@@ -12,15 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
sys
import
numpy
as
np
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
cv2
preprocess
=
Sequential
([
File2Image
(),
BGR2RGB
(),
Div
(
255.0
),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
False
),
Resize
(
640
,
640
),
Transpose
((
2
,
0
,
1
))
File2Image
(),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
True
),
Resize
(
(
800
,
1333
),
True
,
interpolation
=
cv2
.
INTER_LINEAR
),
Transpose
((
2
,
0
,
1
)),
PadStride
(
128
)
])
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
)
...
...
@@ -29,12 +33,13 @@ client = Client()
client
.
load_client_config
(
"serving_client/serving_client_conf.prototxt"
)
client
.
connect
([
'127.0.0.1:9494'
])
im
=
preprocess
(
sys
.
argv
[
1
])
im
,
im_info
=
preprocess
(
sys
.
argv
[
1
])
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
"scale_factor"
:
np
.
array
([
1.0
,
1.0
]).
reshape
(
-
1
)
,
"scale_factor"
:
im_info
[
'scale_factor'
]
,
},
fetch
=
[
"save_infer_model/scale_0.tmp_1"
],
batch
=
False
)
print
(
fetch_map
)
fetch_map
[
"image"
]
=
sys
.
argv
[
1
]
postprocess
(
fetch_map
)
python/examples/detection/ppyolo_r50vd_dcn_1x_coco/test_client.py
浏览文件 @
b806e3fd
...
...
@@ -17,27 +17,29 @@ import numpy as np
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
cv2
preprocess
=
Sequential
([
File2Image
(),
BGR2RGB
(),
Resize
(
(
608
,
608
),
interpolation
=
cv2
.
INTER_LINEAR
),
Div
(
255.0
),
Transpose
(
(
2
,
0
,
1
))
File2Image
(),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
True
),
Resize
(
(
608
,
608
),
False
,
interpolation
=
2
),
Transpose
((
2
,
0
,
1
))
])
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
,
[
608
,
608
]
)
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
)
client
=
Client
()
client
.
load_client_config
(
"serving_client/serving_client_conf.prototxt"
)
client
.
connect
([
'127.0.0.1:9494'
])
im
=
preprocess
(
sys
.
argv
[
1
])
im
,
im_info
=
preprocess
(
sys
.
argv
[
1
])
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
"im_shape"
:
np
.
array
(
list
(
im
.
shape
[
1
:])).
reshape
(
-
1
),
"scale_factor"
:
np
.
array
([
1.0
,
1.0
]).
reshape
(
-
1
)
,
"scale_factor"
:
im_info
[
'scale_factor'
]
,
},
fetch
=
[
"save_infer_model/scale_0.tmp_1"
],
batch
=
False
)
print
(
fetch_map
)
fetch_map
[
"image"
]
=
sys
.
argv
[
1
]
postprocess
(
fetch_map
)
python/examples/detection/ssd_vgg16_300_240e_voc/test_client.py
浏览文件 @
b806e3fd
...
...
@@ -12,15 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
sys
import
numpy
as
np
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
cv2
preprocess
=
Sequential
([
File2Image
(),
BGR2RGB
(),
Normalize
([
123.675
,
116.28
,
103.53
],
[
58.395
,
57.12
,
57.375
],
False
),
Resize
((
512
,
512
)),
Transpose
((
2
,
0
,
1
))
File2Image
(),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
True
),
Resize
(
(
800
,
1333
),
True
,
interpolation
=
cv2
.
INTER_LINEAR
),
Transpose
((
2
,
0
,
1
)),
PadStride
(
128
)
])
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
)
...
...
@@ -29,13 +33,13 @@ client = Client()
client
.
load_client_config
(
"serving_client/serving_client_conf.prototxt"
)
client
.
connect
([
'127.0.0.1:9494'
])
im
=
preprocess
(
sys
.
argv
[
1
])
im
,
im_info
=
preprocess
(
sys
.
argv
[
1
])
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
"im_shape"
:
np
.
array
([
512
,
512
]),
"scale_factor"
:
np
.
array
([
1.0
,
1.0
]).
reshape
(
-
1
),
"scale_factor"
:
im_info
[
'scale_factor'
],
},
fetch
=
[
"save_infer_model/scale_0.tmp_1"
],
batch
=
False
)
print
(
fetch_map
)
fetch_map
[
"image"
]
=
sys
.
argv
[
1
]
postprocess
(
fetch_map
)
python/examples/detection/yolov3_darknet53_270e_coco/test_client.py
浏览文件 @
b806e3fd
...
...
@@ -17,27 +17,30 @@ import numpy as np
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
cv2
preprocess
=
Sequential
([
File2Image
(),
BGR2RGB
(),
Resize
(
(
608
,
608
),
interpolation
=
cv2
.
INTER_LINEAR
),
Div
(
255.0
),
Transpose
(
(
2
,
0
,
1
))
File2Image
(),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
True
),
Resize
(
(
800
,
1333
),
True
,
interpolation
=
cv2
.
INTER_LINEAR
),
Transpose
((
2
,
0
,
1
)),
PadStride
(
128
)
])
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
,
[
608
,
608
]
)
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
)
client
=
Client
()
client
.
load_client_config
(
"serving_client/serving_client_conf.prototxt"
)
client
.
connect
([
'127.0.0.1:9494'
])
im
=
preprocess
(
sys
.
argv
[
1
])
im
,
im_info
=
preprocess
(
sys
.
argv
[
1
])
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
"im_shape"
:
np
.
array
(
list
(
im
.
shape
[
1
:])).
reshape
(
-
1
),
"scale_factor"
:
np
.
array
([
1.0
,
1.0
]).
reshape
(
-
1
)
,
"scale_factor"
:
im_info
[
'scale_factor'
]
,
},
fetch
=
[
"save_infer_model/scale_0.tmp_1"
],
batch
=
False
)
print
(
fetch_map
)
fetch_map
[
"image"
]
=
sys
.
argv
[
1
]
postprocess
(
fetch_map
)
python/examples/yolov4/test_client.py
浏览文件 @
b806e3fd
...
...
@@ -29,7 +29,7 @@ client = Client()
client
.
load_client_config
(
"yolov4_client/serving_client_conf.prototxt"
)
client
.
connect
([
'127.0.0.1:9393'
])
im
=
preprocess
(
sys
.
argv
[
1
])
im
,
im_info
=
preprocess
(
sys
.
argv
[
1
])
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
...
...
python/paddle_serving_app/reader/image_reader.py
浏览文件 @
b806e3fd
...
...
@@ -484,10 +484,15 @@ class Sequential(object):
def
__init__
(
self
,
transforms
):
self
.
transforms
=
transforms
def
__call__
(
self
,
img
):
def
__call__
(
self
,
im
):
im_info
=
{
'scale_factor'
:
np
.
array
(
[
1.
,
1.
],
dtype
=
np
.
float32
),
'im_shape'
:
None
,
}
for
t
in
self
.
transforms
:
im
g
=
t
(
img
)
return
im
g
im
,
im_info
=
t
(
im
,
im_info
)
return
im
,
im_info
def
__repr__
(
self
):
format_string_
=
self
.
__class__
.
__name__
+
'('
...
...
@@ -513,8 +518,8 @@ class BGR2RGB(object):
def
__init__
(
self
):
pass
def
__call__
(
self
,
img
):
return
img
[:,
:,
::
-
1
]
def
__call__
(
self
,
img
,
img_info
=
False
):
return
img
[:,
:,
::
-
1
]
,
img_info
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
+
"()"
...
...
@@ -537,7 +542,7 @@ class File2Image(object):
def
__init__
(
self
):
pass
def
__call__
(
self
,
img_path
):
def
__call__
(
self
,
img_path
,
im_info
):
if
py_version
==
2
:
fin
=
open
(
img_path
)
else
:
...
...
@@ -545,13 +550,16 @@ class File2Image(object):
sample
=
fin
.
read
()
data
=
np
.
fromstring
(
sample
,
np
.
uint8
)
img
=
cv2
.
imdecode
(
data
,
cv2
.
IMREAD_COLOR
)
img
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2RGB
)
'''
img = cv2.imread(img_path, -1)
channels = img.shape[2]
ori_h = img.shape[0]
ori_w = img.shape[1]
'''
return
img
im_info
[
'im_shape'
]
=
np
.
array
(
img
.
shape
[:
2
],
dtype
=
np
.
float32
)
im_info
[
'scale_factor'
]
=
np
.
array
([
1.
,
1.
],
dtype
=
np
.
float32
)
return
img
,
im_info
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
+
"()"
...
...
@@ -592,7 +600,7 @@ class Div(object):
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__call__
(
self
,
img
):
def
__call__
(
self
,
img
,
img_info
=
False
):
"""
Args:
img (numpy array): (int8 numpy array)
...
...
@@ -602,7 +610,7 @@ class Div(object):
"""
img
=
img
.
astype
(
'float32'
)
/
self
.
value
return
img
return
img
,
img_info
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
+
"({})"
.
format
(
self
.
value
)
...
...
@@ -620,23 +628,33 @@ class Normalize(object):
Args:
mean (sequence): Sequence of means for each channel.
std (sequence): Sequence of standard deviations for each channel.
is_scale (bool): whether need im / 255
"""
def
__init__
(
self
,
mean
,
std
,
channel_first
=
Fals
e
):
def
__init__
(
self
,
mean
,
std
,
is_scale
=
Tru
e
):
self
.
mean
=
mean
self
.
std
=
std
self
.
channel_first
=
channel_first
self
.
is_scale
=
is_scale
def
__call__
(
self
,
im
g
):
def
__call__
(
self
,
im
,
im_info
=
False
):
"""
Args:
im
g (numpy array): (C, H, W) to be normalized.
im
(np.ndarray): image (np.ndarray)
im_info (dict): info of image
Returns:
Tensor: Normalized Tensor image.
im (np.ndarray): processed image (np.ndarray)
im_info (dict): info of processed image
"""
return
F
.
normalize
(
img
,
self
.
mean
,
self
.
std
,
self
.
channel_first
)
im
=
im
.
astype
(
np
.
float32
,
copy
=
False
)
mean
=
np
.
array
(
self
.
mean
)[
np
.
newaxis
,
np
.
newaxis
,
:]
std
=
np
.
array
(
self
.
std
)[
np
.
newaxis
,
np
.
newaxis
,
:]
if
self
.
is_scale
:
im
=
im
/
255.0
im
-=
mean
im
/=
std
return
im
,
im_info
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
+
'(mean={0}, std={1})'
.
format
(
self
.
mean
,
...
...
@@ -690,26 +708,72 @@ class CenterCrop(object):
return
self
.
__class__
.
__name__
+
'(size={0})'
.
format
(
self
.
size
)
class
Resize
(
object
):
"""Resize the input numpy array Image to the given size.
class
Resize
(
object
):
"""resize image by target_size and max_size
Args:
size (sequence or int): Desired output size. If size is a sequence like
(w, h), output size will be matched to this. If size is an int,
smaller edge of the image will be matched to this number.
i.e, if height > width, then image will be rescaled to
(size * height / width, size)
interpolation (int, optional): Desired interpolation. Default is
``None``
target_size (int): the target size of image
keep_ratio (bool): whether keep_ratio or not, default true
interp (int): method of resize
"""
def
__init__
(
self
,
size
,
max_size
=
2147483647
,
interpolation
=
None
):
self
.
size
=
size
self
.
max_size
=
max_size
def
__init__
(
self
,
target_size
,
keep_ratio
=
True
,
interpolation
=
cv2
.
INTER_LINEAR
):
if
isinstance
(
target_size
,
int
):
target_size
=
[
target_size
,
target_size
]
self
.
target_size
=
target_size
self
.
keep_ratio
=
keep_ratio
self
.
interpolation
=
interpolation
def
__call__
(
self
,
img
):
return
F
.
resize
(
img
,
self
.
size
,
self
.
max_size
,
self
.
interpolation
)
def
__call__
(
self
,
im
,
im_info
):
"""
Args:
im (np.ndarray): image (np.ndarray)
im_info (dict): info of image
Returns:
im (np.ndarray): processed image (np.ndarray)
im_info (dict): info of processed image
"""
assert
len
(
self
.
target_size
)
==
2
assert
self
.
target_size
[
0
]
>
0
and
self
.
target_size
[
1
]
>
0
im_channel
=
im
.
shape
[
2
]
im_scale_y
,
im_scale_x
=
self
.
generate_scale
(
im
)
im
=
cv2
.
resize
(
im
,
None
,
None
,
fx
=
im_scale_x
,
fy
=
im_scale_y
,
interpolation
=
self
.
interpolation
)
im_info
[
'im_shape'
]
=
np
.
array
(
im
.
shape
[:
2
]).
astype
(
'float32'
)
im_info
[
'scale_factor'
]
=
np
.
array
(
[
im_scale_y
,
im_scale_x
]).
astype
(
'float32'
)
return
im
,
im_info
def
generate_scale
(
self
,
im
):
"""
Args:
im (np.ndarray): image (np.ndarray)
Returns:
im_scale_x: the resize ratio of X
im_scale_y: the resize ratio of Y
"""
origin_shape
=
im
.
shape
[:
2
]
im_c
=
im
.
shape
[
2
]
if
self
.
keep_ratio
:
im_size_min
=
np
.
min
(
origin_shape
)
im_size_max
=
np
.
max
(
origin_shape
)
target_size_min
=
np
.
min
(
self
.
target_size
)
target_size_max
=
np
.
max
(
self
.
target_size
)
im_scale
=
float
(
target_size_min
)
/
float
(
im_size_min
)
if
np
.
round
(
im_scale
*
im_size_max
)
>
target_size_max
:
im_scale
=
float
(
target_size_max
)
/
float
(
im_size_max
)
im_scale_x
=
im_scale
im_scale_y
=
im_scale
else
:
resize_h
,
resize_w
=
self
.
target_size
im_scale_y
=
resize_h
/
float
(
origin_shape
[
0
])
im_scale_x
=
resize_w
/
float
(
origin_shape
[
1
])
return
im_scale_y
,
im_scale_x
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
+
'(size={0}, max_size={1}, interpolation={2})'
.
format
(
...
...
@@ -717,6 +781,35 @@ class Resize(object):
_cv2_interpolation_to_str
[
self
.
interpolation
])
class
PadStride
(
object
):
""" padding image for model with FPN, instead PadBatch(pad_to_stride) in original config
Args:
stride (bool): model with FPN need image shape % stride == 0
"""
def
__init__
(
self
,
stride
=
0
):
self
.
coarsest_stride
=
stride
def
__call__
(
self
,
im
,
im_info
=
False
):
"""
Args:
im (np.ndarray): image (np.ndarray)
im_info (dict): info of image
Returns:
im (np.ndarray): processed image (np.ndarray)
im_info (dict): info of processed image
"""
coarsest_stride
=
self
.
coarsest_stride
if
coarsest_stride
<=
0
:
return
im
im_c
,
im_h
,
im_w
=
im
.
shape
pad_h
=
int
(
np
.
ceil
(
float
(
im_h
)
/
coarsest_stride
)
*
coarsest_stride
)
pad_w
=
int
(
np
.
ceil
(
float
(
im_w
)
/
coarsest_stride
)
*
coarsest_stride
)
padding_im
=
np
.
zeros
((
im_c
,
pad_h
,
pad_w
),
dtype
=
np
.
float32
)
padding_im
[:,
:
im_h
,
:
im_w
]
=
im
return
padding_im
,
im_info
class
ResizeByFactor
(
object
):
"""Resize the input numpy array Image to a size multiple of factor which is usually required by a network
...
...
@@ -768,31 +861,13 @@ class ResizeByFactor(object):
self
.
factor
,
self
.
max_side_len
)
class
PadStride
(
object
):
def
__init__
(
self
,
stride
):
self
.
coarsest_stride
=
stride
def
__call__
(
self
,
img
):
coarsest_stride
=
self
.
coarsest_stride
if
coarsest_stride
==
0
:
return
img
im_c
,
im_h
,
im_w
=
img
.
shape
pad_h
=
int
(
np
.
ceil
(
float
(
im_h
)
/
coarsest_stride
)
*
coarsest_stride
)
pad_w
=
int
(
np
.
ceil
(
float
(
im_w
)
/
coarsest_stride
)
*
coarsest_stride
)
padding_im
=
np
.
zeros
((
im_c
,
pad_h
,
pad_w
),
dtype
=
np
.
float32
)
padding_im
[:,
:
im_h
,
:
im_w
]
=
img
im_info
=
{}
im_info
[
'resize_shape'
]
=
padding_im
.
shape
[
1
:]
return
padding_im
class
Transpose
(
object
):
def
__init__
(
self
,
transpose_target
):
self
.
transpose_target
=
transpose_target
def
__call__
(
self
,
im
g
):
return
F
.
transpose
(
img
,
self
.
transpose_target
)
return
im
g
def
__call__
(
self
,
im
,
im_info
=
False
):
im
=
F
.
transpose
(
im
,
self
.
transpose_target
)
return
im
,
im_info
def
__repr__
(
self
):
format_string
=
self
.
__class__
.
__name__
+
\
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录