Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Habitat Lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
Meta Research
Habitat Lab
Commits
4b6da1c4
Commit
4b6da1c4
authored
5 years ago
by
Erik Wijmans
Committed by
Oleksandr
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Preserve scene ordering (#234)
* Preserve scene ordering
parent
55fc9353
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
habitat/core/dataset.py
+20
-2
20 additions, 2 deletions
habitat/core/dataset.py
test/test_dataset.py
+9
-0
9 additions, 0 deletions
test/test_dataset.py
with
29 additions
and
2 deletions
habitat/core/dataset.py
+
20
−
2
View file @
4b6da1c4
...
...
@@ -322,7 +322,7 @@ class EpisodeIterator(Iterator):
random
.
shuffle
(
self
.
episodes
)
if
group_by_scene
:
self
.
episodes
=
s
orted
(
self
.
episodes
,
key
=
lambda
x
:
x
.
scene_id
)
self
.
episodes
=
s
elf
.
_group_scenes
(
self
.
episodes
)
self
.
max_scene_repetition_episodes
=
max_scene_repeat_episodes
self
.
max_scene_repetition_steps
=
max_scene_repeat_steps
...
...
@@ -387,15 +387,33 @@ class EpisodeIterator(Iterator):
r
"""
Internal method that shuffles the remaining episodes.
If self.group_by_scene is true, then shuffle groups of scenes.
"""
assert
self
.
shuffle
episodes
=
list
(
self
.
_iterator
)
random
.
shuffle
(
episodes
)
if
self
.
group_by_scene
:
episodes
=
s
orted
(
episodes
,
key
=
lambda
x
:
x
.
scene_id
)
episodes
=
s
elf
.
_group_scenes
(
episodes
)
self
.
_iterator
=
iter
(
episodes
)
def
_group_scenes
(
self
,
episodes
):
r
"""
Internal method that groups episodes by scene
Groups will be ordered by the order the first episode of a given
scene is in the list of episodes
So if the episodes list shuffled before calling this method,
the scenes will be in a random order
"""
assert
self
.
group_by_scene
scene_sort_keys
=
{}
for
e
in
episodes
:
if
e
.
scene_id
not
in
scene_sort_keys
:
scene_sort_keys
[
e
.
scene_id
]
=
len
(
scene_sort_keys
)
return
sorted
(
episodes
,
key
=
lambda
e
:
scene_sort_keys
[
e
.
scene_id
])
def
step_taken
(
self
):
self
.
_step_count
+=
1
...
...
This diff is collapsed.
Click to expand it.
test/test_dataset.py
+
9
−
0
View file @
4b6da1c4
...
...
@@ -350,3 +350,12 @@ def test_iterator_scene_switching_steps():
"
Next episodes should still be grouped by scene (before next
"
"
switching).
"
)
def
test_preserve_order
():
dataset
=
_construct_dataset
(
100
)
episodes
=
sorted
(
dataset
.
episodes
,
reverse
=
True
,
key
=
lambda
x
:
x
.
scene_id
)
dataset
.
episodes
=
episodes
[:]
episode_iter
=
dataset
.
get_episode_iterator
(
shuffle
=
False
,
cycle
=
False
)
assert
list
(
episode_iter
)
==
episodes
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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