Skip to content

Instantly share code, notes, and snippets.

@pythonlessons
Created November 26, 2019 14:49
Show Gist options
  • Save pythonlessons/1138da04284ccea6b60b610a9de5edba to your computer and use it in GitHub Desktop.
Save pythonlessons/1138da04284ccea6b60b610a9de5edba to your computer and use it in GitHub Desktop.
1_Cartpole_DQN_keras_model.py
from keras.models import Model
from keras.layers import Input, Dense
from keras.optimizers import Adam, RMSprop
# Neural Network model for Deep Q Learning
def OurModel(input_shape, action_space):
X_input = Input(input_shape)
# 'Dense' is the basic form of a neural network layer
# Input Layer of state size(4) and Hidden Layer with 512 nodes
X = Dense(512, input_shape=input_shape, activation="relu", kernel_initializer='he_uniform')(X_input)
# Hidden layer with 256 nodes
X = Dense(256, activation="relu", kernel_initializer='he_uniform')(X)
# Hidden layer with 64 nodes
X = Dense(64, activation="relu", kernel_initializer='he_uniform')(X)
# Output Layer with # of actions: 2 nodes (left, right)
X = Dense(action_space, activation="linear", kernel_initializer='he_uniform')(X)
model = Model(inputs = X_input, outputs = X, name='CartPole DQN model')
model.compile(loss="mse", optimizer=RMSprop(lr=0.00025, rho=0.95, epsilon=0.01), metrics=["accuracy"])
model.summary()
return model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment