Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用tf.keras保存模型_Python_Tensorflow - Fatal编程技术网

Python 使用tf.keras保存模型

Python 使用tf.keras保存模型,python,tensorflow,Python,Tensorflow,我试图用tensorflow.keras创建并保存一个模型,但我遇到了很多问题。 这个模型不太好用,但这不是我的问题。我的问题是,为什么在保存模型后,它的精度似乎比保存前的精度低得多 导入tensorflow作为tf 从matplotlib导入pyplot作为plt 将numpy作为np导入 mnist=tf.keras.datasets.mnist#28x28手写数字0-9的图像 (x_列,y_列),(x_测试,y_测试)=列表负载数据() x_列=tf.keras.utils.normal

我试图用tensorflow.keras创建并保存一个模型,但我遇到了很多问题。 这个模型不太好用,但这不是我的问题。我的问题是,为什么在保存模型后,它的精度似乎比保存前的精度低得多


导入tensorflow作为tf
从matplotlib导入pyplot作为plt
将numpy作为np导入
mnist=tf.keras.datasets.mnist#28x28手写数字0-9的图像
(x_列,y_列),(x_测试,y_测试)=列表负载数据()
x_列=tf.keras.utils.normalize(x_列,轴=1)
x_检验=tf.keras.utils.normalize(x_检验,轴=1)
model=tf.keras.models.Sequential()
添加(tf.keras.layers.flatte())
添加(tf.keras.layers.Dense(128,activation=tf.nn.relu))
添加(tf.keras.layers.Dense(128,activation=tf.nn.relu))
添加(tf.keras.layers.density(10,activation=tf.nn.softmax))
compile(优化器='adam',loss='sparse\u categorical\u crossentropy',metrics=['accurity'])
模型拟合(x_序列,y_序列,历次=3)
model.save('plz\u help\u me.model'))
model2=tf.keras.models.load\u model('plz\u help\u me.model'))
val_损失,val_acc=模型评估(x_测试,y_测试)
打印('1',val_损失,val_acc)
val_损失,val_acc=模型2.评估(x_测试,y_测试)
打印('2',val_损失,val_acc)
预测=模型预测([x_列车])
预测2=模型2.预测([x_列车])
打印('1',np.argmax(预测[1]))
打印('2',np.argmax(predictions2[1]))
plt.imshow(x_测试[1])
plt.show()
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
通过
这是代码的输出:

C:\Users\orlav\AppData\Local\Programs\Python\Python38\python.exe C:/Users/orlav/PycharmProjects/Something/main.py
2020-10-08 23:54:38.887274: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-10-08 23:54:38.888161: 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.
2020-10-08 23:54:42.642227: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2020-10-08 23:54:42.792796: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1050 computeCapability: 6.1
coreClock: 1.493GHz coreCount: 5 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 104.43GiB/s
2020-10-08 23:54:42.794152: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-10-08 23:54:42.795310: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cublas64_10.dll'; dlerror: cublas64_10.dll not found
2020-10-08 23:54:42.796412: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2020-10-08 23:54:42.797522: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2020-10-08 23:54:42.798629: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found
2020-10-08 23:54:42.799721: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusparse64_10.dll'; dlerror: cusparse64_10.dll not found
2020-10-08 23:54:42.800818: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2020-10-08 23:54:42.801353: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] 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...
2020-10-08 23:54:42.802400: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-10-08 23:54:42.811599: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1fe341d78f0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-10-08 23:54:42.811854: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-10-08 23:54:42.812111: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-10-08 23:54:42.812296: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]      
Epoch 1/3
1875/1875 [==============================] - 2s 988us/step - loss: 0.2650 - accuracy: 0.9232
Epoch 2/3
1875/1875 [==============================] - 2s 908us/step - loss: 0.1097 - accuracy: 0.9659
Epoch 3/3
1875/1875 [==============================] - 2s 917us/step - loss: 0.0739 - accuracy: 0.9768
WARNING:tensorflow:From C:\Users\orlav\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\tracking\tracking.py:111: Model.state_updates (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.
2020-10-08 23:54:49.005250: W tensorflow/python/util/util.cc:348] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
WARNING:tensorflow:From C:\Users\orlav\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\tracking\tracking.py:111: Layer.updates (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.
313/313 [==============================] - 0s 2ms/step - loss: 0.1038 - accuracy: 0.9679
1 0.10376297682523727 0.9678999781608582
313/313 [==============================] - 0s 676us/step - loss: 0.1038 - accuracy: 0.0972
2 0.10376297682523727 0.09719999879598618
WARNING:tensorflow:Layers in a Sequential model should only have a single input tensor, but we receive a <class 'tuple'> input: (<tf.Tensor 'IteratorGetNext:0' shape=(32, 28, 28) dtype=float32>,)
Consider rewriting this model with the Functional API.
1 0
2 0

Process finished with exit code 0
C:\Users\orlav\AppData\Local\Programs\Python\Python38\Python.exe C:/Users/orlav/PycharmProjects/Something/main.py
2020-10-08 23:54:38.887274:W tensorflow/stream_executor/platform/default/dso_loader.cc:59]无法加载动态库“cudart64_101.dll”;错误:找不到cudart64_101.dll
2020-10-08 23:54:38.888161:I tensorflow/stream_executor/cuda/cudart_stub.cc:29]如果您的机器上没有设置GPU,请忽略上面的cudart dler错误。
2020-10-08 23:54:42.642227:I tensorflow/stream_executor/platform/default/dso_loader.cc:48]已成功打开动态库nvcuda.dll
2020-10-08 23:54:42.792796:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716]找到了具有以下属性的设备0:
pciBusID:0000:01:00.0名称:GeForce GTX 1050计算能力:6.1
核心时钟:1.493GHz核心计数:5个设备内存大小:4.00GiB设备内存带宽:104.43GiB/s
2020-10-08 23:54:42.794152:W tensorflow/stream_executor/platform/default/dso_loader.cc:59]无法加载动态库“cudart64_101.dll”;错误:找不到cudart64_101.dll
2020-10-08 23:54:42.795310:W tensorflow/stream_executor/platform/default/dso_loader.cc:59]无法加载动态库“cublas64_10.dll”;D错误:未找到cublas64_10.dll
2020-10-08 23:54:42.796412:W tensorflow/stream_executor/platform/default/dso_loader.cc:59]无法加载动态库“cufft64_10.dll”;错误:未找到cufft64_10.dll
2020-10-08 23:54:42.797522:W tensorflow/stream_executor/platform/default/dso_loader.cc:59]无法加载动态库“curand64_10.dll”;数据错误:未找到curand64_10.dll
2020-10-08 23:54:42.798629:W tensorflow/stream_executor/platform/default/dso_loader.cc:59]无法加载动态库“cusolver64_10.dll”;错误:找不到cusolver64_10.dll
2020-10-08 23:54:42.799721:W tensorflow/stream_executor/platform/default/dso_loader.cc:59]无法加载动态库“cusparse64_10.dll”;错误:找不到CUSPASSE64_10.dll
2020-10-08 23:54:42.800818:W tensorflow/stream_executor/platform/default/dso_loader.cc:59]无法加载动态库“cudnn64_7.dll”;数据错误:未找到cudnn64_7.dll
2020-10-08 23:54:42.801353:W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753]无法打开某些gpu库。如果您想使用GPU,请确保正确安装了上述缺失的库。请按照以下指南操作:https://www.tensorflow.org/install/gpu 了解如何下载和设置平台所需的库。
正在跳过注册GPU设备。。。
2020-10-08 23:54:42.802400:I tensorflow/core/platform/cpu_feature_guard.cc:142]此tensorflow二进制文件使用oneAPI深度神经网络库(oneDNN)进行优化,以便在性能关键型操作中使用以下cpu指令:AVX2
要在其他操作中启用它们,请使用适当的编译器标志重新生成TensorFlow。
2020 XLA XOR/XLAS/Service/Service .CC:168)XLA服务0x1FE131D78F0初始化为平台主机(这不保证XLA将被使用)。设备:
2020-10-08 23:54:42.811854:I tensorflow/compiler/xla/service/service.cc:176]StreamExecutor设备(0):主机,默认版本
2020-10-08 23:54:42.812111:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257]设备互连拖缆执行器与强度1边缘矩阵:
2020-10-08 23:54:42.812296:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]
纪元1/3
1875/1875[====================================]2s 988us/步长-损耗:0.2650-精度:0.9232
纪元2/3
1875/1875[=======================================]-2s 908us/步长-损耗:0.1097-精度:0.9659
纪元3/3
1875/1875[====================================]-2s 917us/步长-损耗:0.0739-精度:0.9768
警告:tensorflow:From C:\Users\orlav\AppData\Local\Programs\Python38\lib\site packages\tensorflow\Python\tracking\tracking.py:111:Model.state\u更新(来自tensorflow.Python.keras.engine.training)已被弃用,并将在未来版本中删除。
更新说明:
此属性不应在TensorFlow 2.0中使用,因为会自动应用更新。
2020-10-08 23∶54:49.005250:W TunSoFrase/Python/UTIL/UTIL.CC:348)集合目前不被认为是序列,但是这在将来可能会改变,所以考虑避免使用它们。
警告:tensorflow:From C:\Users\orlav\AppData\Local\Programs\Python\Python38\lib\site packages\tensorflow\Python\training\tracking\tracking.py:111:Layer.updates(来自tens)