Issue 1:
System information

Have I written custom code: no

OS Platform and Distribution: Windows 7, 64-bit

Tensorflow installed from: Anaconda 5.0.1 via pip 9.0.1

(conda create -p C:\temp\tensorflow-gpu; pip install tensorflow-gpu)

Python 3.5.2

TensorFlow 1.5.0

CUDA 9.0

cuDNN 7.0

Bazel: N/A

GPU model and memory: NVIDIA Quadro K620, 2GB

Describe the problem

Commands to reproduce:

conda create -p C:\temp\tensorflow-gpu
activate C:\temp\tensorflow-gpu
pip install tensorflow-gpu
python
> import tensorflow

After installing all dependencies, tensorflow fails to import. Exactly the same error occurs with other Tf/CUDA/cuDNN versions (tried TF 1.4.0 + CUDA 7.0 + cuDNN 5.1 and TF 1.4.0 + CUDA 8.0 + cuDNN 6.0).

While searching, I discovered a similar bug, but it contains a different error message: #5949

Source code / logs

(C:\temp\tensorflow-gpu) C:\temp>python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 5 2016, 11:41:13) [MSC v
.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensor
flow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\temp\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_m
odule
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 577, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 906, in create_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: Die angegebene Prozedur wurde nicht gefunden.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensor
flow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensor
flow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensor
flow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\temp\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_m
odule
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 2
4, in <module>
from tensorflow.python import *
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\python\__init__.py",
line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensor
flow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensor
flow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\temp\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_m
odule
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 577, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 906, in create_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: Die angegebene Prozedur wurde nicht gefunden.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensor
flow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensor
flow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\temp\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensor
flow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\temp\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_m
odule
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_probl
ems

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
>>>

When doing "import tensorflow", these dlls are loaded:

23:09:18,4934154	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\python.exe	SUCCESS	Image Base: 0x1ce20000, Image Size: 0xd000
23:09:18,4935443	python.exe	4848	Load Image	C:\Windows\System32\ntdll.dll	SUCCESS	Image Base: 0x77190000, Image Size: 0x1aa000
23:09:18,4940523	python.exe	4848	Load Image	C:\Windows\System32\kernel32.dll	SUCCESS	Image Base: 0x77070000, Image Size: 0x11f000
23:09:18,4942051	python.exe	4848	Load Image	C:\Windows\System32\KernelBase.dll	SUCCESS	Image Base: 0x7fefd010000, Image Size: 0x6a000
23:09:18,4954354	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\python35.dll	SUCCESS	Image Base: 0x60840000, Image Size: 0x3e4000
23:09:18,4962254	python.exe	4848	Load Image	C:\Windows\System32\ws2_32.dll	SUCCESS	Image Base: 0x7fefe860000, Image Size: 0x4d000
23:09:18,4963049	python.exe	4848	Load Image	C:\Windows\System32\msvcrt.dll	SUCCESS	Image Base: 0x7fefec80000, Image Size: 0x9f000
23:09:18,4965005	python.exe	4848	Load Image	C:\Windows\System32\rpcrt4.dll	SUCCESS	Image Base: 0x7fefe560000, Image Size: 0x12d000
23:09:18,4967902	python.exe	4848	Load Image	C:\Windows\System32\nsi.dll	SUCCESS	Image Base: 0x7fefed20000, Image Size: 0x8000
23:09:18,4969281	python.exe	4848	Load Image	C:\Windows\System32\advapi32.dll	SUCCESS	Image Base: 0x7fefed30000, Image Size: 0xdb000
23:09:18,4975579	python.exe	4848	Load Image	C:\Windows\System32\sechost.dll	SUCCESS	Image Base: 0x7fefefc0000, Image Size: 0x1f000
23:09:18,4980934	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\vcruntime140.dll	SUCCESS	Image Base: 0x7fef9f20000, Image Size: 0x17000
23:09:18,4985102	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-runtime-l1-1-0.dll	SUCCESS	Image Base: 0x7fefae30000, Image Size: 0x4000
23:09:18,4990202	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\ucrtbase.dll	SUCCESS	Image Base: 0x7fef1980000, Image Size: 0xf6000
23:09:18,4993831	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-core-localization-l1-2-0.dll	SUCCESS	Image Base: 0x7fef9f10000, Image Size: 0x3000
23:09:18,4997199	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-core-processthreads-l1-1-1.dll	SUCCESS	Image Base: 0x7fef9f00000, Image Size: 0x3000
23:09:18,5000873	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-core-file-l1-2-0.dll	SUCCESS	Image Base: 0x7fef9c80000, Image Size: 0x3000
23:09:18,5004132	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-core-timezone-l1-1-0.dll	SUCCESS	Image Base: 0x7fef9c50000, Image Size: 0x3000
23:09:18,5007251	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-core-file-l2-1-0.dll	SUCCESS	Image Base: 0x7fef78f0000, Image Size: 0x3000
23:09:18,5010347	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-core-synch-l1-2-0.dll	SUCCESS	Image Base: 0x7fef78e0000, Image Size: 0x3000
23:09:18,5013723	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-string-l1-1-0.dll	SUCCESS	Image Base: 0x7fef7290000, Image Size: 0x4000
23:09:18,5017053	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-heap-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5b80000, Image Size: 0x3000
23:09:18,5020326	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-stdio-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5b20000, Image Size: 0x4000
23:09:18,5023556	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-convert-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5a00000, Image Size: 0x4000
23:09:18,5027163	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-math-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5680000, Image Size: 0x5000
23:09:18,5030972	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-locale-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5670000, Image Size: 0x3000
23:09:18,5035867	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-time-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5660000, Image Size: 0x3000
23:09:18,5040232	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-environment-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5650000, Image Size: 0x3000
23:09:18,5043476	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-process-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5640000, Image Size: 0x3000
23:09:18,5049748	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-conio-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5630000, Image Size: 0x3000
23:09:18,5053460	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-filesystem-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5620000, Image Size: 0x3000
23:09:18,5100964	python.exe	4848	Load Image	C:\Windows\System32\cryptsp.dll	SUCCESS	Image Base: 0x7fefc6b0000, Image Size: 0x18000
23:09:18,5144867	python.exe	4848	Load Image	C:\Windows\System32\rsaenh.dll	SUCCESS	Image Base: 0x7fefc3b0000, Image Size: 0x47000
23:09:18,5156094	python.exe	4848	Load Image	C:\Windows\System32\cryptbase.dll	SUCCESS	Image Base: 0x7fefccc0000, Image Size: 0xf000
23:09:22,2812159	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\DLLs\_ctypes.pyd	SUCCESS	Image Base: 0x6dae0000, Image Size: 0x23000
23:09:22,2818451	python.exe	4848	Load Image	C:\Windows\System32\ole32.dll	SUCCESS	Image Base: 0x7fefe1b0000, Image Size: 0x1fc000
23:09:22,2819936	python.exe	4848	Load Image	C:\Windows\System32\gdi32.dll	SUCCESS	Image Base: 0x7fefee10000, Image Size: 0x67000
23:09:22,2821573	python.exe	4848	Load Image	C:\Windows\System32\user32.dll	SUCCESS	Image Base: 0x76f70000, Image Size: 0xfa000
23:09:22,2823988	python.exe	4848	Load Image	C:\Windows\System32\lpk.dll	SUCCESS	Image Base: 0x7fefef90000, Image Size: 0xe000
23:09:22,2825875	python.exe	4848	Load Image	C:\Windows\System32\usp10.dll	SUCCESS	Image Base: 0x7fefe3b0000, Image Size: 0xcb000
23:09:22,2828244	python.exe	4848	Load Image	C:\Windows\System32\oleaut32.dll	SUCCESS	Image Base: 0x7fefe480000, Image Size: 0xda000
23:09:22,2852213	python.exe	4848	Load Image	C:\Windows\System32\imm32.dll	SUCCESS	Image Base: 0x7fefe7d0000, Image Size: 0x2e000
23:09:22,2854622	python.exe	4848	Load Image	C:\Windows\System32\msctf.dll	SUCCESS	Image Base: 0x7fefee80000, Image Size: 0x109000
23:09:22,2873239	python.exe	4848	Load Image	C:\Windows\System32\psapi.dll	SUCCESS	Image Base: 0x77350000, Image Size: 0x7000
23:09:22,3305458	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\Lib\site-packages\numpy\core\multiarray.cp35-win_amd64.pyd	SUCCESS	Image Base: 0x7fee9230000, Image Size: 0x1a6000
23:09:22,3403641	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\Lib\site-packages\numpy\.libs\libopenblas.BNVRK7633HSX7YVO2TADGR4A5KEKXJAW.gfortran-win_amd64.dll	SUCCESS	Image Base: 0x65600000, Image Size: 0x2457000
23:09:22,3413041	python.exe	4848	Load Image	C:\Windows\System32\api-ms-win-crt-utility-l1-1-0.dll	SUCCESS	Image Base: 0x7fef5310000, Image Size: 0x3000
23:09:22,3504746	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\Lib\site-packages\numpy\core\umath.cp35-win_amd64.pyd	SUCCESS	Image Base: 0x7fef1500000, Image Size: 0xcb000
23:09:22,4512966	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\DLLs\_bz2.pyd	SUCCESS	Image Base: 0x6da10000, Image Size: 0x1a000
23:09:22,4549442	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\DLLs\_lzma.pyd	SUCCESS	Image Base: 0x7fef43d0000, Image Size: 0x29000
23:09:22,4646128	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\DLLs\_hashlib.pyd	SUCCESS	Image Base: 0x7fee9c80000, Image Size: 0x167000
23:09:22,4963274	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\Lib\site-packages\numpy\linalg\lapack_lite.cp35-win_amd64.pyd	SUCCESS	Image Base: 0x7fef4670000, Image Size: 0xb000
23:09:22,4978504	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\Lib\site-packages\numpy\linalg\_umath_linalg.cp35-win_amd64.pyd	SUCCESS	Image Base: 0x7fef41a0000, Image Size: 0x21000
23:09:22,5099393	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\DLLs\_decimal.pyd	SUCCESS	Image Base: 0x6d930000, Image Size: 0x52000
23:09:22,5235329	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\Lib\site-packages\numpy\fft\fftpack_lite.cp35-win_amd64.pyd	SUCCESS	Image Base: 0x7fef4620000, Image Size: 0x18000
23:09:22,5429263	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\Lib\site-packages\numpy\random\mtrand.cp35-win_amd64.pyd	SUCCESS	Image Base: 0x7feef130000, Image Size: 0xaa000
23:09:22,5610733	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\msvcp140.dll	SUCCESS	Image Base: 0x7fef1460000, Image Size: 0x9e000
23:09:22,5617687	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\api-ms-win-crt-multibyte-l1-1-0.dll	SUCCESS	Image Base: 0x7fef4660000, Image Size: 0x5000
23:09:22,5628030	python.exe	4848	Load Image	C:\Windows\System32\nvcuda.dll	SUCCESS	Image Base: 0x7fed7080000, Image Size: 0xd4c000
23:09:22,5629974	python.exe	4848	Load Image	C:\Windows\System32\setupapi.dll	SUCCESS	Image Base: 0x7fefdfd0000, Image Size: 0x1d7000
23:09:22,5631437	python.exe	4848	Load Image	C:\Windows\System32\cfgmgr32.dll	SUCCESS	Image Base: 0x7fefcfc0000, Image Size: 0x36000
23:09:22,5633367	python.exe	4848	Load Image	C:\Windows\System32\devobj.dll	SUCCESS	Image Base: 0x7fefd210000, Image Size: 0x1a000
23:09:22,5634824	python.exe	4848	Load Image	C:\Windows\System32\shell32.dll	SUCCESS	Image Base: 0x7fefd240000, Image Size: 0xd8a000
23:09:22,5636238	python.exe	4848	Load Image	C:\Windows\System32\shlwapi.dll	SUCCESS	Image Base: 0x7fefeb80000, Image Size: 0x71000
23:09:22,5670519	python.exe	4848	Load Image	C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\cudart64_90.dll	SUCCESS	Image Base: 0x7fef3320000, Image Size: 0x61000
23:09:22,5767031	python.exe	4848	Load Image	C:\temp\cudnn\cuda\bin\cudnn64_7.dll	SUCCESS	Image Base: 0x7fec4ba0000, Image Size: 0x111e9000
23:09:22,5836291	python.exe	4848	Load Image	C:\temp\tensorflow-gpu\Lib\site-packages\tensorflow\python\_pywrap_tensorflow_internal.pyd	SUCCESS	Image Base: 0x7feb5630000, Image Size: 0xf564000
23:09:22,5848467	python.exe	4848	Load Image	C:\Windows\System32\wsock32.dll	SUCCESS	Image Base: 0x7fef89d0000, Image Size: 0x9000

Issue 2:
System information

Have I written custom code (as opposed to using a stock example script provided in TensorFlow): NO

OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04

TensorFlow installed from (source or binary): pip install

TensorFlow version (use command below): v1.9.0-rc0-35-g17d6639b55 1.9.0-rc1

Python version: 3.6

CUDA/cuDNN version: CUDA 9.0 / cuDNN 7

GPU model and memory: GTX 1080

Exact command to reproduce:

import tensorflow as tf

def conv_block(inputs, filters, kernel_size, strides, scope):
'''Create a simple Conv --> BN --> ReLU6 block'''

with tf.variable_scope(scope):
x = tf.keras.layers.Conv2D(filters, kernel_size, strides, name='conv2d')(inputs)
x = tf.keras.layers.BatchNormalization(name='BN')(x)
x = tf.keras.layers.Activation(tf.nn.relu6)(x)
return x

def reproduce_keras_variable_scope_error():

# Construct a simple model
inputs = tf.keras.Input(shape=[224, 224, 3], batch_size=1, name='inputs')
hidden = conv_block(inputs, 32, 3, 2, scope='block_1')
outputs = conv_block(hidden, 64, 3, 2, scope='block_2')

# This is fine, the tensor scopes are matched as expected
for v in tf.trainable_variables():
print('{:20} {}'.format(v.name, v.shape))

# Problem happens here. Please consult the error output below.
model = tf.keras.Model(inputs, outputs)
model.summary()

if __name__ =='__main__':
reproduce_keras_variable_scope_error()

Describe the problem

The problem is Keras layers do not probably name its variables according the variable_scope . Therefore, I cannot call conv_block multiple times.

This problem occurs when calling tf.layers as well.

I would like to use tf.keras.Model because I might convert to Estimator later.

Source code / logs

block_1/conv2d/kernel:0 (3, 3, 3, 32)
block_1/conv2d/bias:0 (32,)
block_1/BN/gamma:0 (32,)
block_1/BN/beta:0 (32,)
block_2/conv2d/kernel:0 (3, 3, 32, 64)
block_2/conv2d/bias:0 (64,)
block_2/BN/gamma:0 (64,)
block_2/BN/beta:0 (64,)
Traceback (most recent call last):
File "tf_keras_layer.py", line 24, in <module>
reproduce_variable_scope_error()
File "tf_keras_layer.py", line 20, in reproduce_variable_scope_error
model = tf.keras.Model(inputs, outputs)
File "/home/dat/miniconda2/envs/portrait/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 112, in __init__
super(Model, self).__init__(*args, **kwargs)
File "/home/dat/miniconda2/envs/portrait/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 78, in __init__
self._init_graph_network(*args, **kwargs)
File "/home/dat/miniconda2/envs/portrait/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 244, in _init_graph_network
self.inputs, self.outputs)
File "/home/dat/miniconda2/envs/portrait/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 1689, in _map_graph_network
str(all_names.count(name)) + ' times in the model. '
ValueError: The name "conv2d" is used 2 times in the model. All layer names should be unique.