yixiao1 / Action-Based-Representation-Learning

14 stars 5 forks source link

A ModuleNotFoundError when reproducing Driving on CARLA benchmark #1

Closed AIasd closed 4 years ago

AIasd commented 4 years ago

Hi!

I was trying to reproduce "Driving on CARLA benchmark". I have reproduced all the previous parts and everything seems fine until step 5 in this part. I encountered the following error message:

Traceback (most recent call last):
  File "benchmark_runner.py", line 169, in <module>
    predefined_benchmarks(args)
  File "benchmark_runner.py", line 60, in predefined_benchmarks
    args.draw_trajectories, make_videos=args.make_videos)
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/driving-benchmarks-carla_09_cexp/version09x/benchmarks/nocrash.py", line 46, in perform
    agent_module = importlib.import_module(module_name)
  File "/home/zhongzzy9/anaconda3/envs/carla_rep/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/drive/AffordancesAgent.py", line 14, in <module>
    from drive.affordances import  get_driving_affordances
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/drive/__init__.py", line 1, in <module>
    from .coil_agent import CoILAgent
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/drive/coil_agent.py", line 19, in <module>
    from carla08.agent import CommandFollower
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/carla08/agent/__init__.py", line 2, in <module>
    from .command_follower import CommandFollower
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/carla08/agent/command_follower.py", line 4, in <module>
    from .modules import ObstacleAvoidance, Controller, Waypointer
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/carla08/agent/modules/__init__.py", line 2, in <module>
    from .controllers import Controller
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/carla08/agent/modules/controllers.py", line 3, in <module>
    from pid_controller.pid import PID
ModuleNotFoundError: No module named 'pid_controller' 

Any help will be appreciated!

yixiao1 commented 4 years ago

Hello @AIasd, please try to comment the following import in "../Action-Based-Representation-Learning/drive/AffordancesAgent.py", line 14:

from drive.affordances import get_driving_affordances

Please kindly tell me if you have more issues

yixiao1 commented 4 years ago

Hi @AIasd,

I found that the PYTHONPATH setting for driving was wrong. Please refer to the my new commit on README file

Cheers

AIasd commented 4 years ago

Hi @yixiao1 , thank you for the quick response! The above issue gets solved after I replace remove drive. in drive.affordances import get_driving_affordances and all other imports in the files inside the drive folder.

Now I encounter a new error:

HANG ON IMPORT
 STARTING BENCHMARK  version09x/descriptions/nocrash/nocrash_training_regular_Town01.json
 STARING BENCHMARK 
['version09x', 'descriptions', 'nocrash']
PACKAGE NAME  nocrash_training_regular_Town01
/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/configs/coil_global.py:125: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  yaml_file = yaml.load(f)
Encoder model  1000 loaded from  _logs/ENCODER/BC_smallDataset_seed1/checkpoints
Affordances Model  1000.pth loaded from  /home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/_logs/EXP/BC_smallDataset_seed1_encoder_frozen_1FC_smallDataset_s1_1000/checkpoints
  0%|                                                    | 0/100 [00:00<?, ?it/s]Traceback (most recent call last):
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/driving-benchmarks-carla_09_cexp/version09x/benchmark.py", line 387, in benchmark
    draw_relative_angle_error= draw_relative_angle_error)
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/driving-benchmarks-carla_09_cexp/version09x/benchmark.py", line 313, in benchmark_env_loop
    state, _ = renv.reset(StateFunction=agent.get_state)
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/cad/cexp/env/environment.py", line 194, in reset
    self._last_executing_agent))
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/cad/cexp/env/experience.py", line 45, in __init__
    self._exp_params['exp_number']))
RuntimeError: time-out of 45000ms while waiting for the simulator, make sure the simulator is ready and connected to localhost:57371
  0%|                                                    | 0/100 [00:45<?, ?it/s]
Traceback (most recent call last):
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/driving-benchmarks-carla_09_cexp/version09x/benchmark.py", line 387, in benchmark
    draw_relative_angle_error= draw_relative_angle_error)
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/driving-benchmarks-carla_09_cexp/version09x/benchmark.py", line 313, in benchmark_env_loop
    state, _ = renv.reset(StateFunction=agent.get_state)
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/cad/cexp/env/environment.py", line 194, in reset
    self._last_executing_agent))
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/cad/cexp/env/experience.py", line 45, in __init__
    self._exp_params['exp_number']))
RuntimeError: time-out of 45000ms while waiting for the simulator, make sure the simulator is ready and connected to localhost:57371

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/driving-benchmarks-carla_09_cexp/version09x/benchmark.py", line 398, in benchmark
    renv.remove_data()
  File "/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/cad/cexp/env/environment.py", line 242, in remove_data
    raise NoDataGenerated("The data is not generated yet")
cexp.env.environment.NoDataGenerated: The data is not generated yet
 PACKAGE DOES NOT EXIST
 STARTING BENCHMARK  version09x/descriptions/nocrash/nocrash_training_dense_Town01.json
 STARING BENCHMARK 
['version09x', 'descriptions', 'nocrash']
PACKAGE NAME  nocrash_training_dense_Town01

I also notice that the port number in make sure the simulator is ready and connected to localhost:57371 changes each time. So despite I run a carla host using a port number in the error message, it will always report another port number next run.

yixiao1 commented 4 years ago

Hi @AIasd,

This RuntimeError usually happens when your simulator is not ready. Please kindly check if you have correctly added Carla package to your PYTHONPATH, and make sure that the docker you are using was successfully built.

As for the port, it is unnecessary to set it, since for each time running, the system will automatically find free port to connect to the simulator. If you really want to set to a specific port number, please comment line 152 in benchmark_runner.py:

args.port = find_free_port()

AIasd commented 4 years ago

Hi @yixiao1,

Thank you for your help!

It finally runs after I rebuilt a docker using the command docker image build -f Carla96ped4/Dockerfile -t carlaped Carla96ped4/.

However, I encountered a segmentation fault after running for a while. The full trace is shown below:

HANG ON IMPORT
 STARTING BENCHMARK  version09x/descriptions/nocrash/nocrash_training_regular_Town01.json
 STARING BENCHMARK 
['version09x', 'descriptions', 'nocrash']
PACKAGE NAME  nocrash_training_regular_Town01
/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/configs/coil_global.py:125: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  yaml_file = yaml.load(f)
Encoder model  1000 loaded from  _logs/ENCODER/BC_smallDataset_seed1/checkpoints
Affordances Model  1000.pth loaded from  /home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/_logs/EXP/BC_smallDataset_seed1_encoder_frozen_1FC_smallDataset_s1_1000/checkpoints
  0%|                                                   | 0/100 [00:00<?, ?it/s]WARNING: Version mismatch detected: You are trying to connect to a simulator that might be incompatible with this API 
WARNING: Client API version     = 0acea97 
WARNING: Simulator API version  = 703dcff 
/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning/drive/AffordancesAgent.py:100: RuntimeWarning: invalid value encountered in double_scalars
  (np.linalg.norm(w_vec) * np.linalg.norm(v_vec)), -1.0, 1.0))
  1%|▎                        | 9.349999999999998/803 [01:24<1:59:38,  9.04s/it]
WARNING: attempting to destroy an actor that is already dead: Actor 264 (vehicle.lincoln.mkz2017) 
 Correctly reseted the agent
  1%|▍                                       | 1/100 [01:48<2:58:12, 108.00s/it]WARNING: attempting to destroy an actor that is already dead: Actor 264 (vehicle.lincoln.mkz2017) 
Destroying ego-vehicle!
  1%|▎                        | 13.00000000000005/943 [01:52<2:14:21,  8.67s/it]
