Tensorflow模型未在GPU(Windows)上运行
因此,我一直在使用tensorflow和python创建一些运行模型。 使用CPU,这些型号运行没有问题。此后,我激活了CUDA和CUDnn软件包,使模型能够通过GPU运行。但是,我在执行模型时遇到了这个持续的错误: 为了测试GPU,代码从sentdex youtube频道复制 错误来自model=keras.Sequential()函数,我无法找出问题所在。 先谢谢你**Tensorflow模型未在GPU(Windows)上运行,windows,tensorflow,gpu,python-3.8,Windows,Tensorflow,Gpu,Python 3.8,因此,我一直在使用tensorflow和python创建一些运行模型。 使用CPU,这些型号运行没有问题。此后,我激活了CUDA和CUDnn软件包,使模型能够通过GPU运行。但是,我在执行模型时遇到了这个持续的错误: 为了测试GPU,代码从sentdex youtube频道复制 错误来自model=keras.Sequential()函数,我无法找出问题所在。 先谢谢你** from tensorflow.keras.datasets import fashion_mnist import ma
from tensorflow.keras.datasets import fashion_mnist
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import Dense, Conv2D, Activation, Flatten,
MaxPooling2D
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
x_train = x_train.reshape(-1, 28, 28, 1)
x_test = x_test.reshape(-1, 28, 28, 1)
def build_model():
model = keras.Sequential()
model.add(Conv2D(32, (3, 3), input_shape=x_train.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(10))
model.add(Activation("softmax"))
model.compile(optimizer="adam",
loss="sparse_categorical_crossentropy",
metrics=["accuracy"])
return model
model = build_model()
model.summary()
model.fit(x_train, y_train, batch_size=64, epochs=5, validation_data=
(x_test, y_test))
2020-11-16 10:41:11.551836:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]成功打开动态库cudart64_101.dll
2020-11-16 10:41:14.835405:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库nvcuda.dll
2020-11-16 10:41:15.235376:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716]找到了具有以下属性的设备0:
pciBusID:0000:01:00.0名称:GeForce GTX 960M计算能力:5.0
核心时钟:1.0975GHz核心计数:5设备内存大小:2.00GiB设备内存带宽:74.65GiB/s
2020-11-16 10:41:15.236058:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cudart64_101.dll
2020-11-16 10:41:15.241600:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cublas64_10.dll
2020-11-16 10:41:15.246735:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cufft64_10.dll
2020-11-16 10:41:15.248925:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库库库和64_10.dll
2020-11-16 10:41:15.257315:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cusolver64_10.dll
2020-11-16 10:41:15.263949:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cusparse64_10.dll
2020-11-16 10:41:15.277163:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cudnn64_7.dll
2020-11-16 10:41:15.277600:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858]添加可见gpu设备:0
2020-11-16 10:41:15.278553:I tensorflow/core/platform/cpu_feature_guard.cc:142]此tensorflow二进制文件使用oneAPI深度神经网络库(oneDNN)进行优化,以便在性能关键型操作中使用以下cpu指令:AVX2
要在其他操作中启用它们,请使用适当的编译器标志重新生成TensorFlow。
202011-16:10:41: 15.288269:I TysFrace/编译器/ XLA/Service / Service .CC:168)XLA服务0x22E8AAC3EA0初始化为平台主机(这不保证XLA将被使用)。设备:
2020-11-16 10:41:15.288886:I tensorflow/compiler/xla/service/service.cc:176]StreamExecutor设备(0):主机,默认版本
2020-11-16 10:41:15.289482:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716]找到了具有以下属性的设备0:
pciBusID:0000:01:00.0名称:GeForce GTX 960M计算能力:5.0
核心时钟:1.0975GHz核心计数:5设备内存大小:2.00GiB设备内存带宽:74.65GiB/s
2020-11-16 10:41:15.290130:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cudart64_101.dll
2020-11-16 10:41:15.290843:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cublas64_10.dll
2020-11-16 10:41:15.291337:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cufft64_10.dll
2020-11-16 10:41:15.291667:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库库库64_10.dll
2020-11-16 10:41:15.292166:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cusolver64_10.dll
2020-11-16 10:41:15.292568:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cusparse64_10.dll
2020-11-16 10:41:15.292896:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库cudnn64_7.dll
2020-11-16 10:41:15.293290:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858]添加可见gpu设备:0
2020-11-16 10:41:15.371430:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257]设备互连拖缆执行器与强度1边缘矩阵:
2020-11-16 10:41:15.372119:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]0
2020-11-16 10:41:15.372562:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1276]0:N
2020-11-16 10:41:15.373198:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1402]创建tensorflow设备(/job:localhost/replica:0/task:0/device:gpu:0,内存1457MB)->物理gpu(设备:0,名称:GeForce GTX 960M,pci总线id:0000:01:00.0,计算能力:5.0)
202011-16:10:41: 15.379271:I TysFrace/编译器/ XLA/Service / Service。CC:168)XLA服务0x22E8BC9EF20初始化为平台CUDA(这不保证XLA将被使用)。设备:
2020-11-16 10:41:15.379864:I tensorflow/compiler/xla/service/service.cc:176]流执行器设备(0):GeForce GTX 960M,计算能力5.0
回溯(最近一次呼叫最后一次):
文件“C:\Users\inder\Desktop\Fashion\Mnist.py”,第36行,在
模型=构建模型()
文件“C:\Users\inder\Desktop\Fashion\Mnist.py”,第13行,内置模型
模型=keras.Sequential()
文件“C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site packages\tensorflow\Python\training\tracking\base.py”,第457行,在方法包装中
结果=方法(自身、*args、**kwargs)
文件“C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site packages\tensorflow\Python\keras\engine\sequential.py”,第116行,在uu init中__
super(functional.functional,self)。uuu init_uuu(#pylint:disable=错误的超级调用
文件“C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site packa
Traceback (most recent call last):
File "C:\Users\inder\Desktop\Fashion_Mnist.py", line 36, in <module>
model = build_model()
File "C:\Users\inder\Desktop\Fashion_Mnist.py", line 13, in build_model
model = keras.Sequential()
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\tracking\base.py", line 457, in _method_wrapper
result = method(self, *args, **kwargs)
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\engine\sequential.py", line 116, in __init__
super(functional.Functional, self).__init__( # pylint: disable=bad-super-call
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\tracking\base.py", line 457, in _method_wrapper
result = method(self, *args, **kwargs)
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\engine\training.py", line 308, in __init__
self._init_batch_counters()
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\tracking\base.py", line 457, in _method_wrapper
result = method(self, *args, **kwargs)
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\engine\training.py", line 317, in _init_batch_counters
self._train_counter = variables.Variable(0, dtype='int64', aggregation=agg)
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\variables.py", line 262, in __call__
return cls._variable_v2_call(*args, **kwargs)
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\variables.py", line 244, in _variable_v2_call
return previous_getter(
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\variables.py", line 237, in <lambda>
previous_getter = lambda **kws: default_variable_creator_v2(None, **kws)
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 2633, in default_variable_creator_v2
return resource_variable_ops.ResourceVariable(
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\variables.py", line 264, in __call__
return super(VariableMetaclass, cls).__call__(*args, **kwargs)
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 1507, in __init__
self._init_from_args(
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 1661, in _init_from_args
handle = eager_safe_variable_handle(
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 242, in eager_safe_variable_handle
return _variable_handle_from_shape_and_dtype(
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 174, in _variable_handle_from_shape_and_dtype
gen_logging_ops._assert( # pylint: disable=protected-access
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\gen_logging_ops.py", line 49, in _assert
_ops.raise_from_not_ok_status(e, name)
File "C:\Users\inder\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 6843, in raise_from_not_ok_status
six.raise_from(core._status_to_exception(e.code, message), None)
File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [0] [Op:Assert] name: EagerVariableNameReuse
[Finished in 5.0s]