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 @@
...
@@ -13,6 +13,7 @@
import
hashlib
import
hashlib
import
unittest
import
unittest
import
os
import
os
import
io
import
numpy
as
np
import
numpy
as
np
import
time
import
time
import
sys
import
sys
...
@@ -23,10 +24,9 @@ from PIL import Image
...
@@ -23,10 +24,9 @@ from PIL import Image
import
math
import
math
from
paddle.dataset.common
import
download
from
paddle.dataset.common
import
download
import
tarfile
import
tarfile
from
six.moves
import
StringIO
import
argparse
import
argparse
import
shutil
random
.
seed
(
0
)
np
.
random
.
seed
(
0
)
np
.
random
.
seed
(
0
)
DATA_DIM
=
224
DATA_DIM
=
224
...
@@ -34,7 +34,7 @@ SIZE_FLOAT32 = 4
...
@@ -34,7 +34,7 @@ SIZE_FLOAT32 = 4
SIZE_INT64
=
8
SIZE_INT64
=
8
FULL_SIZE_BYTES
=
30106000008
FULL_SIZE_BYTES
=
30106000008
FULL_IMAGES
=
50000
FULL_IMAGES
=
50000
TARGET_HASH
=
'
22d2e0008dca693916d9595a5ea3ded8
'
TARGET_HASH
=
'
0be07c2c23296b97dad83c626682c66a
'
FOLDER_NAME
=
"ILSVRC2012/"
FOLDER_NAME
=
"ILSVRC2012/"
VALLIST_TAR_NAME
=
"ILSVRC2012/val_list.txt"
VALLIST_TAR_NAME
=
"ILSVRC2012/val_list.txt"
CHUNK_SIZE
=
8192
CHUNK_SIZE
=
8192
...
@@ -55,8 +55,8 @@ def crop_image(img, target_size, center):
...
@@ -55,8 +55,8 @@ def crop_image(img, target_size, center):
width
,
height
=
img
.
size
width
,
height
=
img
.
size
size
=
target_size
size
=
target_size
if
center
==
True
:
if
center
==
True
:
w_start
=
(
width
-
size
)
/
2
w_start
=
(
width
-
size
)
/
/
2
h_start
=
(
height
-
size
)
/
2
h_start
=
(
height
-
size
)
/
/
2
else
:
else
:
w_start
=
np
.
random
.
randint
(
0
,
width
-
size
+
1
)
w_start
=
np
.
random
.
randint
(
0
,
width
-
size
+
1
)
h_start
=
np
.
random
.
randint
(
0
,
height
-
size
+
1
)
h_start
=
np
.
random
.
randint
(
0
,
height
-
size
+
1
)
...
@@ -95,11 +95,9 @@ def download_concat(cache_folder, zip_path):
...
@@ -95,11 +95,9 @@ def download_concat(cache_folder, zip_path):
file_name
=
os
.
path
.
join
(
cache_folder
,
data_urls
[
i
].
split
(
'/'
)[
-
1
])
file_name
=
os
.
path
.
join
(
cache_folder
,
data_urls
[
i
].
split
(
'/'
)[
-
1
])
file_names
.
append
(
file_name
)
file_names
.
append
(
file_name
)
print
(
"Downloaded part {0}
\n
"
.
format
(
file_name
))
print
(
"Downloaded part {0}
\n
"
.
format
(
file_name
))
if
not
os
.
path
.
exists
(
zip_path
):
with
open
(
zip_path
,
"wb"
)
as
outfile
:
with
open
(
zip_path
,
"w+"
)
as
outfile
:
for
fname
in
file_names
:
for
fname
in
file_names
:
with
open
(
fname
)
as
infile
:
shutil
.
copyfileobj
(
open
(
fname
,
'rb'
),
outfile
)
outfile
.
write
(
infile
.
read
())
def
print_processbar
(
done_percentage
):
def
print_processbar
(
done_percentage
):
...
@@ -114,12 +112,12 @@ def check_integrity(filename, target_hash):
...
@@ -114,12 +112,12 @@ def check_integrity(filename, target_hash):
print
(
'
\n
The binary file exists. Checking file integrity...
\n
'
)
print
(
'
\n
The binary file exists. Checking file integrity...
\n
'
)
md
=
hashlib
.
md5
()
md
=
hashlib
.
md5
()
count
=
0
count
=
0
onepart
=
FULL_SIZE_BYTES
/
CHUNK_SIZE
/
100
onepart
=
FULL_SIZE_BYTES
/
/
CHUNK_SIZE
/
/
100
with
open
(
filename
)
as
ifs
:
with
open
(
filename
,
'rb'
)
as
ifs
:
while
True
:
while
True
:
buf
=
ifs
.
read
(
CHUNK_SIZE
)
buf
=
ifs
.
read
(
CHUNK_SIZE
)
if
count
%
onepart
==
0
:
if
count
%
onepart
==
0
:
done
=
count
/
onepart
done
=
count
/
/
onepart
print_processbar
(
done
)
print_processbar
(
done
)
count
=
count
+
1
count
=
count
+
1
if
not
buf
:
if
not
buf
:
...
@@ -142,28 +140,26 @@ def convert_Imagenet_tar2bin(tar_file, output_file):
...
@@ -142,28 +140,26 @@ def convert_Imagenet_tar2bin(tar_file, output_file):
for
tarInfo
in
tar
:
for
tarInfo
in
tar
:
if
tarInfo
.
isfile
()
and
tarInfo
.
name
!=
VALLIST_TAR_NAME
:
if
tarInfo
.
isfile
()
and
tarInfo
.
name
!=
VALLIST_TAR_NAME
:
dataset
[
tarInfo
.
name
]
=
tar
.
extractfile
(
tarInfo
).
read
()
dataset
[
tarInfo
.
name
]
=
tar
.
extractfile
(
tarInfo
).
read
()
with
open
(
output_file
,
"w+b"
)
as
ofs
:
with
open
(
output_file
,
"w+b"
)
as
ofs
:
ofs
.
seek
(
0
)
ofs
.
seek
(
0
)
num
=
np
.
array
(
int
(
FULL_IMAGES
)).
astype
(
'int64'
)
num
=
np
.
array
(
int
(
FULL_IMAGES
)).
astype
(
'int64'
)
ofs
.
write
(
num
.
tobytes
())
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
idx
=
0
for
imagedata
in
dataset
.
values
():
for
imagedata
in
dataset
.
values
():
img
=
Image
.
open
(
String
IO
(
imagedata
))
img
=
Image
.
open
(
io
.
Bytes
IO
(
imagedata
))
img
=
process_image
(
img
)
img
=
process_image
(
img
)
np_img
=
np
.
array
(
img
)
np_img
=
np
.
array
(
img
)
ofs
.
write
(
np_img
.
astype
(
'float32'
).
tobytes
())
ofs
.
write
(
np_img
.
astype
(
'float32'
).
tobytes
())
if
idx
%
per_percentage
==
0
:
if
idx
%
per_percentage
==
0
:
print_processbar
(
idx
/
per_percentage
)
print_processbar
(
idx
/
/
per_percentage
)
idx
=
idx
+
1
idx
=
idx
+
1
val_info
=
tar
.
getmember
(
VALLIST_TAR_NAME
)
val_list
=
tar
.
extractfile
(
val_info
).
read
()
lines
=
val_list
.
split
(
'
\n
'
)
val_dict
=
{}
val_dict
=
{}
for
line_idx
,
line
in
enumerate
(
lines
):
for
line_idx
,
line
in
enumerate
(
lines
):
if
line_idx
==
FULL_IMAGES
:
if
line_idx
==
FULL_IMAGES
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录