Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mikes zhang
001
提交
49af5ba0
0
001
项目概览
mikes zhang
/
001
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
0
001
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
49af5ba0
编写于
1月 07, 2019
作者:
Y
ysbecca
提交者:
GitHub
1月 07, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Conformed to Black standards
上级
f7aec996
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
26 addition
and
6 deletion
+26
-6
storing-images/storing_images.py
storing-images/storing_images.py
+26
-6
未找到文件。
storing-images/storing_images.py
浏览文件 @
49af5ba0
...
...
@@ -37,6 +37,7 @@ def unpickle(file):
dict
=
pickle
.
load
(
fo
,
encoding
=
"bytes"
)
return
dict
images
,
labels
=
[],
[]
for
batch
in
data_dir
.
glob
(
"data_batch_*"
):
batch_data
=
unpickle
(
batch
)
...
...
@@ -66,7 +67,8 @@ hdf5_dir = Path("data/hdf5/")
# Helper functions for timing
class
CIFAR_Image
():
class
CIFAR_Image
:
def
__init__
(
self
,
image
,
label
):
# Dimensions of image for reconstruction - not really necessary for this
# dataset, but some datasets may include images of varying sizes
...
...
@@ -81,6 +83,7 @@ class CIFAR_Image():
image
=
np
.
frombuffer
(
self
.
image
,
dtype
=
np
.
uint8
)
return
image
.
reshape
(
*
self
.
size
,
self
.
channels
)
def
store_single_disk
(
image
,
image_id
,
label
):
""" Stores a single image as a .png file on disk.
Parameters:
...
...
@@ -104,6 +107,7 @@ def store_single_disk(image, image_id, label):
)
writer
.
writerow
([
label
])
def
store_single_lmdb
(
image
,
image_id
,
label
):
""" Stores a single image to a LMDB.
Parameters:
...
...
@@ -128,6 +132,7 @@ def store_single_lmdb(image, image_id, label):
txn
.
put
(
key
.
encode
(
"ascii"
),
pickle
.
dumps
(
value
))
env
.
close
()
def
store_single_hdf5
(
image
,
image_id
,
label
):
""" Stores a single image to an HDF5 file.
Parameters:
...
...
@@ -155,6 +160,7 @@ def store_single_hdf5(image, image_id, label):
)
file
.
close
()
_store_single_funcs
=
dict
(
disk
=
store_single_disk
,
lmdb
=
store_single_lmdb
,
...
...
@@ -175,6 +181,7 @@ for method in ("disk", "lmdb", "hdf5"):
store_single_timings
[
method
]
=
t
print
(
f
"Method:
{
method
}
, Time usage:
{
t
}
"
)
def
store_many_disk
(
images
,
labels
):
""" Stores an array of images to disk
Parameters:
...
...
@@ -203,6 +210,7 @@ def store_many_disk(images, labels):
# value per row
writer
.
writerow
([
label
])
def
store_many_lmdb
(
images
,
labels
):
""" Stores an array of images to LMDB.
Parameters:
...
...
@@ -231,6 +239,7 @@ def store_many_lmdb(images, labels):
)
env
.
close
()
def
store_many_hdf5
(
images
,
labels
):
""" Stores an array of images to HDF5.
Parameters:
...
...
@@ -260,6 +269,7 @@ def store_many_hdf5(images, labels):
)
file
.
close
()
_store_many_funcs
=
dict
(
disk
=
store_many_disk
,
lmdb
=
store_many_lmdb
,
...
...
@@ -268,7 +278,7 @@ _store_many_funcs = dict(
# Run the multiple images experiment now
cutoffs
=
[
10
,
100
,
1000
,
10000
,
100000
]
cutoffs
=
[
10
,
100
,
1000
,
10000
,
100
_
000
]
# Let's double our images so that we have 100,000
images
=
np
.
concatenate
((
images
,
images
),
axis
=
0
)
...
...
@@ -294,6 +304,7 @@ for cutoff in cutoffs:
# Let's visualise those results
def
plot_with_legend
(
x_range
,
y_data
,
...
...
@@ -334,6 +345,7 @@ def plot_with_legend(
plt
.
legend
(
handles
=
all_plots
)
plt
.
show
()
disk_x
=
store_many_timings
[
"disk"
]
lmdb_x
=
store_many_timings
[
"lmdb"
]
hdf5_x
=
store_many_timings
[
"hdf5"
]
...
...
@@ -360,9 +372,9 @@ plot_with_legend(
# Visualise how much memory is used.
# Memory used in KB
disk_mem
=
[
44
,
404
,
4004
,
40032
,
400296
]
lmdb_mem
=
[
60
,
420
,
4000
,
39000
,
393000
]
hdf5_mem
=
[
36
,
304
,
2900
,
29000
,
293000
]
disk_mem
=
[
44
,
404
,
4004
,
40032
,
400
_
296
]
lmdb_mem
=
[
60
,
420
,
4000
,
39000
,
393
_
000
]
hdf5_mem
=
[
36
,
304
,
2900
,
29000
,
293
_
000
]
X
=
[
disk_mem
,
lmdb_mem
,
hdf5_mem
]
...
...
@@ -384,7 +396,7 @@ for i in range(1, len(cutoffs)):
plt
.
ylabel
(
"Memory in KB"
)
plt
.
title
(
"Disk memory used by method"
)
plt
.
xticks
(
ind
,
(
"PNG"
,
"LMDB"
,
"HDF5"
))
plt
.
yticks
(
np
.
arange
(
0
,
400
000
,
100
000
))
plt
.
yticks
(
np
.
arange
(
0
,
400
_000
,
100_
000
))
plt
.
legend
(
[
plot
[
0
]
for
plot
in
plots
],
...
...
@@ -394,6 +406,7 @@ plt.show()
# Read out a single image.
def
read_single_disk
(
image_id
):
""" Stores a single image to disk.
Parameters:
...
...
@@ -420,6 +433,7 @@ def read_single_disk(image_id):
return
image
,
label
def
read_single_lmdb
(
image_id
):
""" Stores a single image to LMDB.
Parameters:
...
...
@@ -450,6 +464,7 @@ def read_single_lmdb(image_id):
return
image
,
label
def
read_single_hdf5
(
image_id
):
""" Stores a single image to HDF5.
Parameters:
...
...
@@ -470,6 +485,7 @@ def read_single_hdf5(image_id):
return
image
,
label
_read_single_funcs
=
dict
(
disk
=
read_single_disk
,
lmdb
=
read_single_lmdb
,
...
...
@@ -490,6 +506,7 @@ for method in ("disk", "lmdb", "hdf5"):
# Reading in many images
def
read_many_disk
(
num_images
):
""" Reads image from disk.
Parameters:
...
...
@@ -524,6 +541,7 @@ def read_many_disk(num_images):
labels
.
append
(
int
(
row
[
0
]))
return
images
,
labels
def
read_many_lmdb
(
num_images
):
""" Reads image from LMDB.
Parameters:
...
...
@@ -554,6 +572,7 @@ def read_many_lmdb(num_images):
env
.
close
()
return
images
,
labels
def
read_many_hdf5
(
num_images
):
""" Reads image from HDF5.
Parameters:
...
...
@@ -577,6 +596,7 @@ def read_many_hdf5(num_images):
return
images
,
labels
_read_many_funcs
=
dict
(
disk
=
read_many_disk
,
lmdb
=
read_many_lmdb
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录