def __init__(self, filepath, monitor='val_loss', verbose=0,
save_best_only=False, save_weights_only=False,
mode='auto'):
super(ModelCheckpoint, self).__init__()
self.monitor = monitor
self.verbose = verbose
self.filepath = filepath
self.save_best_only = save_best_only
self.save_weights_only = save_weights_only
if mode not in ['auto', 'min', 'max']:
warnings.warn('ModelCheckpoint mode %s is unknown, '
'fallback to auto mode.' % (mode),
RuntimeWarning)
mode = 'auto'
if mode == 'min':
self.monitor_op = np.less
self.best = np.Inf
elif mode == 'max':
self.monitor_op = np.greater
self.best = -np.Inf
else:
if 'acc' in self.monitor:
self.monitor_op = np.greater
self.best = -np.Inf
else:
self.monitor_op = np.less
self.best = np.Inf
python类inf()的实例源码
def on_train_begin(self, logs={}):
self.wait = 0 # Allow instances to be re-used
self.best = np.Inf if self.monitor_op == np.less else -np.Inf
def reset(self):
if self.mode not in ['auto', 'min', 'max']:
warnings.warn('Learning Rate Plateau Reducing mode %s is unknown, '
'fallback to auto mode.' % (self.mode), RuntimeWarning)
self.mode = 'auto'
if self.mode == 'min' or (self.mode == 'auto' and 'acc' not in self.monitor):
self.monitor_op = lambda a, b: np.less(a, b - self.epsilon)
self.best = np.Inf
else:
self.monitor_op = lambda a, b: np.greater(a, b + self.epsilon)
self.best = -np.Inf
self.cooldown_counter = 0
self.wait = 0
self.lr_epsilon = self.min_lr * 1e-4
def _get_bounds(self, ib, dimension):
"""ib == 0/1 means lower/upper bound, return a vector of length
`dimension` """
sign_ = 2 * ib - 1
assert sign_**2 == 1
if self.bounds is None or self.bounds[ib] is None:
return array(dimension * [sign_ * np.Inf])
res = []
for i in range(dimension):
res.append(self.bounds[ib][min([i, len(self.bounds[ib]) - 1])])
if res[-1] is None:
res[-1] = sign_ * np.Inf
return array(res)
def __init__(self, asedb, kvp={}, data={}, batch_size=1,
selection=None, shuffle=True, prefetch=False,
block_size=150000,
capacity=5000, num_epochs=np.Inf, floatX=np.float32):
super(ASEDataProvider, self).__init__(batch_size)
self.asedb = asedb
self.prefetch = prefetch
self.selection = selection
self.block_size = block_size
self.shuffle = shuffle
self.kvp = kvp
self.data = data
self.floatX = floatX
self.feat_names = ['numbers', 'positions', 'cell',
'pbc'] + list(kvp.keys()) + list(data.keys())
self.shapes = [(None,), (None, 3), (3, 3),
(3,)] + list(kvp.values()) + list(data.values())
self.epoch = 0
self.num_epochs = num_epochs
self.n_rows = 0
# initialize queue
with connect(self.asedb) as con:
row = list(con.select(self.selection, limit=1))[0]
feats = self.convert_atoms(row)
dtypes = [np.array(feat).dtype for feat in feats]
self.queue = tf.FIFOQueue(capacity, dtypes)
self.placeholders = [
tf.placeholder(dt, name=name)
for dt, name in zip(dtypes, self.feat_names)
]
self.enqueue_op = self.queue.enqueue(self.placeholders)
self.dequeue_op = self.queue.dequeue()
self.preprocs = []
def read(self):
retval = self.func()
if isinstance(retval,numbers.Number) and retval != np.Inf:self.value.setText('%s'%(self.applySIPrefix(retval,self.units) ))
else: self.value.setText(str(retval))
def read(self):
retval = self.func()
try:
if isinstance(retval,numbers.Number) and retval != np.Inf:self.value.setText('%s'%(self.applySIPrefix(retval,self.units) ))
else: self.value.setText(retval)
except:self.value.setText(str(retval))
def read(self):
retval = self.func(self.optionBox.currentText())
#if abs(retval)<1e4 and abs(retval)>.01:self.value.setText('%.3f %s '%(retval,self.units))
#else: self.value.setText('%.3e %s '%(retval,self.units))
if isinstance(retval,numbers.Number) and retval != np.Inf:self.value.setText('%s'%(self.applySIPrefix(retval,self.units) ))
else: self.value.setText(str(retval))
if self.linkFunc:
self.linkFunc(retval)
def _safe_db(num, den):
"""Properly handle the potential +Inf db SIR, instead of raising a
RuntimeWarning. Only denominator is checked because the numerator can never
be 0.
"""
if den == 0:
return np.Inf
return 10 * np.log10(num / den)
def _get_bounds(self, ib, dimension):
"""ib == 0/1 means lower/upper bound, return a vector of length
`dimension` """
sign_ = 2 * ib - 1
assert sign_**2 == 1
if self.bounds is None or self.bounds[ib] is None:
return array(dimension * [sign_ * np.Inf])
res = []
for i in range(dimension):
res.append(self.bounds[ib][min([i, len(self.bounds[ib]) - 1])])
if res[-1] is None:
res[-1] = sign_ * np.Inf
return array(res)