运行lane-yolo问题记录tensorflow1.x代码运行在tensorflow2.x上错误修改

1、AttributeError: module ‘tensorflow’ has no attribute ‘ConfigProto’

  File "D:\desktop\lane-yolo2\Test_Detections_On_Video.py", line 48, in <module>
    sess_config = tf.ConfigProto(device_count={'GPU': 0})
AttributeError: module 'tensorflow' has no attribute 'ConfigProto'

修改为:

sess_config = tf.compat.v1.ConfigProto(device_count={'GPU': 0})

2、AttributeError: module ‘tensorflow’ has no attribute ‘Session’

Traceback (most recent call last):
  File "D:\desktop\lane-yolo2\Test_Detections_On_Video.py", line 49, in <module>
    sess = tf.Session(config=sess_config)
AttributeError: module 'tensorflow' has no attribute 'Session'

修改为:

sess = tf.compat.v1.Session(config=sess_config)

3、AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’

Traceback (most recent call last):
  File "D:\desktop\lane-yolo2\Test_Detections_On_Video.py", line 67, in <module>
    lane_output_frame = tst_ln_net.test_lanenet(
  File "D:\desktop\lane-yolo2\LaneDetectionLaneNet\tools\test_lanenet.py", line 98, in test_lanenet
    input_tensor = tf.placeholder(dtype=tf.float32, shape=[1, 256, 512, 3], name='input_tensor')
AttributeError: module 'tensorflow' has no attribute 'placeholder'

修改为:

    input_tensor = tf.compat.v1.placeholder(dtype=tf.float32, shape=[1, 256, 512, 3], name='input_tensor')

4、RuntimeError: tf.placeholder() is not compatible with eager execution.

Traceback (most recent call last):
  File "D:\desktop\lane-yolo2\Test_Detections_On_Video.py", line 68, in <module>
    lane_output_frame = tst_ln_net.test_lanenet(
  File "D:\desktop\lane-yolo2\LaneDetectionLaneNet\tools\test_lanenet.py", line 98, in test_lanenet
    input_tensor = tf.compat.v1.placeholder(dtype=tf.float32, shape=[1, 256, 512, 3], name='input_tensor')
  File "G:\anaconda3\envs\lane-yolo2\lib\site-packages\tensorflow\python\ops\array_ops.py", line 3286, in placeholder
    raise RuntimeError("tf.placeholder() is not compatible with "
RuntimeError: tf.placeholder() is not compatible with eager execution.

修改,在导入的库下边添加代码:

tf.compat.v1.disable_eager_execution()

5、AttributeError: module ‘tensorflow’ has no attribute ‘variable_scope’

Traceback (most recent call last):
  File "D:\desktop\lane-yolo2\Test_Detections_On_Video.py", line 68, in <module>
    lane_output_frame = tst_ln_net.test_lanenet(
  File "D:\desktop\lane-yolo2\LaneDetectionLaneNet\tools\test_lanenet.py", line 104, in test_lanenet
    binary_seg_ret, instance_seg_ret = net.inference(input_tensor=input_tensor, name='lanenet_model')
  File "D:\desktop\lane-yolo2\LaneDetectionLaneNet\lanenet_model\lanenet.py", line 46, in inference
    with tf.variable_scope(name_or_scope=name, reuse=self._reuse):
AttributeError: module 'tensorflow' has no attribute 'variable_scope'

修改:

       with tf.compat.v1.variable_scope(name_or_scope=name, reuse=self._reuse):

总结:tensorflow1.x版本的代码在tf后面加上.compat.v1

你可能感兴趣的:(tensorflow,深度学习,人工智能)