运行 Tensorflow 模型 model_main_tf2.py 有语法错误

Running Tensorflow model model_main_tf2.py has SyntaxError

我使用 tensorflow 模型训练我的数据集,运行

python3 model_main_tf2.py \
    --model_dir=/home/123/Documents/tf//train \
    --pipeline_config_path=/home/123/Documents/tf/ssd_mobilenet_v2_coco.config \
    --alsologtostderr

在终端中,几分钟后出现错误:

File "/home/123/venv/lib/python3.5/site-packages/tensorflow/models/official/vision/image_classification/efficientnet/efficientnet_model.py", line 44
    input_filters: int = 0
                 ^
SyntaxError: invalid syntax

我试着改成

input_filters = int(0)

还可以,但是还有一个错误,所以我改回来了。也许 python 版本不匹配或其他原因,我不知道。

我的python版本是3.5.2,tensorflow版本是CPU2.1.0

代码正在使用 type hints on variables。支持这些的最低 Python 版本是 3.6,因此您需要升级 Python 安装(Python 3.5 现在 相当 旧)。