python - 通过 keras API 保存 tensorflow 2.0 模型时发出警告
问题描述
Model.save()
在 tensorflow 2.0 中调用keras 提供的方法时,出现了两个关于弃用操作的警告。下面附上交互模式下的简单复制
Python 3.8.3 (default, Jul 2 2020, 16:21:59)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
2020-10-28 13:49:38.380026: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
>>> from tensorflow import keras
>>> inputs = keras.layers.Input(shape=(10, 10, 1), dtype="float32")
>>> outputs = keras.layers.Dense(2, activation="softmax")(inputs)
2020-10-28 13:50:33.646242: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcuda.so.1
2020-10-28 13:50:34.487222: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:65:00.0 name: GeForce RTX 2080 Ti computeCapability: 7.5
coreClock: 1.545GHz coreCount: 68 deviceMemorySize: 10.76GiB deviceMemoryBandwidth: 573.69GiB/s
2020-10-28 13:50:34.487258: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
2020-10-28 13:50:34.488671: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.10
2020-10-28 13:50:34.490066: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcufft.so.10
2020-10-28 13:50:34.490334: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcurand.so.10
2020-10-28 13:50:34.491816: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusolver.so.10
2020-10-28 13:50:34.492589: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusparse.so.10
2020-10-28 13:50:34.495732: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudnn.so.7
2020-10-28 13:50:34.496509: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
2020-10-28 13:50:34.496780: 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 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-10-28 13:50:34.519843: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 3799900000 Hz
2020-10-28 13:50:34.520483: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5584831adac0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-10-28 13:50:34.520504: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2020-10-28 13:50:34.592987: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x558483219530 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-10-28 13:50:34.593047: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): GeForce RTX 2080 Ti, Compute Capability 7.5
2020-10-28 13:50:34.594379: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:65:00.0 name: GeForce RTX 2080 Ti computeCapability: 7.5
coreClock: 1.545GHz coreCount: 68 deviceMemorySize: 10.76GiB deviceMemoryBandwidth: 573.69GiB/s
2020-10-28 13:50:34.594439: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
2020-10-28 13:50:34.594477: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.10
2020-10-28 13:50:34.594503: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcufft.so.10
2020-10-28 13:50:34.594528: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcurand.so.10
2020-10-28 13:50:34.594553: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusolver.so.10
2020-10-28 13:50:34.594578: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusparse.so.10
2020-10-28 13:50:34.594603: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudnn.so.7
2020-10-28 13:50:34.595938: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
2020-10-28 13:50:34.595979: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
2020-10-28 13:50:34.981431: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-10-28 13:50:34.981470: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263] 0
2020-10-28 13:50:34.981475: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1276] 0: N
2020-10-28 13:50:34.982333: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1402] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10063 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2080 Ti, pci bus id: 0000:65:00.0, compute capability: 7.5)
>>> model = keras.Model(inputs=inputs, outputs=outputs)
>>> model.save("test")
WARNING:tensorflow:From /home/boris/anaconda3/lib/python3.8/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-28 13:51:05.487175: 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 /home/boris/anaconda3/lib/python3.8/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.
INFO:tensorflow:Assets written to: test/assets
>>>
即使在保存一个非常简单的模型时也会出现此警告消息,这让我感到困惑。
我正在使用的确切版本是 tensorflow 2.3.1 和 python 3.8.3。
解决方案
这些是关于不推荐使用的函数的警告,它告诉 Tensorflow 用户它将在未来的版本中被删除。您可以使用以下代码抑制这些警告。
import logging, os
logging.disable(logging.WARNING)
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
import tensorflow as tf
推荐阅读
- swift - 结合框架流转换 ['a','b','c'] -> 'a' then 'b' then 'c'
- c++ - 什么决定了 STL 容器中的 max_size?
- azure - Azure Devops:安装 Windows 服务
- functional-programming - 你能用 Mendler 式的变形写一个无限循环吗?
- c# - 从 ObservableCollection 中移除项目
- discord.js - 机器人不会尽快收集消息
- php - 根据 WooCommerce 3+ 中的用户角色添加自定义我的帐户菜单项
- c# - 从 Datatable C# 中动态选择列
- android - Android viewpager2内部滑动刷新布局
- ansible - 在 Ansible 中使用“json_query”时出错