Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensorflow API on ch2p6 DQNFlappyBird #19

Open
nijisakai opened this issue Oct 28, 2020 · 0 comments
Open

Tensorflow API on ch2p6 DQNFlappyBird #19

nijisakai opened this issue Oct 28, 2020 · 0 comments

Comments

@nijisakai
Copy link
Owner

nijisakai commented Oct 28, 2020

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant