Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
477c4446
Commit
477c4446
authored
Feb 04, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add prefetch
parent
d4484474
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
tensorpack/dataflow/imgaug/__init__.py
tensorpack/dataflow/imgaug/__init__.py
+2
-0
tensorpack/dataflow/prefetch.py
tensorpack/dataflow/prefetch.py
+50
-0
No files found.
tensorpack/dataflow/imgaug/__init__.py
View file @
477c4446
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
import
os
import
os
from
pkgutil
import
walk_packages
from
pkgutil
import
walk_packages
__all__
=
[]
def
global_import
(
name
):
def
global_import
(
name
):
p
=
__import__
(
name
,
globals
(),
locals
())
p
=
__import__
(
name
,
globals
(),
locals
())
lst
=
p
.
__all__
if
'__all__'
in
dir
(
p
)
else
dir
(
p
)
lst
=
p
.
__all__
if
'__all__'
in
dir
(
p
)
else
dir
(
p
)
...
...
tensorpack/dataflow/prefetch.py
0 → 100644
View file @
477c4446
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: prefetch.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
from
.base
import
DataFlow
import
multiprocessing
__all__
=
[
'PrefetchData'
]
class
PrefetchProcess
(
multiprocessing
.
Process
):
def
__init__
(
self
,
ds
,
queue_size
):
super
(
PrefetchProcess
,
self
)
.
__init__
()
self
.
ds
=
ds
self
.
queue
=
multiprocessing
.
Queue
(
queue_size
)
class
Sentinel
:
pass
self
.
sentinel
=
Sentinel
()
def
run
(
self
):
for
dp
in
self
.
ds
.
get_data
():
self
.
queue
.
put
(
dp
)
self
.
queue
.
put
(
self
.
sentinel
)
def
get_data
(
self
):
while
True
:
ret
=
self
.
queue
.
get
()
if
ret
is
self
.
sentinel
:
return
yield
ret
class
PrefetchData
(
DataFlow
):
def
__init__
(
self
,
ds
,
nr_prefetch
):
self
.
ds
=
ds
self
.
nr_prefetch
=
int
(
nr_prefetch
)
assert
self
.
nr_prefetch
>
0
def
size
(
self
):
return
self
.
ds
.
size
()
def
get_data
(
self
):
worker
=
PrefetchProcess
(
self
.
ds
,
self
.
nr_prefetch
)
# TODO register terminate function
worker
.
start
()
for
dp
in
worker
.
get_data
():
yield
dp
worker
.
join
()
worker
.
terminate
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment