0

最終的にはAnaconda Navigator から起動したJupyter Labでtensorflow-gpuを使いたいと思っています。

環境は以下のとおりです。
Windows 10 (RTX2060Super搭載)
Microsoft Visual Studio 2019
Nvidia CUDA 11.6
Anaconda3.9

ここからAnacondaプロンプトを用いて以下のようにインストールを試みました。

> conda create -n twne
> conda activate twne
(twne)> conda install python=3.6.10
(twne)> pip3 install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio===0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
(twne)> conda install tensorflow-gpu=1.14
(twne)> nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:28:54_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.6, V11.6.55
Build cuda_11.6.r11.6/compiler.30794723_0
(twne)>nvidia-smi
Sat Jan 29 17:04:27 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 456.71       Driver Version: 456.71       CUDA Version: 11.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce RTX 206... WDDM  | 00000000:08:00.0  On |                  N/A |
| 29%   30C    P8    19W / 175W |   1502MiB /  8192MiB |     11%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1424    C+G   Insufficient Permissions        N/A      |
|    0   N/A  N/A      2208    C+G   ...8wekyb3d8bbwe\Cortana.exe    N/A      |
|    0   N/A  N/A      7796    C+G   C:\Windows\explorer.exe         N/A      |
|    0   N/A  N/A      8740    C+G   ...5n1h2txyewy\SearchApp.exe    N/A      |
|    0   N/A  N/A     10004    C+G   ...i\Application\vivaldi.exe    N/A      |
|    0   N/A  N/A     10256    C+G   ...cw5n1h2txyewy\LockApp.exe    N/A      |
|    0   N/A  N/A     10872    C+G   Insufficient Permissions        N/A      |
|    0   N/A  N/A     11724    C+G   ...nputApp\TextInputHost.exe    N/A      |
|    0   N/A  N/A     12424    C+G   ...lPanel\SystemSettings.exe    N/A      |
|    0   N/A  N/A     14316    C+G   ...llpaper\RainWallpaper.exe    N/A      |
|    0   N/A  N/A     14568    C+G   ...inWallpaper\videocore.exe    N/A      |
|    0   N/A  N/A     14576    C+G   ...inWallpaper\videocore.exe    N/A      |
|    0   N/A  N/A     15348    C+G   ...ram Files\LGHUB\lghub.exe    N/A      |
|    0   N/A  N/A     16256    C+G   ...aming\Spotify\Spotify.exe    N/A      |
|    0   N/A  N/A     16908    C+G   ...4.0.3.0\GoogleDriveFS.exe    N/A      |
|    0   N/A  N/A     18548    C+G   ...t\GoogleIMEJaRenderer.exe    N/A      |
|    0   N/A  N/A     19144    C+G   ...ions\Sancan210\Sancan.exe    N/A      |
|    0   N/A  N/A     20204    C+G   ...ekyb3d8bbwe\YourPhone.exe    N/A      |
+-----------------------------------------------------------------------------+
(twne)>python
Python 3.6.13 |Anaconda, Inc.| (default, Mar 16 2021, 11:37:27) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from tensorflow.python.client import device_lib
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
>>> print(device_lib.list_local_devices())
2022-01-29 17:12:54.466889: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2022-01-29 17:12:54.469356: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll
2022-01-29 17:12:54.493073: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: GeForce RTX 2060 SUPER major: 7 minor: 5 memoryClockRate(GHz): 1.65
pciBusID: 0000:08:00.0
2022-01-29 17:12:54.493153: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2022-01-29 17:12:54.493217: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2022-01-29 17:12:54.880700: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-01-29 17:12:54.880765: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0
2022-01-29 17:12:54.881017: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N
2022-01-29 17:12:54.881165: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/device:GPU:0 with 6734 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2060 SUPER, pci bus id: 0000:08:00.0, compute capability: 7.5)
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 11278547066770496530
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 7061500724
locality {
  bus_id: 1
  links {
  }
}
incarnation: 16847822037550859714
physical_device_desc: "device: 0, name: GeForce RTX 2060 SUPER, pci bus id: 0000:08:00.0, compute capability: 7.5"
]
>>>
(twne)>

この状況で、Anaconda Navigator から起動したJupyter Labで以下のコードを実行しましたが失敗しました。

# 関数定義
%cd .\stylegan2
from function import *

C:\Users\hoge\painter\stylegan2
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Setting up TensorFlow plugin "fused_bias_act.cu": Preprocessing... Failed!
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-1-5a9fc02cd5e9> in <module>
      1 # 関数定義
      2 get_ipython().run_line_magic('cd', '.\\stylegan2')
----> 3 from function import *

~\painter\stylegan2\function.py in <module>
      8 
      9 tflib.init_tf()
---> 10 _G, _D, Gs = pickle.load(open("../network-tadne.pkl", "rb"))
     11 # _G = Instantaneous snapshot of the generator. Mainly useful for resuming a previous training run.
     12 # _D = Instantaneous snapshot of the discriminator. Mainly useful for resuming a previous training run.

~\painter\stylegan2\dnnlib\tflib\network.py in __setstate__(self, state)
    295 
    296         # Init TensorFlow graph.
--> 297         self._init_graph()
    298         self.reset_own_vars()
    299         tfutil.set_vars({self.find_var(name): value for name, value in state["variables"]})

