質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
OpenAI Gym

OpenAI Gymは、強化学習を開発・強化するためのシミュレーション環境です。強化学習における実験や評価環境などを標準化し提供することを目的としています。さらに、結果をアップロードしたり、他の人の実行結果や実装を見ることも可能です。

強化学習

強化学習とは、ある環境下のエージェントが現状を推測し行動を決定することで報酬を獲得するという見解から、その報酬を最大限に得る方策を学ぶ機械学習のことを指します。問題解決時に得る報酬が選択結果によって変化することで、より良い行動を選択しようと学習する点が特徴です。

Keras-RL

Keras-RLは、Kerasを用いてDQNなどの深層強化学習アルゴリズムを実装したライブラリです。学習する強化学習の環境をOpenAI Gymのインターフェースに準じて作成することが必要です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

2156閲覧

Keras-rlの公式exampleでのエラー

LXHayato

総合スコア1

OpenAI Gym

OpenAI Gymは、強化学習を開発・強化するためのシミュレーション環境です。強化学習における実験や評価環境などを標準化し提供することを目的としています。さらに、結果をアップロードしたり、他の人の実行結果や実装を見ることも可能です。

強化学習

強化学習とは、ある環境下のエージェントが現状を推測し行動を決定することで報酬を獲得するという見解から、その報酬を最大限に得る方策を学ぶ機械学習のことを指します。問題解決時に得る報酬が選択結果によって変化することで、より良い行動を選択しようと学習する点が特徴です。

Keras-RL

Keras-RLは、Kerasを用いてDQNなどの深層強化学習アルゴリズムを実装したライブラリです。学習する強化学習の環境をOpenAI Gymのインターフェースに準じて作成することが必要です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/01/24 10:42

前提・実現したいこと

強化学習を試したく、keras-rlをインストールして公式の下記exampleを実行しました。
https://github.com/keras-rl/keras-rl/blob/master/examples/ddpg_pendulum.py

しかしエラーが出てきて困っています。
アドバイスの程よろしくお願いいたします。
環境はWin10 / JupyterLab
以下の表示が出た後に問題のエラーが出ます。

==================================================================================================
Total params: 2,305
Trainable params: 2,305
Non-trainable params: 0


None


発生している問題・エラーメッセージ

--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-3-49ce8198fa31> in <module>() 55 agent = DDPGAgent(nb_actions=nb_actions, actor=actor, critic=critic, critic_action_input=action_input, 56 memory=memory, nb_steps_warmup_critic=100, nb_steps_warmup_actor=100, ---> 57 random_process=random_process, gamma=.99, target_model_update=1e-3) 58 agent.compile(Adam(lr=.001, clipnorm=1.), metrics=['mae']) 59 1 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/keras_tensor.py in __len__(self) 238 239 def __len__(self): --> 240 raise TypeError('Keras symbolic inputs/outputs do not ' 241 'implement `__len__`. You may be ' 242 'trying to pass Keras symbolic inputs/outputs ' TypeError: Keras symbolic inputs/outputs do not implement `__len__`. You may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model. This error will also get raised if you try asserting a symbolic input/output directly.

該当のソースコード

python

import numpy as np import gym from keras.models import Sequential, Model from keras.layers import Dense, Activation, Flatten, Input, Concatenate from keras.optimizers import Adam from rl.agents import DDPGAgent from rl.memory import SequentialMemory from rl.random import OrnsteinUhlenbeckProcess ENV_NAME = 'Pendulum-v0' # Get the environment and extract the number of actions. env = gym.make(ENV_NAME) np.random.seed(123) env.seed(123) assert len(env.action_space.shape) == 1 nb_actions = env.action_space.shape[0] # Next, we build a very simple model. actor = Sequential() actor.add(Flatten(input_shape=(1,) + env.observation_space.shape)) actor.add(Dense(16)) actor.add(Activation('relu')) actor.add(Dense(16)) actor.add(Activation('relu')) actor.add(Dense(16)) actor.add(Activation('relu')) actor.add(Dense(nb_actions)) actor.add(Activation('linear')) print(actor.summary()) action_input = Input(shape=(nb_actions,), name='action_input') observation_input = Input(shape=(1,) + env.observation_space.shape, name='observation_input') flattened_observation = Flatten()(observation_input) x = Concatenate()([action_input, flattened_observation]) x = Dense(32)(x) x = Activation('relu')(x) x = Dense(32)(x) x = Activation('relu')(x) x = Dense(32)(x) x = Activation('relu')(x) x = Dense(1)(x) x = Activation('linear')(x) critic = Model(inputs=[action_input, observation_input], outputs=x) print(critic.summary()) # Finally, we configure and compile our agent. You can use every built-in Keras optimizer and # even the metrics! memory = SequentialMemory(limit=100000, window_length=1) random_process = OrnsteinUhlenbeckProcess(size=nb_actions, theta=.15, mu=0., sigma=.3) agent = DDPGAgent(nb_actions=nb_actions, actor=actor, critic=critic, critic_action_input=action_input, memory=memory, nb_steps_warmup_critic=100, nb_steps_warmup_actor=100, random_process=random_process, gamma=.99, target_model_update=1e-3) agent.compile(Adam(lr=.001, clipnorm=1.), metrics=['mae']) # Okay, now it's time to learn something! We visualize the training here for show, but this # slows down training quite a lot. You can always safely abort the training prematurely using # Ctrl + C. agent.fit(env, nb_steps=50000, visualize=True, verbose=1, nb_max_episode_steps=200) # After training is done, we save the final weights. agent.save_weights('ddpg_{}_weights.h5f'.format(ENV_NAME), overwrite=True) # Finally, evaluate our algorithm for 5 episodes. agent.test(env, nb_episodes=5, visualize=True, nb_max_episode_steps=200)

試したこと

Google Colaboratoryでも同様のエラーが出ました。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

keras-rl2を使用したすると解決できるそうです

https://github.com/wau/keras-rl2

投稿2021/07/30 16:56

holy_

総合スコア364

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問