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
4d64098a
Commit
4d64098a
authored
Apr 21, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
selectcomponent
parent
27ea2836
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
tensorpack/dataflow/common.py
tensorpack/dataflow/common.py
+22
-2
tensorpack/dataflow/prefetch.py
tensorpack/dataflow/prefetch.py
+2
-4
No files found.
tensorpack/dataflow/common.py
View file @
4d64098a
...
@@ -65,7 +65,9 @@ class BatchData(ProxyDataFlow):
...
@@ -65,7 +65,9 @@ class BatchData(ProxyDataFlow):
return
result
return
result
class
FixedSizeData
(
ProxyDataFlow
):
class
FixedSizeData
(
ProxyDataFlow
):
""" Generate data from another DataFlow, but with a fixed epoch size"""
""" Generate data from another DataFlow, but with a fixed epoch size.
The state of the underlying DataFlow is maintained among each epoch.
"""
def
__init__
(
self
,
ds
,
size
):
def
__init__
(
self
,
ds
,
size
):
"""
"""
:param ds: a :mod:`DataFlow` to produce data
:param ds: a :mod:`DataFlow` to produce data
...
@@ -165,7 +167,7 @@ class MapDataComponent(ProxyDataFlow):
...
@@ -165,7 +167,7 @@ class MapDataComponent(ProxyDataFlow):
def
__init__
(
self
,
ds
,
func
,
index
=
0
):
def
__init__
(
self
,
ds
,
func
,
index
=
0
):
"""
"""
:param ds: a :mod:`DataFlow` instance.
:param ds: a :mod:`DataFlow` instance.
:param func: a function that takes a datapoint dp[index], returns a
:param func: a function that takes a datapoint
component
dp[index], returns a
new value of dp[index]. return None to skip this datapoint.
new value of dp[index]. return None to skip this datapoint.
"""
"""
super
(
MapDataComponent
,
self
)
.
__init__
(
ds
)
super
(
MapDataComponent
,
self
)
.
__init__
(
ds
)
...
@@ -269,3 +271,21 @@ class JoinData(DataFlow):
...
@@ -269,3 +271,21 @@ class JoinData(DataFlow):
for
dp
in
d
.
get_data
():
for
dp
in
d
.
get_data
():
yield
dp
yield
dp
class
SelectComponent
(
ProxyDataFlow
):
"""
Select component from a datapoint.
"""
def
__init__
(
self
,
ds
,
idxs
):
"""
:param ds: a :mod:`DataFlow` instance
:param idxs: a list of datapoint component index of the original dataflow
"""
super
(
SelectComponent
,
self
)
.
__init__
(
ds
)
self
.
idxs
=
idxs
def
get_data
(
self
):
for
dp
in
self
.
ds
.
get_data
():
newdp
=
[]
for
idx
in
self
.
idxs
:
newdp
.
append
(
dp
[
idx
])
yield
newdp
tensorpack/dataflow/prefetch.py
View file @
4d64098a
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
import
multiprocessing
import
multiprocessing
from
six.moves
import
range
from
.base
import
ProxyDataFlow
from
.base
import
ProxyDataFlow
from
..utils.concurrency
import
ensure_procs_terminate
from
..utils.concurrency
import
ensure_procs_terminate
...
@@ -49,12 +50,9 @@ class PrefetchData(ProxyDataFlow):
...
@@ -49,12 +50,9 @@ class PrefetchData(ProxyDataFlow):
def
get_data
(
self
):
def
get_data
(
self
):
tot_cnt
=
0
tot_cnt
=
0
while
True
:
for
_
in
range
(
tot_cnt
)
:
dp
=
self
.
queue
.
get
()
dp
=
self
.
queue
.
get
()
yield
dp
yield
dp
tot_cnt
+=
1
if
tot_cnt
==
self
.
_size
:
break
def
__del__
(
self
):
def
__del__
(
self
):
self
.
queue
.
close
()
self
.
queue
.
close
()
...
...
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