~\painter\stylegan2\dnnlib\tflib\network.py in _init_graph(self)
    152             with tf.control_dependencies(None):  # ignore surrounding control dependencies
    153                 self.input_templates = [tf.placeholder(tf.float32, name=name) for name in self.input_names]
--> 154                 out_expr = self._build_func(*self.input_templates, **build_kwargs)
    155 
    156         # Collect outputs.

<string> in G_synthesis_stylegan2(dlatents_in, dlatent_size, num_channels, resolution, fmap_base, fmap_decay, fmap_min, fmap_max, randomize_noise, architecture, nonlinearity, dtype, resample_kernel, fused_modconv, **_kwargs)

<string> in layer(x, layer_idx, fmaps, kernel, up)

<string> in modulated_conv2d_layer(x, y, fmaps, kernel, up, down, demodulate, resample_kernel, gain, use_wscale, lrmul, fused_modconv, weight_var, mod_weight_var, mod_bias_var)

<string> in apply_bias_act(x, act, alpha, gain, lrmul, bias_var)

~\painter\stylegan2\dnnlib\tflib\ops\fused_bias_act.py in fused_bias_act(x, b, axis, act, alpha, gain, impl)
     66         'cuda': _fused_bias_act_cuda,
     67     }
---> 68     return impl_dict[impl](x=x, b=b, axis=axis, act=act, alpha=alpha, gain=gain)
     69 
     70 #----------------------------------------------------------------------------

~\painter\stylegan2\dnnlib\tflib\ops\fused_bias_act.py in _fused_bias_act_cuda(x, b, axis, act, alpha, gain)
    120 
    121     # CUDA kernel.
--> 122     cuda_kernel = _get_plugin().fused_bias_act
    123     cuda_kwargs = dict(axis=axis, act=act_spec.cuda_idx, alpha=alpha, gain=gain)
    124 

~\painter\stylegan2\dnnlib\tflib\ops\fused_bias_act.py in _get_plugin()
     14 
     15 def _get_plugin():
---> 16     return custom_ops.get_plugin(os.path.splitext(__file__)[0] + '.cu')
     17 
     18 #----------------------------------------------------------------------------

~\painter\stylegan2\dnnlib\tflib\custom_ops.py in get_plugin(cuda_file)
    109             with tempfile.TemporaryDirectory() as tmp_dir:
    110                 tmp_file = os.path.join(tmp_dir, cuda_file_name + '_tmp' + cuda_file_ext)
--> 111                 _run_cmd(_prepare_nvcc_cli('"%s" --preprocess -o "%s" --keep --keep-dir "%s"' % (cuda_file, tmp_file, tmp_dir)))
    112                 with open(tmp_file, 'rb') as f:
    113                     bad_file_str = ('"' + cuda_file.replace('\\', '/') + '"').encode('utf-8') # __FILE__ in error check macros

~\painter\stylegan2\dnnlib\tflib\custom_ops.py in _run_cmd(cmd)
     59         status = pipe.close()
     60     if status is not None:
---> 61         raise RuntimeError('NVCC returned an error. See below for full command line and output log:\n\n%s\n\n%s' % (cmd, output))
     62 
     63 def _prepare_nvcc_cli(opts):

RuntimeError: NVCC returned an error. See below for full command line and output log:

nvcc "C:\Users\hoge\painter\stylegan2\dnnlib\tflib\ops\fused_bias_act.cu" --preprocess -o "C:\Users\hoge\AppData\Local\Temp\tmpgwzv8k1u\fused_bias_act_tmp.cu" --keep --keep-dir "C:\Users\hoge\AppData\Local\Temp\tmpgwzv8k1u" --disable-warnings --include-path "C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\include" --include-path "C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\include\external\protobuf_archive\src" --include-path "C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\include\external\com_google_absl" --include-path "C:\Users\hoge\anaconda3\envs\twne\lib\site-packages\tensorflow\include\external\eigen_archive" --compiler-bindir "C:/Program Files (x86)/Microsoft Visual Studio 14.0/vc/bin" 2>&1

nvcc fatal   : nvcc cannot find a supported version of Microsoft Visual Studio. Only the versions between 2017 and 2019 (inclusive) are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk.

しかし、Visual Studio 2019はインストール済みで、実際、他の仮想環境ではtensorflowではありませんが、GPUを利用したシステムが動いています。
どうすればいいでしょうか?

1 件の回答 1

0

Visual Studio installerを起動し[変更]ボタンを押すと、インストール詳細欄の『MSVC140 - VS 2015 C++...』のチェックボックスにチェックが付いていたのでチェックをはずして[変更]。
"C:\Program Files (x86)\Microsoft Visual Studio 14.0"が消えたので再度Pythonコードを実行すると今度は「\stylegan2\dnnlib\tflib\custom_ops.pyのcompiler_bindir_search_pathを確認しろ」というエラーが出るので確認したところ、以下のようになっていました。

'C:/Program Files (x86)/Microsoft Visual studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64',
'C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64',
'C:/Program Files (x86)/Microsoft Visual Studio 14.0/vc/bin',

1行目と3行目を消し、2行目の14.23.28105を実際のナンバリングに書き換え、Anacondaを再起動したとこ上手くいきました。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。