代码:
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 已被弃用,将来会被删除,我还能使用这个版本多久,我该如何删除所有这些警告?
由于您在 中执行代码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] 删除。
我来说两句