Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
donut_pytorch
Commits
4c977771
"vscode:/vscode.git/clone" did not exist on "aeb8cfcba8512c0a3ca3e50b057b7981d35f512f"
Commit
4c977771
authored
Nov 20, 2022
by
moonbings
Browse files
Update random split logic for reproducing
parent
e83c78be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
14 deletions
+6
-14
synthdog/template.py
synthdog/template.py
+6
-14
No files found.
synthdog/template.py
View file @
4c977771
...
...
@@ -38,10 +38,10 @@ class SynthDoG(templates.Template):
**
config
.
get
(
"effect"
,
{}),
)
# config for splits
(output_filename, split_ratio etc)
# config for splits
self
.
splits
=
[
"train"
,
"validation"
,
"test"
]
self
.
split_
indexes
=
[
0
,
0
,
0
]
self
.
split_
ratio
=
[
sum
(
split_ratio
[:
i
+
1
])
for
i
in
range
(
0
,
len
(
split_ratio
)
)]
self
.
split_
ratio
=
split_ratio
self
.
split_
indexes
=
np
.
random
.
choice
(
3
,
size
=
10000
,
p
=
split_ratio
)
def
generate
(
self
):
landscape
=
np
.
random
.
rand
()
<
self
.
landscape
...
...
@@ -88,19 +88,11 @@ class SynthDoG(templates.Template):
roi
=
data
[
"roi"
]
# split
output_dirpath
=
os
.
path
.
join
(
root
,
"train"
)
file_idx
=
idx
split_prob
=
np
.
random
.
rand
()
for
_idx
,
(
split
,
ratio
)
in
enumerate
(
zip
(
self
.
splits
,
self
.
split_ratio
)):
if
split_prob
<
ratio
:
output_dirpath
=
os
.
path
.
join
(
root
,
split
)
file_idx
=
self
.
split_indexes
[
_idx
]
self
.
split_indexes
[
_idx
]
+=
1
break
split
=
self
.
split_indexes
[
idx
%
len
(
self
.
split_indexes
)]
output_dirpath
=
os
.
path
.
join
(
root
,
self
.
splits
[
split
])
# save image
image_filename
=
f
"image_
{
file_
idx
}
.jpg"
image_filename
=
f
"image_
{
idx
}
.jpg"
image_filepath
=
os
.
path
.
join
(
output_dirpath
,
image_filename
)
os
.
makedirs
(
os
.
path
.
dirname
(
image_filepath
),
exist_ok
=
True
)
image
=
Image
.
fromarray
(
image
[...,
:
3
].
astype
(
np
.
uint8
))
...
...
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