Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
46989e88
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
46989e88
编写于
1月 28, 2021
作者:
L
lidanqing
提交者:
GitHub
1月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix python3 incompatibility issues (#30698)
* solve python3 incompatibility issues * update checksum
上级
a12b6bb9
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
17 addition
and
21 deletion
+17
-21
paddle/fluid/inference/tests/api/full_ILSVRC2012_val_preprocess.py
...uid/inference/tests/api/full_ILSVRC2012_val_preprocess.py
+17
-21
未找到文件。
paddle/fluid/inference/tests/api/full_ILSVRC2012_val_preprocess.py
浏览文件 @
46989e88
...
...
@@ -13,6 +13,7 @@
import
hashlib
import
unittest
import
os
import
io
import
numpy
as
np
import
time
import
sys
...
...
@@ -23,10 +24,9 @@ from PIL import Image
import
math
from
paddle.dataset.common
import
download
import
tarfile
from
six.moves
import
StringIO
import
argparse
import
shutil
random
.
seed
(
0
)
np
.
random
.
seed
(
0
)
DATA_DIM
=
224
...
...
@@ -34,7 +34,7 @@ SIZE_FLOAT32 = 4
SIZE_INT64
=
8
FULL_SIZE_BYTES
=
30106000008
FULL_IMAGES
=
50000
TARGET_HASH
=
'
22d2e0008dca693916d9595a5ea3ded8
'
TARGET_HASH
=
'
0be07c2c23296b97dad83c626682c66a
'
FOLDER_NAME
=
"ILSVRC2012/"
VALLIST_TAR_NAME
=
"ILSVRC2012/val_list.txt"
CHUNK_SIZE
=
8192
...
...
@@ -55,8 +55,8 @@ def crop_image(img, target_size, center):
width
,
height
=
img
.
size
size
=
target_size
if
center
==
True
:
w_start
=
(
width
-
size
)
/
2
h_start
=
(
height
-
size
)
/
2
w_start
=
(
width
-
size
)
/
/
2
h_start
=
(
height
-
size
)
/
/
2
else
:
w_start
=
np
.
random
.
randint
(
0
,
width
-
size
+
1
)
h_start
=
np
.
random
.
randint
(
0
,
height
-
size
+
1
)
...
...
@@ -95,11 +95,9 @@ def download_concat(cache_folder, zip_path):
file_name
=
os
.
path
.
join
(
cache_folder
,
data_urls
[
i
].
split
(
'/'
)[
-
1
])
file_names
.
append
(
file_name
)
print
(
"Downloaded part {0}
\n
"
.
format
(
file_name
))
if
not
os
.
path
.
exists
(
zip_path
):
with
open
(
zip_path
,
"w+"
)
as
outfile
:
with
open
(
zip_path
,
"wb"
)
as
outfile
:
for
fname
in
file_names
:
with
open
(
fname
)
as
infile
:
outfile
.
write
(
infile
.
read
())
shutil
.
copyfileobj
(
open
(
fname
,
'rb'
),
outfile
)
def
print_processbar
(
done_percentage
):
...
...
@@ -114,12 +112,12 @@ def check_integrity(filename, target_hash):
print
(
'
\n
The binary file exists. Checking file integrity...
\n
'
)
md
=
hashlib
.
md5
()
count
=
0
onepart
=
FULL_SIZE_BYTES
/
CHUNK_SIZE
/
100
with
open
(
filename
)
as
ifs
:
onepart
=
FULL_SIZE_BYTES
/
/
CHUNK_SIZE
/
/
100
with
open
(
filename
,
'rb'
)
as
ifs
:
while
True
:
buf
=
ifs
.
read
(
CHUNK_SIZE
)
if
count
%
onepart
==
0
:
done
=
count
/
onepart
done
=
count
/
/
onepart
print_processbar
(
done
)
count
=
count
+
1
if
not
buf
:
...
...
@@ -142,28 +140,26 @@ def convert_Imagenet_tar2bin(tar_file, output_file):
for
tarInfo
in
tar
:
if
tarInfo
.
isfile
()
and
tarInfo
.
name
!=
VALLIST_TAR_NAME
:
dataset
[
tarInfo
.
name
]
=
tar
.
extractfile
(
tarInfo
).
read
()
with
open
(
output_file
,
"w+b"
)
as
ofs
:
ofs
.
seek
(
0
)
num
=
np
.
array
(
int
(
FULL_IMAGES
)).
astype
(
'int64'
)
ofs
.
write
(
num
.
tobytes
())
per_percentage
=
FULL_IMAGES
/
100
per_percentage
=
FULL_IMAGES
/
/
100
val_info
=
tar
.
getmember
(
VALLIST_TAR_NAME
)
val_list
=
tar
.
extractfile
(
val_info
).
read
().
decode
(
"utf-8"
)
lines
=
val_list
.
splitlines
()
idx
=
0
for
imagedata
in
dataset
.
values
():
img
=
Image
.
open
(
String
IO
(
imagedata
))
img
=
Image
.
open
(
io
.
Bytes
IO
(
imagedata
))
img
=
process_image
(
img
)
np_img
=
np
.
array
(
img
)
ofs
.
write
(
np_img
.
astype
(
'float32'
).
tobytes
())
if
idx
%
per_percentage
==
0
:
print_processbar
(
idx
/
per_percentage
)
print_processbar
(
idx
/
/
per_percentage
)
idx
=
idx
+
1
val_info
=
tar
.
getmember
(
VALLIST_TAR_NAME
)
val_list
=
tar
.
extractfile
(
val_info
).
read
()
lines
=
val_list
.
split
(
'
\n
'
)
val_dict
=
{}
for
line_idx
,
line
in
enumerate
(
lines
):
if
line_idx
==
FULL_IMAGES
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录