PokemonRedExperiments icon indicating copy to clipboard operation
PokemonRedExperiments copied to clipboard

FileNotFoundError even though I have the ROM saved in the specified path.

Open fau1095 opened this issue 2 years ago • 8 comments

I'm getting this error:

Traceback (most recent call last): File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/run_pretrained_interactive.py", line 42, in <module> env = make_env(0, env_config)() #SubprocVecEnv([make_env(i, env_config) for i in range(num_cpu)]) File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/run_pretrained_interactive.py", line 21, in _init env = RedGymEnv(env_conf) File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/red_gym_env.py", line 92, in __init__ self.pyboy = PyBoy( File "/Users/fabriziomendez/Library/Python/3.10/lib/python/site-packages/pyboy/pyboy.py", line 79, in __init__ raise FileNotFoundError(f"ROM file {gamerom_file} was not found!") FileNotFoundError: ROM file ../PokemonRed.gb was not found!

However, you may see that I have the PokemonRed.gb file where its supposed to be: image image

Any tips on how to solve this issue?

fau1095 avatar Oct 17 '23 18:10 fau1095

The .gb have to be in PokemonRedExperiments not in PokemonRedExperiments/baselines

waskalien avatar Oct 17 '23 19:10 waskalien

The .gb have to be in PokemonRedExperiments not in PokemonRedExperiments/baselines

Oh right, I must have misread the readme, however even after moving the file where its supposed to be, I get this error: BrokenPipeError: [Errno 32] Broken pipe

Full error:

fabriziomendez@Fabrizios-MacBook-Pro baselines % /usr/local/bin/python3.10 "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/run_pretrained_interactive.
py"
UserWarning: Using SDL2 binaries from pysdl2-dll 2.28.0
4064     pyboy.pyboy                    WARNING  The emulation speed might not be accurate when speed-target is higher than 5

