AttributeError: 'Model' object has no attribute 'target_tensors'

 使用TPU时候碰到的问题,

完整问题复现如下:

WARNING:tensorflow:Keras support is now deprecated in support of TPU Strategy. Please follow the distribution strategy guide on tensorflow.org to migrate to the 2.0 supported version.
INFO:tensorflow:Querying Tensorflow master (grpc://10.94.17.170:8470) for TPU system metadata.
INFO:tensorflow:Found TPU system:
INFO:tensorflow:*** Num TPU Cores: 8
INFO:tensorflow:*** Num TPU Workers: 1
INFO:tensorflow:*** Num TPU Cores Per Worker: 8
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:CPU:0, CPU, -1, 5318427542844900690)
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:TPU:0, TPU, 17179869184, 16868474098292505710)
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:TPU:1, TPU, 17179869184, 7432862407376987853)
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:TPU:2, TPU, 17179869184, 8452046943043630676)
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:TPU:3, TPU, 17179869184, 4894794154746251569)
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:TPU:4, TPU, 17179869184, 16242358405714188922)
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:TPU:5, TPU, 17179869184, 15231011154896667063)
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:TPU:6, TPU, 17179869184, 1938731572797274520)
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:TPU:7, TPU, 17179869184, 9964760283833988398)
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:TPU_SYSTEM:0, TPU_SYSTEM, 8589934592, 7014322032663729690)
INFO:tensorflow:*** Available Device: _DeviceAttributes(/job:worker/replica:0/task:0/device:XLA_CPU:0, XLA_CPU, 17179869184, 5972651299852305070)
WARNING:tensorflow:Keras support is now deprecated in support of TPU Strategy. Please follow the distribution strategy guide on tensorflow.org to migrate to the 2.0 supported version.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
 in ()
    125 
    126 if __name__ == "__main__":
--> 127     main(3, "tf_keras_tpu")

4 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/contrib/tpu/python/tpu/keras_support.py in __init__(self, cpu_model, strategy)
   1426           self._cpu_model.sample_weight_mode,
   1427           self._cpu_model._compile_weighted_metrics,
-> 1428           self._cpu_model.target_tensors,
   1429       )
   1430 

AttributeError: 'Model' object has no attribute 'target_tensors'

解决方案:

降低版本,

pip install tensorflow==1.13.1

Reference:

[1]https://github.com/tensorflow/tensorflow/issues/30531

 

你可能感兴趣的:(AttributeError: 'Model' object has no attribute 'target_tensors')