处理没有 GPU 支持的传统 tensorflow

熊树

代码:

import os
os.envirion['TF_CPP_MIN_LOG_LEVEL']='2'

import numpy as np
import matplotlib.pyplot as plt
from tensorflow import keras
from tensorflow.keras.layers import Dense

c = np.array([-40, -10, -0, 8, 15, 22, 38])
f = np.array([-40, 14, 32, 46, 59, 72, 100])

model = keras.Sequential()
model.add(Dense(units=1,input_shape=(1,), activation='linear'))

model.compile(loss='mean_squared_error', optimizer=keras.optimizers.Adam(0.1))

history = model.fit(c, f, epochs=500, verbose=0)

plt.plot(history.history['loss'])
plt.grid(True)
plt.show()

print(model.get_weights())

我不需要CUDA工作(而且我无法在amd上安装它)并且CPU就足够了。在没有 GPU 支持的情况下安装了 tensorflow 1.15,前两行代码似乎隐藏了没有 CUDA 的警告,但它们根本不起作用:

Traceback (most recent call last):
  File "C:/Users/krist/PycharmProjects/newpy/exam1.py", line 2, in <module>
    os.envirion['TF_CPP_MIN_LOG_LEVEL']='2'
AttributeError: module 'os' has no attribute 'envirion'

没有它们也能工作,但有很多警告:

    2021-02-13 15:06:56.460608: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2021-02-13 15:06:56.460848: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
WARNING:tensorflow:From C:\Users\krist\miniconda3\envs\newpy\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
2021-02-13 15:06:58.537138: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2021-02-13 15:06:59.115843: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce GTX 1650 major: 7 minor: 5 memoryClockRate(GHz): 1.56
pciBusID: 0000:01:00.0
2021-02-13 15:06:59.117006: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2021-02-13 15:06:59.117956: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cublas64_100.dll'; dlerror: cublas64_100.dll not found
2021-02-13 15:06:59.118915: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cufft64_100.dll'; dlerror: cufft64_100.dll not found
2021-02-13 15:06:59.119933: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'curand64_100.dll'; dlerror: curand64_100.dll not found
2021-02-13 15:06:59.120970: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cusolver64_100.dll'; dlerror: cusolver64_100.dll not found
2021-02-13 15:06:59.122001: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cusparse64_100.dll'; dlerror: cusparse64_100.dll not found
2021-02-13 15:06:59.122953: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2021-02-13 15:06:59.123152: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1641] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2021-02-13 15:06:59.123868: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-02-13 15:06:59.201911: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-02-13 15:06:59.202095: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]   

这里有点说 tensorflow 已被弃用,将来会被删除,我还能使用这个版本多久,我该如何删除所有这些警告?

TFer2

由于您在 中执行代码TF 1.15,因此您会收到不推荐使用的警告。升级到Tensorflow 2.x.

AttributeError: 模块“os”没有属性“envirion”

如果您可以更正周围的拼写,则可以解决

工作代码如下图

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import Adam


c = np.array([-40, -10, -0, 8, 15, 22, 38])
f = np.array([-40, 14, 32, 46, 59, 72, 100])

model = Sequential()
model.add(Dense(units=1,input_shape=(1,), activation='linear'))

model.compile(loss='mean_squared_error', optimizer= Adam(0.1))

history = model.fit(c, f, epochs=500, verbose=0)

plt.plot(history.history['loss'])
plt.grid(True)
plt.show()
print(model.get_weights())

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TensorFlow:没有可用的GPU设备支持的内核

具有GPU支持的TensorFlow操作

导入具有GPU支持的TensorFlow时DLL加载失败

tensorflow 2.2 GPU支持Windows

TensorFlow没有使用GPU

Amazon EC2 Tensorflow GPU支持

xgboost安装在tensorflow GPU支持上

Tensorflow Gpu支持,检查tf是否正在使用我的GPU?

具有GPU支持的特定版本的Tensorflow的最强大方法

Tensorflow似乎没有看到我的GPU

没有NVIDIA的Tensorflow-GPU,可能吗?

Keras没有检测到GPU,但是tensorflow是

在wsl2上使用gpu的tensorflow没有学习

Tensorflow-GPU仍在CPU上处理

tensorflow.python.pywrap_tensorflow_internal没有模块Windows 10 tensorflow gpu

具有多个GPU的TensorFlow XLA不能同时使用GPU

具有Keras错误的Tensorflow-gpu

在带有gpu的docker内部使用tensorflow

TensorFlow的./configure在哪里,以及如何启用GPU支持?

tensorflow-gpu 和 tensorflow 有什么区别?

Windows 上的 Tensorflow-gpu:ImportError:没有名为 _pywrap_tensorflow 的模块

需要 tensorflow-gpu 时“没有名为 tensorflow 的模块”

在GPU支持下安装tensorflow。安装GPU必备组件后缺少libcublas.so.9.0

Tensorflow:特定gpu设备下的dynamic_rnn无法正常工作,GPU设备不支持受支持的内核

有没有办法确定TensorFlow使用了多少GPU内存?

Tensorflow(Keras)和多处理导致GPU内存不足

与TensorFlow并行在多个小批处理上训练GPU

如何使用tensorflow-gpu对子任务进行多处理?

tensorflow,tensorflow-gpu 无法识别 GPU