loading checkpoint
/Users/fabriziomendez/Library/Python/3.10/lib/python/site-packages/stable_baselines3/common/vec_env/patch_gym.py:95: UserWarning: You loaded a model that was trained using OpenAI Gym. We strongly recommend transitioning to Gymnasium by saving that model again.
  warnings.warn(
Wrapping the env with a `Monitor` wrapper
Wrapping the env in a DummyVecEnv.
Wrapping the env in a VecTransposeImage.
/Users/fabriziomendez/Library/Python/3.10/lib/python/site-packages/stable_baselines3/common/base_class.py:752: UserWarning: You are probably loading a model saved with SB3 < 1.7.0, we deactivated exact_match so you can save the model again to avoid issues in the future (see https://github.com/DLR-RM/stable-baselines3/issues/1233 for more info). Original error: Error(s) in loading state_dict for ActorCriticCnnPolicy:
        Missing key(s) in state_dict: "pi_features_extractor.cnn.0.weight", "pi_features_extractor.cnn.0.bias", "pi_features_extractor.cnn.2.weight", "pi_features_extractor.cnn.2.bias", "pi_features_extractor.cnn.4.weight", "pi_features_extractor.cnn.4.bias", "pi_features_extractor.linear.0.weight", "pi_features_extractor.linear.0.bias", "vf_features_extractor.cnn.0.weight", "vf_features_extractor.cnn.0.bias", "vf_features_extractor.cnn.2.weight", "vf_features_extractor.cnn.2.bias", "vf_features_extractor.cnn.4.weight", "vf_features_extractor.cnn.4.bias", "vf_features_extractor.linear.0.weight", "vf_features_extractor.linear.0.bias".  
Note: the model should still work fine, this only a warning.
  warnings.warn(
Traceback (most recent call last):
  File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/run_pretrained_interactive.py", line 70, in <module>
    obs, rewards, terminated, truncated, info = env.step(action)
  File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/red_gym_env.py", line 176, in step
    self.run_action_on_emulator(action)
  File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/red_gym_env.py", line 224, in run_action_on_emulator
    self.add_video_frame()
  File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/red_gym_env.py", line 230, in add_video_frame
    self.full_frame_writer.add_image(self.render(reduce_res=False, update_mem=False))
  File "/Users/fabriziomendez/Library/Python/3.10/lib/python/site-packages/mediapy/__init__.py", line 1388, in add_image
    if self._proc.stdin.write(data) != len(data):
BrokenPipeError: [Errno 32] Broken pipe

fau1095 avatar Oct 17 '23 19:10 fau1095

While I'm unsure about your error because it looks like it's an issue with stable_baselines3 and not this project. Maybe try pip install again or upgrade your installed packages with pip list --outdated --format=freeze | grep -v '^-e' | cut -d = -f 1 | xargs -n1 pip install -U

Also for a fix to the location issue you may consider adding a ROMs folder in the root and then just scan it, I set it up already and works and can merge the code. The main thing is you don't need to worry about spaces or capitalization since it's currently hard coded. The issue is it will encourage people to put other rom types in there.

techmore avatar Oct 17 '23 22:10 techmore

The .gb have to be in PokemonRedExperiments not in PokemonRedExperiments/baselines

Oh right, I must have misread the readme, however even after moving the file where its supposed to be, I get this error: BrokenPipeError: [Errno 32] Broken pipe

Full error:

fabriziomendez@Fabrizios-MacBook-Pro baselines % /usr/local/bin/python3.10 "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/run_pretrained_interactive.
py"
UserWarning: Using SDL2 binaries from pysdl2-dll 2.28.0
4064     pyboy.pyboy                    WARNING  The emulation speed might not be accurate when speed-target is higher than 5

loading checkpoint
/Users/fabriziomendez/Library/Python/3.10/lib/python/site-packages/stable_baselines3/common/vec_env/patch_gym.py:95: UserWarning: You loaded a model that was trained using OpenAI Gym. We strongly recommend transitioning to Gymnasium by saving that model again.
  warnings.warn(
Wrapping the env with a `Monitor` wrapper
Wrapping the env in a DummyVecEnv.
Wrapping the env in a VecTransposeImage.
/Users/fabriziomendez/Library/Python/3.10/lib/python/site-packages/stable_baselines3/common/base_class.py:752: UserWarning: You are probably loading a model saved with SB3 < 1.7.0, we deactivated exact_match so you can save the model again to avoid issues in the future (see https://github.com/DLR-RM/stable-baselines3/issues/1233 for more info). Original error: Error(s) in loading state_dict for ActorCriticCnnPolicy:
        Missing key(s) in state_dict: "pi_features_extractor.cnn.0.weight", "pi_features_extractor.cnn.0.bias", "pi_features_extractor.cnn.2.weight", "pi_features_extractor.cnn.2.bias", "pi_features_extractor.cnn.4.weight", "pi_features_extractor.cnn.4.bias", "pi_features_extractor.linear.0.weight", "pi_features_extractor.linear.0.bias", "vf_features_extractor.cnn.0.weight", "vf_features_extractor.cnn.0.bias", "vf_features_extractor.cnn.2.weight", "vf_features_extractor.cnn.2.bias", "vf_features_extractor.cnn.4.weight", "vf_features_extractor.cnn.4.bias", "vf_features_extractor.linear.0.weight", "vf_features_extractor.linear.0.bias".  
Note: the model should still work fine, this only a warning.
  warnings.warn(
Traceback (most recent call last):
  File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/run_pretrained_interactive.py", line 70, in <module>
    obs, rewards, terminated, truncated, info = env.step(action)
  File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/red_gym_env.py", line 176, in step
    self.run_action_on_emulator(action)
  File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/red_gym_env.py", line 224, in run_action_on_emulator
    self.add_video_frame()
  File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/red_gym_env.py", line 230, in add_video_frame
    self.full_frame_writer.add_image(self.render(reduce_res=False, update_mem=False))
  File "/Users/fabriziomendez/Library/Python/3.10/lib/python/site-packages/mediapy/__init__.py", line 1388, in add_image
    if self._proc.stdin.write(data) != len(data):
BrokenPipeError: [Errno 32] Broken pipe

I have the same problem on m1 mac. Probably a separate issue could be created for this.

wotori avatar Oct 20 '23 17:10 wotori

  File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/red_gym_env.py", line 230, in add_video_frame
    self.full_frame_writer.add_image(self.render(reduce_res=False, update_mem=False))
  File "/Users/fabriziomendez/Library/Python/3.10/lib/python/site-packages/mediapy/__init__.py", line 1388, in add_image
    if self._proc.stdin.write(data) != len(data):
BrokenPipeError: [Errno 32] Broken pipe

I have found a quick solution to the issue. In case you only want to run the demo without the need to record the video, you can comment out this section.

        # if self.save_video:
        #     base_dir = self.s_path / Path('rollouts')
        #     base_dir.mkdir(exist_ok=True)
        #     full_name = Path(f'full_reset_{self.reset_count}_id{self.instance_id}').with_suffix('.mp4')
        #     model_name = Path(f'model_reset_{self.reset_count}_id{self.instance_id}').with_suffix('.mp4')
        #     self.full_frame_writer = media.VideoWriter(base_dir / full_name, (144, 160), fps=60)
        #     self.full_frame_writer.__enter__()
        #     self.model_frame_writer = media.VideoWriter(base_dir / model_name, self.output_full[:2], fps=60)
        #     self.model_frame_writer.__enter__()

Also, comment out the self.add_video_frame() function in the run_action_on_emulator method. By doing this, everything should start working. However, it's important to note that this is not a general solution. We still need to figure out why it is not working out of the box, especially if it works for Linux users.

wotori avatar Oct 20 '23 18:10 wotori

File "/Users/fabriziomendez/Documents/AI and ML/PokemonRedExperiments/baselines/red_gym_env.py", line 230, in add_video_frame

self.full_frame_writer.add_image(self.render(reduce_res=False, update_mem=False))

File "/Users/fabriziomendez/Library/Python/3.10/lib/python/site-packages/mediapy/init.py", line 1388, in add_image

if self._proc.stdin.write(data) != len(data):

BrokenPipeError: [Errno 32] Broken pipe

I have found a quick solution to the issue. In case you only want to run the demo without the need to record the video, you can comment out this section.


        # if self.save_video:

        #     base_dir = self.s_path / Path('rollouts')

        #     base_dir.mkdir(exist_ok=True)

        #     full_name = Path(f'full_reset_{self.reset_count}_id{self.instance_id}').with_suffix('.mp4')

        #     model_name = Path(f'model_reset_{self.reset_count}_id{self.instance_id}').with_suffix('.mp4')

        #     self.full_frame_writer = media.VideoWriter(base_dir / full_name, (144, 160), fps=60)

        #     self.full_frame_writer.__enter__()

        #     self.model_frame_writer = media.VideoWriter(base_dir / model_name, self.output_full[:2], fps=60)

        #     self.model_frame_writer.__enter__()

Also, comment out the self.add_video_frame() function in the run_action_on_emulator method. By doing this, everything should start working. However, it's important to note that this is not a general solution. We still need to figure out why it is not working out of the box, especially if it works for Linux users.

Oh that's awesome man, I'll try that later today, however I was able to run it even with the video recording part, but for some reason it ONLY worked on Python3.11 in my M1 Pro.

fau1095 avatar Oct 20 '23 18:10 fau1095

Oh that's awesome man, I'll try that later today, however I was able to run it even with the video recording part, but for some reason it ONLY worked on Python3.11 in my M1 Pro.

after your comment, I tried 3.11, I also have 1m pro but the program did not start, the same error as with 3.10

wotori avatar Oct 21 '23 11:10 wotori

im having similar problems with the run file not recognizing the .gb file, using Ubuntu 22.04.3 and Python 3.12, it runs normally with python3 -m pyboy with the specified directory but doesnt run if i do python3 -m pyboy ../PokemonRed.gb . ive even tried going into the .py and changing the directory manually but still doesnt recognize the .gb. at least i could play it normally if i wanted to with pyboy and the specified directory, but the program just isnt wanting to work..

xovtar avatar Nov 13 '23 03:11 xovtar