Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
deeplightfield
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Nianchen Deng
deeplightfield
Commits
f7038e26
There was an error fetching the commit references. Please try again later.
Commit
f7038e26
authored
4 years ago
by
BobYeah
Browse files
Options
Downloads
Patches
Plain Diff
sync
parent
72636b3e
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
data/loader.py
+39
-0
39 additions, 0 deletions
data/loader.py
with
39 additions
and
0 deletions
data/loader.py
0 → 100644
+
39
−
0
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment