tensorflow 2.16.1 can not use save and load

作者在升级到Keras2.15.0时遇到问题,BatchNormalization层不接受参数。讨论了如何在新版本中正确配置多输出模型的损失函数、指标和权重。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

already use model.save(). not use the load weight. the question is : self.b1 = BatchNormalization(), in my code, the BatchNormalization(), do not take any parameter, why Layer 'batch_normalization_20' expected 4 variables?

Sent by you: already use model.save(). not use the load weight. the question is : self.b1 = BatchNormalization(), in my code, the BatchNormalization(), do not take any parameter, why Layer 'batch_normalization_20' expected 4 variables?

change to 2.15.0 , it is ok. but a lot of change on 

model_res_net.compile(optimizer=optimizer,
                      # loss=[tf.keras.losses.CategoricalCrossentropy(from_logits=False)] * 4,
                      # # metrics=['categorical_accuracy'] * 4,
                      # metrics=[tf.keras.metrics.CategoricalAccuracy(name='categorical_accuracy'),
                      #          tf.keras.metrics.CategoricalAccuracy(name='categorical_accuracy_1'),
                      #          tf.keras.metrics.CategoricalAccuracy(name='categorical_accuracy_2'),
                      #          tf.keras.metrics.CategoricalAccuracy(name='categorical_accuracy_3')],
                      loss={'output_1': tf.keras.losses.CategoricalCrossentropy(from_logits=False),
                            'output_2': tf.keras.losses.CategoricalCrossentropy(from_logits=False),
                            'output_3': tf.keras.losses.CategoricalCrossentropy(from_logits=False),
                            'output_4': tf.keras.losses.CategoricalCrossentropy(from_logits=False)},
                      metrics={
                          'output_1': tf.keras.metrics.CategoricalAccuracy(name='acc'),
                          'output_2': tf.keras.metrics.CategoricalAccuracy(name='acc'),
                          'output_3': tf.keras.metrics.CategoricalAccuracy(name='acc'),
                          'output_4': tf.keras.metrics.CategoricalAccuracy(name='acc')},
                      loss_weights=[1.0, 1.0, 1.0, 1.0]
                      )
### 安装 TensorFlow 2.16.1 及其兼容的 Keras 版本 为了确保 TensorFlow 2.16.1 和 Keras 能够顺利配合工作,建议按照以下方法进行安装: #### 创建虚拟环境并激活 创建一个新的 Python 虚拟环境有助于隔离依赖项,防止不同项目之间的冲突。 ```bash python -m venv tf_venv source tf_venv/bin/activate # Linux 或 macOS tf_venv\Scripts\activate # Windows ``` #### 更新 pip 工具至最新版 确保 `pip` 是最新的可以帮助避免因工具过旧而引发的各种问题。 ```bash pip install --upgrade pip ``` #### 安装指定版本的 TensorFlow 通过指定确切版本号来安装 TensorFlow 2.16.1。这一步骤对于保证软件包间的兼容性至关重要。 ```bash pip install tensorflow==2.16.1 ``` #### 验证安装成功与否 可以通过导入模块的方式验证 TensorFlow 是否已正确安装。 ```python import tensorflow as tf print(tf.__version__) ``` #### 安装匹配的 Keras 版本 鉴于 TensorFlow 自带集成了一部分 Keras 功能,通常情况下不需要单独再安装 Keras 库;但如果确实有需求,则应选择与当前使用的 TensorFlow 版本相适应的具体版本。根据已有信息显示,当使用 TensorFlow 2.16.x 时,应该配套安装相同次版本系列中的 Keras,即大约为 2.16.x 的范围内的稳定发布版本[^3]。 ```bash pip install keras==2.16.0 # 假设这是最接近且稳定的版本 ``` 需要注意的是,在某些特殊场景下可能还需要额外配置 CUDA、cuDNN 等 GPU 支持组件,具体取决于目标硬件平台和个人开发需求[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值