WARNING: attempting to destroy an actor that is already dead: Actor 711 (vehicle.lincoln.mkz2017) 
 Correctly reseted the agent
  2%|▊                                       | 2/100 [04:01<3:08:55, 115.66s/it]Response Spawn failed because of collision at spawn position
WARNING: attempting to destroy an actor that is already dead: Actor 711 (vehicle.lincoln.mkz2017) 
Destroying ego-vehicle!
  1%|▏                      | 11.150000000000023/1107 [01:32<2:31:58,  8.32s/it]
WARNING: attempting to destroy an actor that is already dead: Actor 1158 (vehicle.lincoln.mkz2017) 
 Correctly reseted the agent
  3%|█▏                                      | 3/100 [05:58<3:07:38, 116.07s/it]WARNING: attempting to destroy an actor that is already dead: Actor 1158 (vehicle.lincoln.mkz2017) 
Destroying ego-vehicle!
  1%|▏                        | 5.299999999999989/844 [00:43<1:56:00,  8.30s/it]
WARNING: attempting to destroy an actor that is already dead: Actor 1604 (vehicle.lincoln.mkz2017) 
 Correctly reseted the agent
  4%|█▌                                      | 4/100 [07:01<2:40:11, 100.12s/it]WARNING: attempting to destroy an actor that is already dead: Actor 1604 (vehicle.lincoln.mkz2017) 
Destroying ego-vehicle!
  1%|▏                        | 8.249999999999982/885 [01:08<2:01:45,  8.33s/it]
WARNING: attempting to destroy an actor that is already dead: Actor 2051 (vehicle.lincoln.mkz2017) 
 Correctly reseted the agent
  5%|██                                       | 5/100 [08:29<2:32:53, 96.56s/it]./run_drive_on_carla_benchmark.sh: line 6:  6822 Segmentation fault      (core dumped)

Note that I use a simple .sh script rather than define global variable and running python. The script run_drive_on_carla_benchmark.sh is shown below:

export SRL_DATASET_PATH=/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning
export ACTIONDIR=/home/zhongzzy9/Documents/self-driving-car/Action-Based-Representation-Learning

export PYTHONPATH=$ACTIONDIR:$ACTIONDIR/cad:$ACTIONDIR/Carla96ped4/PythonAPI/carla/dist/carla-0.9.6-py3.5-linux-x86_64.egg/:$ACTIONDIR/Carla96ped4/PythonAPI/carla:$ACTIONDIR/scenario_runner

python3 benchmark_runner.py -b NoCrash -a $ACTIONDIR/drive/AffordancesAgent.py -d carlaped -c $ACTIONDIR/_logs/EXP/BC_smallDataset_seed1_encoder_frozen_1FC_smallDataset_s1_1000/config.json --gpu 0

I wonder what can be potential cause of the seg fault? Or is this a normal behavior?

Another question I have is about the carla version mismatch:

WARNING: Client API version     = 0acea97 
WARNING: Simulator API version  = 703dcff 

In particular, I believe I export the correct carla python path with

export PYTHONPATH=$ACTIONDIR:$ACTIONDIR/cad:$ACTIONDIR/Carla96ped4/PythonAPI/carla/dist/carla-0.9.6-py3.5-linux-x86_64.egg/:$ACTIONDIR/Carla96ped4/PythonAPI/carla:$ACTIONDIR/scenario_runner

and I use the docker file inside Carla96ped4 to build the docker. Also, I run easy_install Carla96ped4/PythonAPI/carla/dist/carla-0.9.6-py3.5-linux-x86_64.egg to make sure it is the one used in my conda environment.

What do you think can be possible causes of this mismatch?

yixiao1 commented 4 years ago

Hi @AIasd,

The WARNING of the mismatch means that the client and simulator are not from the same version. But it is fine, this is not a problem in our case.

As for the "Segmentation fault" error, sorry I am unable to give much reference, since it never happen to me. It looks like your benchmark was already running properly at the beginning.

yixiao1 commented 4 years ago

The main issue has been addressed.