Ejemplo n.º 1
0
 def set_param_values(self, flattened_params, **tags):
     debug = tags.pop("debug", False)
     param_values = unflatten_tensors(flattened_params,
                                      self.get_param_shapes(**tags))
     for param, dtype, value in zip(self.get_params(**tags),
                                    self.get_param_dtypes(**tags),
                                    param_values):
         param.set_value(value.astype(dtype))
         if debug:
             print("setting value of %s" % param.name)
Ejemplo n.º 2
0
 def set_param_values(self, flattened_params, all_params=False, **tags):
     debug = tags.pop("debug", False)
     param_values = unflatten_tensors(
         flattened_params, self.get_param_shapes(all_params, **tags))
     ops = []
     feed_dict = dict()
     for param, dtype, value in zip(
             self.get_params(all_params, **tags),
             self.get_param_dtypes(all_params, **tags),
             param_values):
         if param not in self._cached_assign_ops:
             assign_placeholder = tf.placeholder(dtype=param.dtype.base_dtype)
             assign_op = tf.assign(param, assign_placeholder)
             self._cached_assign_ops[param] = assign_op
             self._cached_assign_placeholders[param] = assign_placeholder
         ops.append(self._cached_assign_ops[param])
         feed_dict[self._cached_assign_placeholders[param]] = value.astype(dtype)
         if debug:
             print("setting value of %s" % param.name)
     tf.get_default_session().run(ops, feed_dict=feed_dict)
Ejemplo n.º 3
0
 def flat_to_params(self, flattened_params, all_params=False, **tags):
     return unflatten_tensors(flattened_params,
                              self.get_param_shapes(all_params, **tags))