# 无效参数错误：赋值要求两个张量的形状匹配。左形状= [100,256] 右形状= [200,256]

- **ID:** `tensorflow/checkpoint-incompatible-shape`
- **领域:** tensorflow
- **类别:** runtime_error
- **错误码:** `CIS`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试将检查点恢复到模型时，由于模型架构更改，层形状与保存的检查点不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| tensorflow 2.10 | active | — | — |
| tensorflow 2.11 | active | — | — |
| tensorflow 2.12 | active | — | — |

## 解决方案

1. ```
   Modify the model to match the checkpoint shapes. For example, if the checkpoint has a Dense layer with 256 units but your model has 200 units, change to 256: model.add(tf.keras.layers.Dense(256)). Then restore: model.load_weights('path/to/checkpoint').
   ```
2. ```
   Use load_weights with by_name=True and skip_mismatch=True to load only matching layers: model.load_weights('path/to/checkpoint', by_name=True, skip_mismatch=True)
   ```

## 无效尝试

- **Deleting and recreating the checkpoint file** — The checkpoint is valid; the problem is the model definition mismatch. Deleting the checkpoint loses training progress without addressing the root cause. (90% 失败率)
- **Changing learning rate or optimizer** — The error is about tensor shape mismatch during assignment, not optimization hyperparameters. (99% 失败率)
