Skip to content

Tensorflow API on ch2p6 DQNFlappyBird  #19

@nijisakai

Description

@nijisakai

Use Anaconda

# Python Version : 3.7.9
# OpenCV Version : 3.4.2
# Tensorflow Version : 2.1.0
# install opencv before tensorflow to avoid dependency confilct
conda install opencv
conda install tensorflow-gpu
pip3 install pygame

Errors and Fix

Traceback (most recent call last):
  File "deep_q_network_trained.py", line 215, in <module>
    main()
  File "deep_q_network_trained.py", line 212, in main
    playGame()
  File "deep_q_network_trained.py", line 207, in playGame
    sess = tf.InteractiveSession()
AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'

# change line 207 to
sess = tf.compat.v1.InteractiveSession()
Traceback (most recent call last):
  File "deep_q_network_trained.py", line 215, in <module>
    main()
  File "deep_q_network_trained.py", line 212, in main
    playGame()
  File "deep_q_network_trained.py", line 208, in playGame
    s, readout, h_fc1 = createNetwork()
  File "deep_q_network_trained.py", line 40, in createNetwork
    W_conv1 = weight_variable([8, 8, 4, 32])
  File "deep_q_network_trained.py", line 25, in weight_variable
    initial = tf.truncated_normal(shape, stddev = 0.01)
AttributeError: module 'tensorflow' has no attribute 'truncated_normal'

# change line 25 to
initial = tf.random.truncated_normal(shape, stddev = 0.01)
Traceback (most recent call last):
  File "deep_q_network_trained.py", line 215, in <module>
    main()
  File "deep_q_network_trained.py", line 212, in main
    playGame()
  File "deep_q_network_trained.py", line 208, in playGame
    s, readout, h_fc1 = createNetwork()
  File "deep_q_network_trained.py", line 56, in createNetwork
    s = tf.placeholder("float", [None, 80, 80, 4])
AttributeError: module 'tensorflow' has no attribute 'placeholder'

# change 
import tensorflow as tf
# to
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

Difference between deep_q_network.py and deep_q_network_trained.py
Comment out Line 109-113

checkpoint = tf.train.get_checkpoint_state("saved_networks")
    # if checkpoint and checkpoint.model_checkpoint_path:
    #     saver.restore(sess, checkpoint.model_checkpoint_path)
    #     print("Successfully loaded:", checkpoint.model_checkpoint_path)
    # else:
    #     print("Could not find old network weights")

    # start training

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions