gpt4 book ai didi

python - 如何解决AttributeError : module 'tensorflow._api.v2.distribute' has no attribute 'TPUStrategy'

转载 作者:行者123 更新时间:2023-12-04 17:22:09 27 4
gpt4 key购买 nike

我正在使用 Keras 和 Tensorflow 来创建预测模型。我只有 CPU 设备,无法执行我的代码。代码中只使用 Keras 和 Kerastuner 搜索超参数。这是错误跟踪:

File "file.py", line 537, in <Module>
params,tuner = search_model(X_train,y_train,trials=t,executions=e)
File "file.py", line 503, in search_model
verbose = 0
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/base_tuner.py", line 131, in search
self.run_trial(trial, *fit_args, **fit_kwargs)
File "file.py", line 476, in run_trial
super(MyTuner, self).run_trial(trial, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/multi_execution_tuner.py", line 78,
trial.trial_id, self._reported_step),
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/tuner.py", line 317, in _get_checkp
if (isinstance(self.distribution_strategy, tf.distribute.TPUStrategy) and
AttributeError: module 'tensorflow._api.v2.distribute' has no attribute 'TPUStrategy'

我试过这样的事情:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'

或:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

或:

with tf.device("/cpu:0"):

没有任何作用。这是我的信息设备:

>>> from tensorflow.python.client import device_lib
>>> print(device_lib.list_local_devices())
2021-01-04 20:10:34.173749: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA
2021-01-04 20:10:34.217597: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2100000000 Hz
2021-01-04 20:10:34.225175: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f3c8c000b20 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-01-04 20:10:34.225243: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2021-01-04 20:10:34.229506: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2021-01-04 20:10:34.229542: E tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: UNKNOWN ERROR (303)
2021-01-04 20:10:34.229584: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (estio108): /proc/driver/nvidia/version does not exist
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 5882703391360358162
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 18109344296496597660
physical_device_desc: "device: XLA_CPU device"
]

非常感谢您的帮助。

最佳答案

您必须将 Tensorflow 更新到版本 2.3 或更高版本 - 这就是 TPUStrategy 的位置加入。这是您对此的线索:

AttributeError: module 'tensorflow._api.v2.distribute' has no attribute 'TPUStrategy'

在这种情况下,这无关紧要,因为您将使用 CPU。

关于python - 如何解决AttributeError : module 'tensorflow._api.v2.distribute' has no attribute 'TPUStrategy' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65569050/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com