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
9ac20fcc
Commit
9ac20fcc
authored
Mar 15, 2019
by
IlyaOvodov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CLR with restart additions etc
parent
c52b3eb4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
4 deletions
+6
-4
params.py
ovotools/params.py
+1
-1
pytorch_tools.py
ovotools/pytorch_tools.py
+5
-3
No files found.
ovotools/params.py
View file @
9ac20fcc
...
@@ -98,7 +98,7 @@ class AttrDict(dict):
...
@@ -98,7 +98,7 @@ class AttrDict(dict):
params
.
data_root
=
data_root
params
.
data_root
=
data_root
return
AttrDict
(
params
)
return
AttrDict
(
params
)
def
load
(
params_fn
,
data_root
,
verbose
=
False
):
def
load
(
params_fn
,
data_root
=
None
,
verbose
=
False
):
'''
'''
loads from file, adding '.param.txt' to name
loads from file, adding '.param.txt' to name
'''
'''
...
...
ovotools/pytorch_tools.py
View file @
9ac20fcc
...
@@ -61,6 +61,8 @@ class MarginBaseLoss:
...
@@ -61,6 +61,8 @@ class MarginBaseLoss:
self
.
false_pos
=
0
self
.
false_pos
=
0
self
.
false_neg
=
0
self
.
false_neg
=
0
alpha
=
self
.
model
.
mb_loss_alpha
if
self
.
params
.
mb_loss
.
train_alpha
else
self
.
model
.
mb_loss_alpha
.
detach
()
with
self
.
timer
.
watch
(
'time.d_ij'
):
with
self
.
timer
.
watch
(
'time.d_ij'
):
assert
len
(
pred_embeddings
.
shape
)
==
2
,
pred_embeddings
.
shape
assert
len
(
pred_embeddings
.
shape
)
==
2
,
pred_embeddings
.
shape
norm
=
(
pred_embeddings
**
2
)
.
sum
(
1
)
norm
=
(
pred_embeddings
**
2
)
.
sum
(
1
)
...
@@ -78,13 +80,13 @@ class MarginBaseLoss:
...
@@ -78,13 +80,13 @@ class MarginBaseLoss:
weights_same
=
weights
[
i_start
:
i_end
]
# i-th element already excluded
weights_same
=
weights
[
i_start
:
i_end
]
# i-th element already excluded
j
=
np
.
random
.
choice
(
range
(
i_start
,
i_end
),
p
=
weights_same
/
np
.
sum
(
weights_same
),
replace
=
False
)
j
=
np
.
random
.
choice
(
range
(
i_start
,
i_end
),
p
=
weights_same
/
np
.
sum
(
weights_same
),
replace
=
False
)
assert
j
!=
i
assert
j
!=
i
loss
+=
(
self
.
model
.
mb_loss_alpha
+
(
self
.
d_ij
[
i
,
j
]
-
self
.
model
.
mb_loss_beta
))
.
clamp
(
min
=
0
)
#https://arxiv.org/pdf/1706.07567.pdf
loss
+=
(
alpha
+
(
self
.
d_ij
[
i
,
j
]
-
self
.
model
.
mb_loss_beta
))
.
clamp
(
min
=
0
)
-
alpha
#https://arxiv.org/pdf/1706.07567.pdf
# select neg. pai
t
# select neg. pai
r
weights
=
np
.
delete
(
weights
,
np
.
s_
[
i_start
:
i_end
],
axis
=
0
)
weights
=
np
.
delete
(
weights
,
np
.
s_
[
i_start
:
i_end
],
axis
=
0
)
k
=
np
.
random
.
choice
(
range
(
0
,
n
-
self
.
params
.
data
.
samples_per_class
),
p
=
weights
/
np
.
sum
(
weights
),
replace
=
False
)
k
=
np
.
random
.
choice
(
range
(
0
,
n
-
self
.
params
.
data
.
samples_per_class
),
p
=
weights
/
np
.
sum
(
weights
),
replace
=
False
)
if
k
>=
i_start
:
if
k
>=
i_start
:
k
+=
self
.
params
.
data
.
samples_per_class
k
+=
self
.
params
.
data
.
samples_per_class
loss
+=
(
self
.
model
.
mb_loss_alpha
-
(
self
.
d_ij
[
i
,
k
]
-
self
.
model
.
mb_loss_beta
))
.
clamp
(
min
=
0
)
#https://arxiv.org/pdf/1706.07567.pdf
loss
+=
(
(
alpha
-
(
self
.
d_ij
[
i
,
k
]
-
self
.
model
.
mb_loss_beta
))
.
clamp
(
min
=
0
)
-
alpha
)
*
self
.
params
.
mb_loss
.
neg2pos_weight
#https://arxiv.org/pdf/1706.07567.pdf
self
.
mb_loss_val
=
loss
[
0
]
/
len
(
pred_embeddings
)
self
.
mb_loss_val
=
loss
[
0
]
/
len
(
pred_embeddings
)
negative
=
(
d
>
self
.
model
.
mb_loss_beta
.
detach
())
.
float
()
negative
=
(
d
>
self
.
model
.
mb_loss_beta
.
detach
())
.
float
()
positive
=
(
d
<=
self
.
model
.
mb_loss_beta
.
detach
())
.
float
()
positive
=
(
d
<=
self
.
model
.
mb_loss_beta
.
detach
())
.
float
()
...
...
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