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
17eca8ec
Commit
17eca8ec
authored
Oct 08, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
keep_state option for FixedSizeData
parent
fec86fec
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
2 deletions
+17
-2
tensorpack/dataflow/common.py
tensorpack/dataflow/common.py
+17
-2
No files found.
tensorpack/dataflow/common.py
View file @
17eca8ec
...
...
@@ -190,18 +190,31 @@ class BatchDataByShape(BatchData):
class
FixedSizeData
(
ProxyDataFlow
):
""" Generate data from another DataFlow, but with a fixed total count.
The iterator state of the underlying DataFlow will be kept if not exhausted.
"""
def
__init__
(
self
,
ds
,
size
):
def
__init__
(
self
,
ds
,
size
,
keep_state
=
True
):
"""
Args:
ds (DataFlow): input dataflow
size (int): size
keep_state (bool): keep the iterator state of ``ds``
between calls to :meth:`get_data()`, so that the
next call will continue the previous iteration over ``ds``,
instead of reinitializing an iterator.
Examples:
.. code-block:: none
ds produces: 1, 2, 3, 4, 5; 1, 2, 3, 4, 5; ...
FixedSizeData(ds, 3, True): 1, 2, 3; 4, 5, 1; 2, 3, 4; ...
FixedSizeData(ds, 3, False): 1, 2, 3; 1, 2, 3; ...
FixedSizeData(ds, 6, False): 1, 2, 3, 4, 5, 1; 1, 2, 3, 4, 5, 1;...
"""
super
(
FixedSizeData
,
self
)
.
__init__
(
ds
)
self
.
_size
=
int
(
size
)
self
.
itr
=
None
self
.
_guard
=
DataFlowReentrantGuard
()
self
.
_keep
=
keep_state
def
size
(
self
):
return
self
.
_size
...
...
@@ -221,6 +234,8 @@ class FixedSizeData(ProxyDataFlow):
cnt
+=
1
yield
dp
if
cnt
==
self
.
_size
:
if
not
self
.
_keep
:
self
.
itr
=
None
return
...
...
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