# Buggy code
def initialize_variables(variables=None, session=None, force=False, **run_kwargs):
    session = tf.get_default_session() if session is None else session
    if variables is None:
        initializer = tf.global_variables_initializer()
    else:
        if force:
            initializer = tf.variables_initializer(variables)
        else:
            uninitialized = tf.report_uninitialized_variables(var_list=variables)

            def uninitialized_names():
                for uv in session.run(uninitialized):
                    yield uv.decode("utf-8")
                    # if isinstance(uv, bytes):
                    #     yield uv.decode('utf-8')
                    # elif isinstance(uv, str):
                    #     yield uv
                    # else:
                    #     msg = 'Unknown output type "{}" from `tf.report_uninitialized_variables`'
                    #     raise ValueError(msg.format(type(uv)))

            names = set(uninitialized_names())
            vars_for_init = [v for v in variables if v.name.split(":")[0] in names]
            initializer = tf.variables_initializer(vars_for_init)
    session.run(initializer, **run_kwargs)


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-e3c07a8fceb7> in <module>()
10                                 np.random.randn(M, D),
11                                 minibatch_size=2)
---> 12 model.compute_log_likelihood()

/[...]/GPflow/gpflow/decors.py in runnable(obj, *args, **kwargs)
152                     _setup_storage(store, *af_args, **af_kwargs)
153                     _build_method(method, obj, store)
--> 154             return _session_run(session, obj, store, *args, **kwargs)
155         return runnable
156     return autoflow_wrapper

/[...]/GPflow/gpflow/decors.py in _session_run(session, obj, store, *args, **kwargs)
189         feed_dict.update(obj.feeds)
190     initialize = kwargs.pop('initialize', False)
--> 191     obj.initialize(session=session, force=initialize)
192     return session.run(store['result'], **kwargs)
193

/[...]/GPflow/gpflow/core/node.py in initialize(self, session, force)
82                 session=session,
83                 force=force,
---> 84                 feed_dict=self.initializable_feeds)
85
86     def clear(self):

/[...]/GPflow/gpflow/misc.py in initialize_variables(variables, session, force, **run_kwargs)
82             initializer = tf.variables_initializer(variables)
83         else:
---> 84             uninitialized = tf.report_uninitialized_variables(var_list=variables)
85             def uninitialized_names():
86                 for uv in session.run(uninitialized):

/[...]/anaconda3/envs/py35cpu/lib/python3.5/site-packages/tensorflow/python/util/tf_should_use.py in wrapped(*args, **kwargs)
105   """
106   def wrapped(*args, **kwargs):
--> 107     return _add_should_use_warning(fn(*args, **kwargs))
108   return tf_decorator.make_decorator(
109       fn, wrapped, 'should_use_result',

/[...]/anaconda3/envs/py35cpu/lib/python3.5/site-packages/tensorflow/python/ops/variables.py in report_uninitialized_variables(var_list, name)
1519         variables_mask = math_ops.logical_not(
1520             array_ops.stack(
-> 1521                 [state_ops.is_variable_initialized(v) for v in var_list]))
1522         # Get a 1-D string tensor containing all the variable names.
1523         variable_names_tensor = array_ops.constant(

/[...]/anaconda3/envs/py35cpu/lib/python3.5/site-packages/tensorflow/python/ops/variables.py in <listcomp>(.0)
1519         variables_mask = math_ops.logical_not(
1520             array_ops.stack(
-> 1521                 [state_ops.is_variable_initialized(v) for v in var_list]))
1522         # Get a 1-D string tensor containing all the variable names.
1523         variable_names_tensor = array_ops.constant(

/[...]/anaconda3/envs/py35cpu/lib/python3.5/site-packages/tensorflow/python/ops/state_ops.py in is_variable_initialized(ref, name)
182     A `Tensor` of type `bool`.
183   """
--> 184   if ref.dtype._is_ref_dtype:
185     return gen_state_ops.is_variable_initialized(ref=ref, name=name)
186   # Handle resource variables.

AttributeError: 'Iterator' object has no attribute 'dtype'

# Fixed code
def initialize_variables(variables=None, session=None, force=False, **run_kwargs):
    session = tf.get_default_session() if session is None else session
    if variables is None:
        initializer = tf.global_variables_initializer()
    else:
        if force:
            vars_for_init = list(_initializable_tensors(variables))
        else:
            vars_for_init = list(_find_initializable_tensors(variables, session))
        if not vars_for_init:
            return
        initializer = tf.variables_initializer(vars_for_init)
    session.run(initializer, **run_kwargs)