【解決方法】Modulenotfounderror: ‘keras.utils.multi_gpu_utils’ という名前のモジュールがありません

[ad_1]

私はanaconda Spyderでこのコードを実行しようとしています

Python
import tensorflow as tf
from tensorflow.python import keras
from keras.models import Model
from keras.models import load_model
from keras.optimizers import Adam
from keras.layers import Input, Conv2D, UpSampling2D, Dropout, LeakyReLU, BatchNormalization, Activation, Lambda
from tensorflow.keras.layers import Concatenate
from keras.applications import VGG16
from keras import backend as K
from keras.utils.multi_gpu_utils import multi_gpu_model  --->error

このコードはこの行でエラーを出しています

Python
from keras.utils.multi_gpu_utils import multi_gpu_model

エラーは

Python
ModuleNotFoundError: No module named 'keras.utils.multi_gpu_utils'

この問題を解決するにはどうすればよいですか?

私が試したこと:

tensorflow-gpu をインストールするためのコマンドを実行しました

Python
pip3 install tensorflow-gpu

しかし、次のエラーが発生し、実行が停止します

Python
Collecting tensorflow-gpu
      Using cached tensorflow-gpu-2.12.0.tar.gz (2.6 kB)
      Preparing metadata (setup.py) ... error
      error: subprocess-exited-with-error
    
      × python setup.py egg_info did not run successfully.
      │ exit code: 1
      ╰─> [39 lines of output]
          Traceback (most recent call last):
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\_vendor\packaging\requirements.py", line 35, in __init__
              parsed = parse_requirement(requirement_string)
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\_vendor\packaging\_parser.py", line 64, in parse_requirement
              return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\_vendor\packaging\_parser.py", line 82, in _parse_requirement
              url, specifier, marker = _parse_requirement_details(tokenizer)
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\_vendor\packaging\_parser.py", line 126, in _parse_requirement_details
              marker = _parse_requirement_marker(
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\_vendor\packaging\_parser.py", line 147, in _parse_requirement_marker
              tokenizer.raise_syntax_error(
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\_vendor\packaging\_tokenizer.py", line 163, in raise_syntax_error
              raise ParserSyntaxError(
          setuptools.extern.packaging._tokenizer.ParserSyntaxError: Expected end or semicolon (after name and no valid version specifier)
              python_version>"3.7"
                            ^
    
          The above exception was the direct cause of the following exception:
    
          Traceback (most recent call last):
            File "<string>", line 2, in <module>
            File "<pip-setuptools-caller>", line 34, in <module>
            File "C:\Users\hp\AppData\Local\Temp\pip-install-ovwye3d5\tensorflow-gpu_8fc59815d9a64f798e39953c26d47c5b\setup.py", line 40, in <module>
              setuptools.setup()
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\__init__.py", line 106, in setup
              _install_setup_requires(attrs)
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\__init__.py", line 77, in _install_setup_requires
              dist.parse_config_files(ignore_option_errors=True)
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\dist.py", line 910, in parse_config_files
              self._finalize_requires()
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\dist.py", line 607, in _finalize_requires
              self._move_install_requirements_markers()
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\dist.py", line 647, in _move_install_requirements_markers
              inst_reqs = list(_reqs.parse(spec_inst_reqs))
            File "C:\Users\hp\anaconda3\lib\site-packages\setuptools\_vendor\packaging\requirements.py", line 37, in __init__
              raise InvalidRequirement(str(e)) from e
          setuptools.extern.packaging.requirements.InvalidRequirement: Expected end or semicolon (after name and no valid version specifier)
              python_version>"3.7"
                            ^
          [end of output]
    
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: metadata-generation-failed
    
    × Encountered error while generating package metadata.
    ╰─> See above for output.
    
    note: This is an issue with the package mentioned above, not pip.
    hint: See above for details.

注:私のPCにはありません NVIDIA GUP しかし、それは持っています ラデオン GPU

解決策 1

TensorFlow が nVidia 固有の CUDA によって支えられていることを考えると、少し問題があります。

見る TensorFlow は AMD GPU で実行できますか? – クオラ[^].

[ad_2]

コメント

タイトルとURLをコピーしました