Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
OvoTools
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林帅浩
OvoTools
Commits
1229eb80
Commit
1229eb80
authored
Oct 18, 2019
by
IlyaOvodov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
glue_augmentation, params print with ''
parent
7be4d213
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
3 deletions
+54
-3
params.py
ovotools/params/params.py
+3
-3
__init__.py
ovotools/pytorch/data/__init__.py
+3
-0
glue_augmentation.py
ovotools/pytorch/data/glue_augmentation.py
+48
-0
No files found.
ovotools/params/params.py
View file @
1229eb80
...
...
@@ -41,7 +41,7 @@ class AttrDict(OrderedDict):
elif
isinstance
(
v
,
list
):
self
[
k
]
=
[
AttrDict
(
item
)
if
isinstance
(
item
,
dict
)
else
item
for
item
in
v
]
def
__
st
r__
(
self
):
def
__
rep
r__
(
self
):
def
write_item
(
item
,
margin
=
'
\n
'
):
if
isinstance
(
item
,
dict
):
s
=
'{'
...
...
@@ -62,7 +62,7 @@ class AttrDict(OrderedDict):
s
+=
write_item
(
v
,
margin
=
margin
+
' '
)
+
","
s
+=
' '
+
(
']'
if
isinstance
(
item
,
list
)
else
')'
)
else
:
s
=
st
r
(
item
)
s
=
rep
r
(
item
)
return
s
return
write_item
(
self
)
...
...
@@ -236,6 +236,6 @@ if __name__=='__main__':
mm
.
save
(
fn
,
can_overwrite
=
True
)
print
(
m
)
print
(
mm
)
assert
str
(
m
)
==
st
r
(
mm
)
assert
repr
(
m
)
==
rep
r
(
mm
)
os
.
remove
(
fn
+
'.param.txt'
)
os
.
remove
(
fn
+
'0.param.txt'
)
ovotools/pytorch/data/__init__.py
View file @
1229eb80
from
.threading_dataloader
import
BatchThreadingDataLoader
,
ThreadingDataLoader
from
.cached_dataset
import
CachedDataSet
from
.glue_augmentation
import
glue_augmentation
\ No newline at end of file
ovotools/pytorch/data/glue_augmentation.py
0 → 100644
View file @
1229eb80
import
random
def
glue_augmentation
(
type
=
'x'
,
var_range
=
(
0.1
,
0.9
),
p
=
0.5
,
check_f
=
lambda
i1
,
i2
:
True
,
**
tensor_args
):
'''
:param type: 'x' - glues 2 vertical slices
:param range: cut by x in this range
:param p: with probability p
:param check_f: function gets 2 data ingexes and returns if they can be glued
:param tensor_args: arguments with tensors (BxCxHxW) to be glued
:return: None. modifies tensor_args inplace.
'''
assert
type
==
'x'
b
=
None
for
_
,
t
in
tensor_args
.
items
():
if
b
is
None
:
b
=
t
.
shape
[
0
]
else
:
assert
b
==
t
.
shape
[
0
]
assert
b
>
1
,
"Batch must be > 1 for glue_augmentation"
if
random
.
random
()
<
p
:
for
i1
in
range
(
0
,
b
-
1
,
2
):
i2
=
i1
+
1
if
check_f
(
i1
,
i2
):
x
=
int
(
random
.
uniform
(
var_range
[
0
],
var_range
[
1
])
*
t
.
shape
[
3
])
tmp
=
t
[
i1
,
:,:,
:
x
]
.
clone
()
t
[
i1
,
:,
:,
:
x
]
=
t
[
i2
,
:,:,
:
x
]
.
clone
()
t
[
i2
,
:,
:,
:
x
]
=
tmp
if
__name__
==
'__main__'
:
import
torch
t
=
torch
.
stack
([
torch
.
zeros
(
1
,
2
,
4
),
torch
.
ones
(
1
,
2
,
4
),
torch
.
zeros
(
1
,
2
,
4
),
torch
.
ones
(
1
,
2
,
4
)])
glue_augmentation
(
type
=
'x'
,
var_range
=
(
0.5
,
0.5
),
p
=
1
,
t
=
t
)
print
(
t
)
assert
(
(
t
==
torch
.
Tensor
([[[[
1.
,
1.
,
0.
,
0.
],
[
1.
,
1.
,
0.
,
0.
]]],
[[[
0.
,
0.
,
1.
,
1.
],
[
0.
,
0.
,
1.
,
1.
]]],
[[[
1.
,
1.
,
0.
,
0.
],
[
1.
,
1.
,
0.
,
0.
]]],
[[[
0.
,
0.
,
1.
,
1.
],
[
0.
,
0.
,
1.
,
1.
]]]])
)
.
all
()
)
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