<h3 dir="auto">System information</h3>
<ul dir="auto">
<li><strong>Have I written custom code (as opposed to using a stock example script provided in TensorFlow)</strong>:<br>
Yes.</li>
<li><strong>OS Platform and Distribution (e.g., Linux Ubuntu 16.04)</strong>:<br>
Linux Ubuntu 16.04.3</li>
<li><strong>TensorFlow installed from (source or binary)</strong>:<br>
Binary.</li>
<li><strong>TensorFlow version (use command below)</strong>:<br>
1.3.0</li>
<li><strong>Python version</strong>:<br>
2.7.12</li>
<li><strong>CUDA/cuDNN version</strong>:<br>
CUDA Version 8.0.61</li>
<li><strong>GPU model and memory</strong>:<br>
NVIDIA GTX 1080Ti  12G</li>
</ul>
<h3 dir="auto">Describe the problem</h3>
<p dir="auto">If I import cv2, " tf.global_variables_initializer() " will be very slow, about 143s. You can run my test code below, when " import cv2 " is commented out, the time is about 5s. The version of opencv is 2.4.13.4.</p>
<h3 dir="auto">Source code / logs</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import tensorflow as tf
import time
import cv2

weight = tf.Variable(tf.truncated_normal([5,5,1,32], stddev=0.1))

ot = time.time()
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init_op)
nt = time.time()
print('time: {:.3f}'.format(nt-ot))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>
<span class="pl-k">import</span> <span class="pl-s1">time</span>
<span class="pl-k">import</span> <span class="pl-s1">cv2</span>

<span class="pl-s1">weight</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Variable</span>(<span class="pl-s1">tf</span>.<span class="pl-en">truncated_normal</span>([<span class="pl-c1">5</span>,<span class="pl-c1">5</span>,<span class="pl-c1">1</span>,<span class="pl-c1">32</span>], <span class="pl-s1">stddev</span><span class="pl-c1">=</span><span class="pl-c1">0.1</span>))

<span class="pl-s1">ot</span> <span class="pl-c1">=</span> <span class="pl-s1">time</span>.<span class="pl-en">time</span>()
<span class="pl-s1">init_op</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">global_variables_initializer</span>()
<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-v">Session</span>() <span class="pl-k">as</span> <span class="pl-s1">sess</span>:
    <span class="pl-s1">sess</span>.<span class="pl-en">run</span>(<span class="pl-s1">init_op</span>)
<span class="pl-s1">nt</span> <span class="pl-c1">=</span> <span class="pl-s1">time</span>.<span class="pl-en">time</span>()
<span class="pl-en">print</span>(<span class="pl-s">'time: {:.3f}'</span>.<span class="pl-en">format</span>(<span class="pl-s1">nt</span><span class="pl-c1">-</span><span class="pl-s1">ot</span>))</pre></div>
<p dir="auto">Please go to Stack Overflow for help and support:</p>
<p dir="auto"><a href="https://stackoverflow.com/questions/tagged/tensorflow" rel="nofollow">https://stackoverflow.com/questions/tagged/tensorflow</a></p>
<p dir="auto">If you open a GitHub issue, here is our policy:</p>
<ol dir="auto">
<li>It must be a bug, a feature request, or a significant problem with documentation (for small docs fixes please send a PR instead).</li>
<li>The form below must be filled out.</li>
<li>It shouldn't be a TensorBoard issue. Those go <a href="https://github.com/tensorflow/tensorboard/issues">here</a>.</li>
</ol>
<p dir="auto"><strong>Here's why we have that policy</strong>: TensorFlow developers respond to issues. We want to focus on work that benefits the whole community, e.g., fixing bugs and adding features. Support only helps individuals. GitHub also notifies thousands of people when issues are filed. We want them to see you communicating an interesting problem, rather than being redirected to Stack Overflow.</p>
<hr>
<h3 dir="auto">System information</h3>
<ul dir="auto">
<li><strong>Have I written custom code (as opposed to using a stock example script provided in TensorFlow)</strong>: N/A</li>
<li><strong>OS Platform and Distribution (e.g., Linux Ubuntu 16.04)</strong>: OS 10.13.4</li>
<li><strong>Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device</strong>: N/A</li>
<li><strong>TensorFlow installed from (source or binary)</strong>: source (whole package)</li>
<li><strong>TensorFlow version (use command below)</strong>: 1.10.1</li>
<li><strong>Python version</strong>: 3.7</li>
<li><strong>Bazel version (if compiling from source)</strong>: N/A</li>
<li><strong>GCC/Compiler version (if compiling from source)</strong>:</li>
</ul>
<p dir="auto">Apple LLVM version 9.1.0 (clang-902.0.39.1)<br>
Target: x86_64-apple-darwin17.5.0<br>
Thread model: posix<br>
InstalledDir: /Library/Developer/CommandLineTools/usr/bin</p>
<ul dir="auto">
<li>
<p dir="auto"><strong>CUDA/cuDNN version</strong>: N/A</p>
</li>
<li>
<p dir="auto"><strong>GPU model and memory</strong>: N/A</p>
</li>
<li>
<p dir="auto"><strong>Exact command to reproduce</strong>:</p>
</li>
</ul>
<p dir="auto">run the following below:</p>
<p dir="auto">import numpy as np<br>
import tensorflow as tf<br>
import tensorflow</p>
<p dir="auto">from tensorflow import keras<br>
from keras.models import Sequential<br>
from keras.layers import Embedding</p>
<p dir="auto">model = Sequential()<br>
model.add(Embedding(5, 2, input_length=5))</p>
<p dir="auto">You can collect some of this information using our environment capture script:</p>
<p dir="auto"><a href="https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh">https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh</a></p>
<p dir="auto">You can obtain the TensorFlow version with:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="python -c &quot;import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)&quot;"><pre class="notranslate">python -c <span class="pl-s"><span class="pl-pds">"</span>import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)<span class="pl-pds">"</span></span></pre></div>
<h3 dir="auto">Describe the problem</h3>
<p dir="auto">Describe the problem clearly here. Be sure to convey here why it's a bug in TensorFlow or a feature request.</p>
<p dir="auto">So it appears Tensorflow doesn't play nicely with Python 3.7 - there is a source issue when I run ANY tensorflow or keras command using python 3.7 (but runs perfectly fine with earlier versions of python - reverted back and everything ran perfectly fine).</p>
<p dir="auto">Here are all the relevant files with environment (it actually errors out when running in p3.7)</p>
<p dir="auto">files using 3.7:</p>
<p dir="auto"><a href="https://github.com/tensorflow/tensorflow/files/2488938/broken-old-tf_env.txt">broken-old-tf_env.txt</a><br>
<a href="https://github.com/tensorflow/tensorflow/files/2488939/broken-tf_env.txt">broken-tf_env.txt</a></p>
<p dir="auto">normal env:</p>
<p dir="auto"><a href="https://github.com/tensorflow/tensorflow/files/2488954/old-tf_env.txt">old-tf_env.txt</a><br>
<a href="https://github.com/tensorflow/tensorflow/files/2488958/tf_env.txt">tf_env.txt</a></p>
<h3 dir="auto">Source code / logs</h3>
<p dir="auto">Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem.</p>
<p dir="auto">Here is the trace error message - this exact message occurs when attempting to run ANY keras or tf command using python 3.7:</p>
<p dir="auto">(for test case, honestly even the most simple lines will cause the break - try;</p>
<p dir="auto">embeddings = tf.Variable(tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0))</p>
<p dir="auto">Or for keras:</p>
<p dir="auto">model = Sequential()<br>
model.add(Embedding(10000, 50, input_length=3334))</p>
<h2 dir="auto">Error message:</h2>
<p dir="auto">UnboundLocalError                         Traceback (most recent call last)<br>
 in ()<br>
