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
8403a009
Commit
8403a009
authored
Jul 28, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nr_reuse in locallyshuffledata
parent
53291500
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
5 deletions
+15
-5
tensorpack/dataflow/common.py
tensorpack/dataflow/common.py
+15
-5
No files found.
tensorpack/dataflow/common.py
View file @
8403a009
...
...
@@ -311,9 +311,15 @@ class JoinData(DataFlow):
del
itr
class
LocallyShuffleData
(
ProxyDataFlow
,
RNGDataFlow
):
def
__init__
(
self
,
ds
,
cache_size
):
def
__init__
(
self
,
ds
,
cache_size
,
nr_reuse
=
1
):
"""
Cache a number of datapoints and shuffle them.
:param cache_size: size of the cache
:param nr_reuse: reuse each datapoints several times
"""
ProxyDataFlow
.
__init__
(
self
,
ds
)
self
.
q
=
deque
(
maxlen
=
cache_size
)
self
.
nr_reuse
=
nr_reuse
def
reset_state
(
self
):
ProxyDataFlow
.
reset_state
(
self
)
...
...
@@ -322,17 +328,22 @@ class LocallyShuffleData(ProxyDataFlow, RNGDataFlow):
self
.
current_cnt
=
0
def
get_data
(
self
):
def
add_next
():
dp
=
next
(
self
.
ds_itr
)
for
_
in
range
(
self
.
nr_reuse
):
self
.
q
.
append
(
dp
)
for
_
in
range
(
self
.
q
.
maxlen
-
len
(
self
.
q
)):
try
:
self
.
q
.
append
(
next
(
self
.
ds_itr
)
)
add_next
(
)
except
StopIteration
:
logger
.
error
(
"LocallyShuffleData: cache_size is larger than the size of ds!"
)
while
True
:
self
.
rng
.
shuffle
(
self
.
q
)
for
_
in
range
(
self
.
q
.
maxlen
):
for
_
in
range
(
self
.
nr_reuse
):
yield
self
.
q
.
popleft
()
try
:
self
.
q
.
append
(
next
(
self
.
ds_itr
)
)
add_next
(
)
except
StopIteration
:
# produce the rest and return
self
.
rng
.
shuffle
(
self
.
q
)
...
...
@@ -341,7 +352,6 @@ class LocallyShuffleData(ProxyDataFlow, RNGDataFlow):
return
def
SelectComponent
(
ds
,
idxs
):
"""
:param ds: a :mod:`DataFlow` instance
...
...
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