---
title: 预处理batch动作设置drop_remainder
description: "当原始网络脚本中使用dataset.batch(batch_size)返回动态形状时，由于数据流中剩余的样本数可能小于batch大小，导致网络中最后一个step的shape与之前的shape不一致，此种场景下会进入动态shape编译流程。为提升网络编译性能，建议将drop_remainder设置为True，丢弃文件中的最后几个样本，确保网络中每个step的shape一致。"
url: https://www.hiascend.com/document/detail/zh/TensorFlowCommercial/latest/migration/tfmigr2/tfmigr2_000016.html
sourcePath: /source/zh/TensorFlowCommercial/900/migration/tfmigr2/tfmigr2_000016.html
indexId: 2a8f906326c3ffa5c0da2fa3efa56f56a1c248b34b2e275410c2293b82fe639c73
---
# 预处理batch动作设置drop_remainder

当原始网络脚本中使用dataset.batch(batch_size)返回动态形状时，由于数据流中剩余的样本数可能小于batch大小，导致网络中最后一个step的shape与之前的shape不一致，此种场景下会进入动态shape编译流程。为提升网络编译性能，建议将drop_remainder设置为True，丢弃文件中的最后几个样本，确保网络中每个step的shape一致。
```
dataset = dataset.batch(batch_size, drop_remainder=True)
```


关于batch操作的更多细节，请参考链接(https://www.tensorflow.org/api_docs/python/tf/data/Dataset)。