6 embedding_size = 100<br>
7<br>
----&gt; 8 embeddings = tf.Variable(tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0))<br>
9 nce_weights = tf.Variable(tf.truncated_normal([vocabulary_size, embedding_size], stddev=1.0 / math.sqrt(embedding_size)))<br>
10 nce_biases = tf.Variable(tf.zeros([vocabulary_size]))</p>
<p dir="auto">~/.local/share/virtualenvs/embedded-feature-extraction-o8pNKOHv/lib/python3.7/site-packages/tensorflow/python/ops/random_ops.py in random_uniform(shape, minval, maxval, dtype, seed, name)<br>
233   with ops.name_scope(name, "random_uniform", [shape, minval, maxval]) as name:<br>
234     shape = _ShapeTensor(shape)<br>
--&gt; 235     minval = ops.convert_to_tensor(minval, dtype=dtype, name="min")<br>
236     maxval = ops.convert_to_tensor(maxval, dtype=dtype, name="max")<br>
237     seed1, seed2 = random_seed.get_seed(seed)</p>
<p dir="auto">~/.local/share/virtualenvs/embedded-feature-extraction-o8pNKOHv/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in convert_to_tensor(value, dtype, name, preferred_dtype)<br>
996       name=name,<br>
997       preferred_dtype=preferred_dtype,<br>
--&gt; 998       as_ref=False)<br>
999<br>
1000</p>
<p dir="auto">~/.local/share/virtualenvs/embedded-feature-extraction-o8pNKOHv/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx)<br>
1092<br>
1093     if ret is None:<br>
-&gt; 1094       ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)<br>
1095<br>
1096     if ret is NotImplemented:</p>
<p dir="auto">~/.local/share/virtualenvs/embedded-feature-extraction-o8pNKOHv/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref)<br>
215                                          as_ref=False):<br>
216   _ = as_ref<br>
--&gt; 217   return constant(v, dtype=dtype, name=name)<br>
218<br>
219</p>
<p dir="auto">~/.local/share/virtualenvs/embedded-feature-extraction-o8pNKOHv/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name, verify_shape)<br>
194   tensor_value.tensor.CopyFrom(<br>
195       tensor_util.make_tensor_proto(<br>
--&gt; 196           value, dtype=dtype, shape=shape, verify_shape=verify_shape))<br>
197   dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)<br>
198   const_tensor = g.create_op(</p>
<p dir="auto">~/.local/share/virtualenvs/embedded-feature-extraction-o8pNKOHv/lib/python3.7/site-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape)<br>
534     raise TypeError(<br>
535         "Element type not supported in TensorProto: %s" % numpy_dtype.name)<br>
--&gt; 536   append_fn(tensor_proto, proto_values)<br>
537<br>
538   return tensor_proto</p>
<p dir="auto">tensorflow/python/framework/fast_tensor_util.pyx in tensorflow.python.framework.fast_tensor_util.AppendFloat32ArrayToTensorProto()</p>
<p dir="auto">~/.local/share/virtualenvs/embedded-feature-extraction-o8pNKOHv/lib/python3.7/site-packages/google/protobuf/internal/containers.py in append(<em><strong>failed resolving arguments</strong></em>)<br>
249   def append(self, value):<br>
250     """Appends an item to the list. Similar to list.append()."""<br>
--&gt; 251     self._values.append(self._type_checker.CheckValue(value))<br>
252     if not self._message_listener.dirty:<br>
253       self._message_listener.Modified()</p>
<p dir="auto">UnboundLocalError: local variable 'self' referenced before assignment</p>