Skip to content
Snippets Groups Projects
Commit b9215cb2 authored by Peter Fackeldey's avatar Peter Fackeldey
Browse files

black

parent 6e0fbf29
No related branches found
No related tags found
No related merge requests found
......@@ -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
)
}
)
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment