我正在嘗試使用 openai 健身房、tensorflow 和 keras 執行學習模型。
我用這種方法構建我的模型:
def build_model(states, actions):
model = Sequential()
model.add(Dense(24, activation='relu', input_shape=states))
model.add(Dense(24, activation='relu'))
model.add(Dense(actions, activation='linear'))
return model
model = build_model(states, actions)
之后,我建立了我的代理:
def build_agent(model, actions):
policy = BoltzmannQPolicy()
memory = SequentialMemory(limit=50000, window_length=1)
dqn = DQNAgent(model=model, memory=memory, policy=policy,
nb_actions=actions, nb_steps_warmup=10, target_model_update=1e-2)
return dqn
當我打電話給培訓時:
dqn = build_agent(model, actions)
dqn.compile(Adam(lr=1e-3), metrics=['mae'])
dqn.fit(env, nb_steps=50000, visualize=True, verbose=1)
我收到此錯誤,即會話未初始化或沒有dense_24/bias 變數
---------------------------------------------------------------------------
FailedPreconditionError Traceback (most recent call last)
<ipython-input-112-7ebc8b726721> in <module>()
2 dqn.compile(Adam(lr=1e-3), metrics=['mae'])
3
-->4 dqn.fit(env, nb_steps=50000, visualize=True, verbose=1)
5
4 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/client/session.py in __call__(self, *args, **kwargs)
1483 # called before this destructor, in which case `self._session._session`
1484 # will be `None`.
-> 1485 if (self._handle is not None and self._session._session is not None and
1486 not self._session._closed):
1487 tf_session.TF_SessionReleaseCallable(self._session._session,
FailedPreconditionError: Could not find variable dense_24/bias. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Resource localhost/dense_24/bias/N10tensorflow3VarE does not exist.
[[{{node dense_24/BiasAdd/ReadVariableOp}}]]
誰能幫我解決問題?
uj5u.com熱心網友回復:
我認為這是一個keras參考問題,您應該正確匯入:
import tensorflow as tf
from tensorflow import keras
然后創建一個這樣的模型:
model = keras.Sequential([
keras.layers.Dense(24, activation='relu', input_shape=states))
keras.layers.Dense(24, activation='relu'))
keras.layers.Dense(actions, activation='linear'))
])
我沒有嘗試過你的整個代碼,嘗試并報告。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/381039.html
下一篇:keras中RNN的輸入形狀
