TensorFlow optimize initilizer.
@@ -53,7 +53,7 @@ class _TensorFlowOptimizer(optimizer.Optimizer):
with session.as_default():
minimize = self.optimizer.minimize(objective, var_list=full_var_list, **kwargs)
model.initialize(session=session)
- self._initialize_optimizer(session, full_var_list)
+ self._initialize_optimizer(session)
return minimize
def make_optimize_action(self, model, session=None, var_list=None, **kwargs):
@@ -117,21 +117,9 @@ class _TensorFlowOptimizer(optimizer.Optimizer):
if anchor:
opt.model.anchor(session)
- def _initialize_optimizer(self, session, var_list):
- """
- TODO(@awav): AdamOptimizer creates beta1 and beta2 variables which are
- not included in slots.
- """
- def get_optimizer_slots():
- for name in self.optimizer.get_slot_names():
- for var in var_list:
- slot = self.optimizer.get_slot(var, name)
- if slot is not None:
- yield slot
- extra_vars = [v for v in self.optimizer.__dict__.values() if isinstance(v, tf.Variable)]
- optimizer_vars = list(get_optimizer_slots())
- full_var_list = list(set(optimizer_vars + extra_vars))
- misc.initialize_variables(full_var_list, session=session, force=False)
+ def _initialize_optimizer(self, session: tf.Session):
+ var_list = self.optimizer.variables()
+ misc.initialize_variables(var_list, session=session, force=False)
@property
def minimize_operation(self):
