Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Insights
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
3pia
CMS Analyses
Tools
Commits
b9215cb2
Commit
b9215cb2
authored
4 years ago
by
Peter Fackeldey
Browse files
Options
Downloads
Patches
Plain Diff
black
parent
6e0fbf29
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
evil.py
+13
-6
13 additions, 6 deletions
evil.py
tf.py
+45
-24
45 additions, 24 deletions
tf.py
with
58 additions
and
30 deletions
evil.py
+
13
−
6
View file @
b9215cb2
...
...
@@ -10,14 +10,17 @@ def ccall(func, pass_name=False):
key =
"
word
"
def arguments(): pass
"""
class
metaclass
(
type
):
def
__new__
(
cls
,
name
,
a
,
d
):
d
.
pop
(
"
__module__
"
,
0
)
if
pass_name
:
d
[
"
__name__
"
]
=
name
return
func
(
*
a
[
1
:],
**
d
)
def
__call__
(
*
a
,
**
d
):
return
func
(
*
a
,
**
d
)
return
type
.
__new__
(
metaclass
,
func
.
__name__
,
(),
{})
...
...
@@ -31,9 +34,13 @@ def pin(loc, *skip):
these = 2
"""
loc
=
dict
(
loc
)
loc
.
pop
(
"
self
"
).
__dict__
.
update
({
k
:
v
for
k
,
v
in
loc
.
items
()
if
not
any
(
s
is
k
or
s
is
True
and
k
.
startswith
(
"
_
"
)
or
s
is
v
and
isinstance
(
s
,
object
)
for
s
in
skip
)})
loc
.
pop
(
"
self
"
).
__dict__
.
update
(
{
k
:
v
for
k
,
v
in
loc
.
items
()
if
not
any
(
s
is
k
or
s
is
True
and
k
.
startswith
(
"
_
"
)
or
s
is
v
and
isinstance
(
s
,
object
)
for
s
in
skip
)
}
)
This diff is collapsed.
Click to expand it.
tf.py
+
45
−
24
View file @
b9215cb2
...
...
@@ -5,25 +5,32 @@ from time import time
from
analysis.util
import
atq
from
io
import
BytesIO
import
h5py
from
tensorflow.python.keras.engine.saving
import
save_weights_to_hdf5_group
,
load_weights_from_hdf5_group
from
tensorflow.python.keras.engine.saving
import
(
save_weights_to_hdf5_group
,
load_weights_from_hdf5_group
,
)
from
evil
import
pin
,
ccall
from
tensorflow.python.util
import
deprecation
deprecation
.
_PRINT_DEPRECATION_WARNINGS
=
False
def
last_map
(
func
,
obj
,
order
=
1
):
return
tf
.
concat
([
obj
[...,
:
-
1
],
tf
.
expand_dims
(
last_map
(
func
=
func
,
obj
=
obj
[...,
-
1
],
order
=
order
-
1
)
if
1
<
order
else
func
(
obj
[...,
-
1
]),
axis
=-
1
),
],
axis
=-
1
)
return
tf
.
concat
(
[
obj
[...,
:
-
1
],
tf
.
expand_dims
(
last_map
(
func
=
func
,
obj
=
obj
[...,
-
1
],
order
=
order
-
1
)
if
1
<
order
else
func
(
obj
[...,
-
1
]),
axis
=-
1
,
),
],
axis
=-
1
,
)
def
tf_meanstd
(
val
,
**
kwargs
):
...
...
@@ -34,6 +41,7 @@ def tf_meanstd(val, **kwargs):
# this is mostly unused ...
class
FD
(
dict
):
def
add
(
self
,
data
,
dtype
=
None
,
shape
=
None
,
**
kwargs
):
if
shape
is
True
:
...
...
@@ -48,7 +56,17 @@ class FD(dict):
class
Chain
(
object
):
def
__init__
(
self
,
__name__
,
loss
,
sumnbs
=
(),
step
=
None
,
opt
=
None
,
train
=
None
,
ema
=
(
1
,
2
,
3
,
4
,
5
),
**
kwargs
):
def
__init__
(
self
,
__name__
,
loss
,
sumnbs
=
(),
step
=
None
,
opt
=
None
,
train
=
None
,
ema
=
(
1
,
2
,
3
,
4
,
5
),
**
kwargs
):
if
step
is
None
:
step
=
tf
.
Variable
(
0
,
trainable
=
False
,
name
=
"
%s_step
"
%
__name__
)
if
opt
is
None
:
...
...
@@ -88,9 +106,13 @@ class Chain(object):
reset_ema
=
ema_step
.
initializer
for
i
in
ema
:
with
tf
.
name_scope
(
"
%s_%d
"
%
(
__name__
,
i
)):
ema
=
tf
.
train
.
ExponentialMovingAverage
(
decay
=
1.
-
tf
.
maximum
(
0.1
**
i
,
tf
.
exp
((
np
.
log
(
0.1
**
i
)
/
10.
)
*
tf
.
cast
(
ema_step
,
tf
.
float32
))
))
ema
=
tf
.
train
.
ExponentialMovingAverage
(
decay
=
1.0
-
tf
.
maximum
(
0.1
**
i
,
tf
.
exp
((
np
.
log
(
0.1
**
i
)
/
10.0
)
*
tf
.
cast
(
ema_step
,
tf
.
float32
)),
)
)
_ema_ops
.
append
(
ema
.
apply
(
_ema_val
.
values
()))
for
key
,
val
in
_ema_val
.
items
():
val
=
ema
.
average
(
val
)
...
...
@@ -139,7 +161,9 @@ class Runner(object):
@contextmanager
def
make
(
cls
,
path
,
gpuOpts
=
{},
flush_secs
=
20
):
with
cls
.
make_session
(
gpuOpts
=
gpuOpts
)
as
sess
:
with
tf
.
summary
.
FileWriter
(
path
,
session
=
sess
,
flush_secs
=
flush_secs
,
graph
=
sess
.
graph
)
as
writer
:
with
tf
.
summary
.
FileWriter
(
path
,
session
=
sess
,
flush_secs
=
flush_secs
,
graph
=
sess
.
graph
)
as
writer
:
yield
cls
(
sess
,
writer
)
@classmethod
...
...
@@ -168,11 +192,12 @@ class Confirmer(object):
break
if
tnext
<
time
():
tnext
=
time
()
+
self
.
tdelay
pTotal
=
100.
*
i
/
its
pTotal
=
100.
0
*
i
/
its
self
.
task
.
set_progress_percentage
(
pTotal
)
self
.
task
.
set_status_message
(
"
total=%.1f%% conf=%.1f%% best=%.2e
"
%
(
pTotal
,
100.
*
self
.
conf
/
target
,
self
.
best
))
self
.
task
.
set_status_message
(
"
total=%.1f%% conf=%.1f%% best=%.2e
"
%
(
pTotal
,
100.0
*
self
.
conf
/
target
,
self
.
best
)
)
if
not
(
self
.
conf
<
target
):
break
self
.
step
+=
1
...
...
@@ -216,11 +241,7 @@ class Confirmer(object):
}
def
__repr__
(
self
):
return
"
Confirmer(step=%d, best=%.3e, conf=%d)
"
%
(
self
.
step
,
self
.
best
,
self
.
conf
)
return
"
Confirmer(step=%d, best=%.3e, conf=%d)
"
%
(
self
.
step
,
self
.
best
,
self
.
conf
)
class
Bestie
(
object
):
...
...
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