Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nianchen Deng
deeplightfield
Commits
f7038e26
Commit
f7038e26
authored
Jan 09, 2021
by
BobYeah
Browse files
sync
parent
72636b3e
Changes
1
Hide whitespace changes
Inline
Side-by-side
data/loader.py
0 → 100644
View file @
f7038e26
import
torch
import
math
from
..my
import
device
class
FastDataLoader
(
object
):
class
Iter
(
object
):
def
__init__
(
self
,
dataset
,
batch_size
,
shuffle
,
drop_last
)
->
None
:
super
().
__init__
()
self
.
indices
=
torch
.
randperm
(
len
(
dataset
),
device
=
device
.
GetDevice
())
\
if
shuffle
else
torch
.
arange
(
len
(
dataset
),
device
=
device
.
GetDevice
())
self
.
offset
=
0
self
.
batch_size
=
batch_size
self
.
dataset
=
dataset
self
.
drop_last
=
drop_last
def
__next__
(
self
):
if
self
.
offset
+
(
self
.
batch_size
if
self
.
drop_last
else
0
)
>=
len
(
self
.
dataset
):
raise
StopIteration
()
indices
=
self
.
indices
[
self
.
offset
:
self
.
offset
+
self
.
batch_size
]
self
.
offset
+=
self
.
batch_size
return
self
.
dataset
[
indices
]
def
__init__
(
self
,
dataset
,
batch_size
,
shuffle
,
drop_last
,
**
kwargs
)
->
None
:
super
().
__init__
()
self
.
dataset
=
dataset
self
.
batch_size
=
batch_size
self
.
shuffle
=
shuffle
self
.
drop_last
=
drop_last
def
__iter__
(
self
):
return
FastDataLoader
.
Iter
(
self
.
dataset
,
self
.
batch_size
,
self
.
shuffle
,
self
.
drop_last
)
def
__len__
(
self
):
return
math
.
floor
(
len
(
self
.
dataset
)
/
self
.
batch_size
)
if
self
.
drop_last
\
else
math
.
ceil
(
len
(
self
.
dataset
)
/
self
.
batch_size
)
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