Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OrcaSong
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Show more breadcrumbs
Machine Learning
OrcaSong
Commits
8809183e
Commit
8809183e
authored
4 years ago
by
Stefan Reck
Browse files
Options
Downloads
Patches
Plain Diff
fix incorrect filename when theres only one iteration & restructure
parent
87abba00
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!15
Fix shuffle2
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
orcasong/tools/shuffle2.py
+57
-40
57 additions, 40 deletions
orcasong/tools/shuffle2.py
tests/test_postproc.py
+16
-3
16 additions, 3 deletions
tests/test_postproc.py
with
73 additions
and
43 deletions
orcasong/tools/shuffle2.py
+
57
−
40
View file @
8809183e
...
...
@@ -14,7 +14,61 @@ from orcasong.tools.concatenate import copy_attrs
__author__
=
"
Stefan Reck
"
def
shuffle_v2
(
def
h5shuffle2
(
input_file
,
output_file
=
None
,
iterations
=
None
,
datasets
=
(
"
x
"
,
"
y
"
),
max_ram_fraction
=
0.25
,
**
kwargs
):
if
output_file
is
None
:
output_file
=
get_filepath_output
(
input_file
,
shuffle
=
True
)
if
iterations
is
None
:
iterations
=
get_n_iterations
(
input_file
,
datasets
=
datasets
,
max_ram_fraction
=
max_ram_fraction
,
)
np
.
random
.
seed
(
42
)
for
i
in
range
(
iterations
):
print
(
f
"
\n
Iteration
{
i
+
1
}
/
{
iterations
}
"
)
if
iterations
==
1
:
# special case if theres only one iteration
stgs
=
{
"
input_file
"
:
input_file
,
"
output_file
"
:
output_file
,
"
delete
"
:
False
,
}
elif
i
==
0
:
# first iteration
stgs
=
{
"
input_file
"
:
input_file
,
"
output_file
"
:
f
"
{
output_file
}
_temp_
{
i
}
"
,
"
delete
"
:
False
,
}
elif
i
==
iterations
-
1
:
# last iteration
stgs
=
{
"
input_file
"
:
f
"
{
output_file
}
_temp_
{
i
-
1
}
"
,
"
output_file
"
:
output_file
,
"
delete
"
:
True
,
}
else
:
# intermediate iterations
stgs
=
{
"
input_file
"
:
f
"
{
output_file
}
_temp_
{
i
-
1
}
"
,
"
output_file
"
:
f
"
{
output_file
}
_temp_
{
i
}
"
,
"
delete
"
:
True
,
}
shuffle_file
(
datasets
=
datasets
,
max_ram_fraction
=
max_ram_fraction
,
chunks
=
True
,
**
stgs
,
**
kwargs
,
)
def
shuffle_file
(
input_file
,
datasets
=
(
"
x
"
,
"
y
"
),
output_file
=
None
,
...
...
@@ -267,7 +321,7 @@ def slicify(fancy_indices):
return
[
slice
(
slice_starts
[
i
],
slice_ends
[
i
])
for
i
in
range
(
len
(
slice_starts
))]
def
h5shuffle2
():
def
run_parser
():
parser
=
argparse
.
ArgumentParser
(
description
=
'
Shuffle datasets in a h5file that have the same length.
'
'
Uses chunkwise readout for speed-up.
'
)
...
...
@@ -285,41 +339,4 @@ def h5shuffle2():
"
Default: 0.25
"
)
parser
.
add_argument
(
'
--iterations
'
,
type
=
int
,
default
=
None
,
help
=
"
Shuffle the file this many times. Default: Auto choose best number.
"
)
kwargs
=
vars
(
parser
.
parse_args
())
input_file
=
kwargs
.
pop
(
"
input_file
"
)
output_file
=
kwargs
.
pop
(
"
output_file
"
)
if
output_file
is
None
:
output_file
=
get_filepath_output
(
input_file
,
shuffle
=
True
)
iterations
=
kwargs
.
pop
(
"
iterations
"
)
if
iterations
is
None
:
iterations
=
get_n_iterations
(
input_file
,
datasets
=
kwargs
[
"
datasets
"
],
max_ram_fraction
=
kwargs
[
"
max_ram_fraction
"
],
)
np
.
random
.
seed
(
42
)
for
i
in
range
(
iterations
):
print
(
f
"
\n
Iteration
{
i
+
1
}
/
{
iterations
}
"
)
if
i
==
0
:
# first iteration
stgs
=
{
"
input_file
"
:
input_file
,
"
output_file
"
:
f
"
{
output_file
}
_temp_
{
i
}
"
,
"
delete
"
:
False
}
elif
i
==
iterations
-
1
:
# last iteration
stgs
=
{
"
input_file
"
:
f
"
{
output_file
}
_temp_
{
i
-
1
}
"
,
"
output_file
"
:
output_file
,
"
delete
"
:
True
}
else
:
# intermediate iterations
stgs
=
{
"
input_file
"
:
f
"
{
output_file
}
_temp_
{
i
-
1
}
"
,
"
output_file
"
:
f
"
{
output_file
}
_temp_
{
i
}
"
,
"
delete
"
:
True
}
shuffle_v2
(
**
kwargs
,
**
stgs
,
chunks
=
True
)
h5shuffle2
(
**
vars
(
parser
.
parse_args
()))
This diff is collapsed.
Click to expand it.
tests/test_postproc.py
+
16
−
3
View file @
8809183e
...
...
@@ -3,7 +3,7 @@ import os
import
h5py
import
numpy
as
np
import
orcasong.tools.postproc
as
postproc
from
orcasong.tools.shuffle2
import
shuffle
_v
2
import
orcasong.tools.shuffle2
as
shuffle2
__author__
=
'
Stefan Reck
'
...
...
@@ -41,11 +41,10 @@ class TestShuffleV2(TestCase):
self
.
x
,
self
.
y
=
_make_shuffle_dummy_file
(
self
.
temp_input
)
np
.
random
.
seed
(
42
)
shuffle
_v
2
(
shuffle
2
.
h5shuffle
2
(
input_file
=
self
.
temp_input
,
output_file
=
self
.
temp_output
,
datasets
=
(
"
x
"
,
"
y
"
),
chunks
=
True
,
max_ram
=
400
,
# -> 2 batches
)
...
...
@@ -76,6 +75,20 @@ class TestShuffleV2(TestCase):
f
[
"
x
"
][:,
0
],
target_order
)
def
test_run_3_iterations
(
self
):
# just check if it goes through without errors
fname
=
"
temp_output_triple.h5
"
try
:
shuffle2
.
h5shuffle2
(
input_file
=
self
.
temp_input
,
output_file
=
fname
,
datasets
=
(
"
x
"
,
"
y
"
),
iterations
=
3
,
)
finally
:
if
os
.
path
.
exists
(
fname
):
os
.
remove
(
fname
)
def
_make_shuffle_dummy_file
(
filepath
):
x
=
np
.
random
.
rand
(
22
,
2
)
...
...
This diff is collapsed.
Click to expand it.
Stefan Reck
@sreck
mentioned in issue
#17 (closed)
·
4 years ago
mentioned in issue
#17 (closed)
mentioned in issue #17
Toggle commit list
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