In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use the ImportError of the baselines program train_cartpole.py". In the daily operation, I believe many people have doubts about how to use the ImportError of the baselines program train_cartpole.py. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the ImportError of the baselines program train_cartpole.py". Next, please follow the editor to study!
Problem export
In order to make it easier to implement some of my ideas, I finally succumbed to OpenAI's baselines, because some of my implementations are always difficult to compare with the results given by major papers. So I installed baselines today, and there are still some pits. This is mainly about the pits encountered by cartpole.py when running the example after the installation is complete, which is called ImportError.
ImportError
Let's cd to the folder baselines/baselines/deepq/experiments, and then run the following statement:
$python3 train_cartpole.py
And then I made a mistake.
As we can see from the figure, there is the following statement in the file train_cartpole.py:
From baselines import deepq
When we import deepq, the _ _ init__.py file under the deepq folder will be executed, so we open this file:
From baselines.deepq import models # noqafrom baselines.deepq.build_graph import build_act, build_train # noqafrom baselines.deepq.simple import learn, load # noqafrom baselines.deepq.replay_buffer import ReplayBuffer, PrioritizedReplayBuffer # noqadef wrap_atari_dqn (env): from baselines.common.atari_wrappers import wrap_deepmind return wrap_deepmind (env, fram_stack=True, scale=True)
In the error report, the above sentence is mentioned:
From baselines.deepq.simple import learn, load # noqa
At the same time, it is mentioned in the error report that there are:
From baselines import deepq
The problem becomes clear that when we import deepq, we will execute the _ _ init__.py file, which will import learn and load from simple.py into the deepq namespace. And simple.py wants import deepq, which constitutes the so-called "Looping Import". So how should we solve it?
Let's comment out the following statement in simple.py:
From baselines import deepq
Then run:
$python3 train_cartpole.py
Found out that something had gone wrong again:
However, this mistake is bound to make, we commented out an import sentence written by others for no reason, which can be good. But don't panic, let's continue to analyze, why do you want import deepq here? To execute the following statement:
Act = deepq.build_act (* * act_params)... act, train, update_target, debug = deepq.build_train (...)
Here, because we imported the build_act and build_train methods into the namespace of deepq in _ _ init__.py, we can call build_act and build_action directly in the namespace of deepq.
If we want to use deepq.build_act in the simple.py file, then we have to import deepq in simple.py, and we also need to import simple in _ _ init__.py, so there will be a "Looping Import" problem.
Solution
So the solution we chose is:
A) comment out the following statement in _ _ init__.py:
From baselines.deepq.build_graph import build_act, build_train # noqa
B) replace the following statements in simple.py:
From baselines import deepq
To be replaced by:
From baselines.deepq.build_graph import build_act, build_train
C) modify the following statements:
Act = deepq.build_act (* * act_params)... act, train, update_target, debug = deepq.build_train (...)
Change to:
Act = build_act (* * act_params)... act, train, update_target, debug = build_train (...)
D) run:
$python3 train_cartpole.py
OK, problem solved.
By the way, in OpenAI Baselines, some code uses the features of Python3.6, such as direct (None, * tuple), which is not allowed in Python3.4, so it is recommended that you directly install the conda environment and install Python3.6.
At this point, the study on "how to use the ImportError of baselines program train_cartpole.py" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.