tensorflow / tensorflow/probability
AttributeError: 'NoneType' object has no attribute 'original_name_scope'
Open
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
So, I'm trying to apply some flipout layers to a deep-q network. However, Keras seems to throw the above error when I run the DQN. How can I resolve this?
Full Traceback:
Traceback (most recent call last):
File "thoughtmouse.py", line 57, in <module>
combined()
File "thoughtmouse.py", line 18, in combined
state_action_reward_loop(agent)
File "thoughtmouse.py", line 30, in state_action_reward_loop
rewards = agent.replay(1)
File "/home/ai/Downloads/ScreenMouse/bdqn.py", line 88, in replay
target = (reward + self.gamma * np.amax(self.model.predict(next_state)[0]))
File "/home/ai/anaconda3/envs/drl/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 1096, in predict
x, check_steps=True, steps_name='steps', steps=steps)
File "/home/ai/anaconda3/envs/drl/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 2289, in _standardize_user_data
self._set_inputs(cast_inputs)
File "/home/ai/anaconda3/envs/drl/lib/python3.6/site-packages/tensorflow/python/training/checkpointable/base.py", line 442, in _method_wrapper
method(self, *args, **kwargs)
File "/home/ai/anaconda3/envs/drl/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 2529, in _set_inputs
outputs = self.call(inputs, training=training)
File "/home/ai/anaconda3/envs/drl/lib/python3.6/site-packages/tensorflow/python/keras/engine/sequential.py", line 233, in call
inputs, training=training, mask=mask)
File "/home/ai/anaconda3/envs/drl/lib/python3.6/site-packages/tensorflow/python/keras/engine/sequential.py", line 253, in _call_and_compute_mask
with ops.name_scope(layer._name_scope()):
File "/home/ai/anaconda3/envs/drl/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 284, in _name_scope
return self._current_scope.original_name_scope
AttributeError: 'NoneType' object has no attribute 'original_name_scope'
Code of DQN:
class DQN:
def __init__(self, state_size, action_size):
self.state_size = state_size
self.action_size = action_size
self.memory = deque(maxlen=2000)
self.gamma = 0.95 # discount rate
self.epsilon = 0.81 # exploration rate
self.epsilon_min = 0.2
self.epsilon_decay = 0.965
self.lr = 0.001
self.model = self._build_model()
self.optimizer = Adam(lr=self.lr)
def _build_model(self):
model = Sequential()
## model.add(tfp.layers.Convolution2DFlipout(2, kernel_size=5,
## activation='relu'
## ))
model.add(tf.layers.Dropout(rate=0.3))
model.add(Flatten())
#model.add(tfp.layers.DenseFlipout(self.action_size * 4, activation='relu'))
#model.add(tfp.layers.DenseFlipout(self.action_size * 3, activation='relu'))
model.add(tfp.layers.DenseFlipout(self.action_size * 2, activation='relu'))
model.add(tfp.layers.DenseFlipout(self.action_size))
return model
def remember(self, state, action, reward, next_state, done):
self.memory.append((state, action, reward, next_state, done))
def act(self, state):
if np.random.rand() <= self.epsilon:
return random.randrange(self.action_size)
else:
act_values = self.model.predict(state)
return np.argmax(act_values[0]) # returns action
def replay(self, batch_size):
minibatch = random.sample(self.memory, batch_size)
for state, action, reward, next_state, done in minibatch:
target = reward
if not done:
target = (reward + self.gamma * np.amax(self.model.predict(next_state)[0]))
target_f = self.model.predict(state)
target_f[0][action] = target
self.history = self.model.fit(state, target_f, epochs=1, verbose=0)
if self.epsilon > self.epsilon_min:
self.epsilon *= self.epsilon_decay
loss = self.history.history['loss'][0]
return loss
def load(self, name):
self.model.load_weights(name)
def save(self, name):
self.model.save_weights(name)
def initialize(self):
self.model.compile(loss='mean_squared_logarithmic_error', optimizer = self.optimizer)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with DQN._build_model in bdqn.py and the model.predict calls in replay, then reproduce the traceback through thoughtmouse.py. Inspect how the Sequential model combines tf.layers.Dropout and TensorFlow Probability Flipout layers. Done means the DQN can run predict and replay without the original_name_scope AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100