Farama-Foundation / ViZDoom

Reinforcement Learning environments based on the 1993 game Doom :godmode:
https://vizdoom.farama.org/
1.71k stars 396 forks source link

screen shot showing replay info instead of the actual gameplay #447

Open HadiSDev opened 4 years ago

HadiSDev commented 4 years ago

If you encountered an issue, please post the following things:

Also I did notice that replays do contain all the images from when it was save. Is that normal?

Thanks!

Miffyli commented 4 years ago

I am not sure what the issue is here? I understand you are recording your own replay by playing the game and saving the images with your own script? Or are you using the replay files of ViZDoom to record things?

In any case, you seem to be launching the game outside vizdoom control. I recommend you launch the game and control the flow via ViZDoom. See this example for recording Doom replay files, for example.

HadiSDev commented 4 years ago

@Miffyli Yea sorry I forgot to mention I am using the vizdoom replay files here: Replay.zip

I have also followed the examples linked to record and to replay

Miffyli commented 4 years ago

Ok, I ran the replays on Windows 10, ViZDoom 1.1.7, Python 3.7. If I use SPECTATOR mode, it will have "Main menu" overlay on top and also include some of the console frames in state.screen_buffer. If I use ASYNC_PLAYER mode, there is no "Main menu" overlay but it still includes some images of console. It seems like the first (or last?) frames of replays are these console images.

That said, for me things seem to work as expected, minus the occasional image of the console. Here's the code I used.

from vizdoom import *
import cv2

# Run with basic.wad and basic.cfg in same directory,
# and replays in "replays" directory
game = DoomGame()
game.load_config("basic.cfg")

game.set_screen_resolution(ScreenResolution.RES_800X600)
game.set_render_hud(True)
game.set_mode(Mode.ASYNC_PLAYER)
game.init()

episodes = 5

for i in range(episodes):
    game.replay_episode("replays/episode_basic_" + str(i) + "_rec.lmp")

    while not game.is_episode_finished():
        s = game.get_state()
        buf = s.screen_buffer
        buf = buf.transpose([1,2,0])
        cv2.imshow("img", buf)
        cv2.waitKey(1)

        # Use advance_action instead of make_action.
        game.advance_action()

        r = game.get_last_reward()
        # game.get_last_action is not supported and don't work for replay at the moment.

        print("State #" + str(s.number))
        print("Game variables:", s.game_variables[0])
        print("Reward:", r)
        print("=====================")

    print("Episode finished.")
    print("total reward:", game.get_total_reward())
    print("************************")
HadiSDev commented 4 years ago

Okay thanks I will try again. Btw game.get_last_action does work for some actions

HadiSDev commented 4 years ago

Oh I noticed you only ran 5 episodes. As the number of episodes you are replaying is increasing the ratio of console images increases as well. Try to use cv2 to save all the images in a folder for all episodes I attached

Miffyli commented 4 years ago

Ah yes, now I see the problem. Indeed if I run all 50, around 35th replay it starts to get stuck in the console screen and behave oddly. If I only play last 20 (replays 30-50), it still works as expected, indicating there is some kind of issue with loading multiple replays in row. Thanks for reporting this!

Can you confirm this does not happen on Linux (I do not have access to a Linux machine at the moment)? All development is done on Linux side, so Windows side has odd bugs like this every now and then, which is why we highly recommend using Linux machines.

As for the get_last_action: This is a known issue (e.g. #354), so indeed you need to be careful with the actions you get back.

HadiSDev commented 4 years ago

@Miffyli I also noticed that the amount of screen shots in a replay file is less than the actual amount from when it was recorded. Is that normal?

Miffyli commented 4 years ago

Is this with all replay files or just after loading many replays (like discussed above)? How many frames were missing? Can you test this by recording and replaying them on Linux? When I was playing your replays, they seemed fine and contain necessary frames.

HadiSDev commented 4 years ago

For example in the home scenarios I have 99 episodes. When I recorded them I also saved every image (13K) images. When I run the recorded files, I get 4.2K images. This is the same on windows and linux

Miffyli commented 4 years ago

Hmm I have not observed such behaviour before. Have you noticed what is missing, e.g. does it cut off from the beginning or from the end of the episodes, or does it skip every Nth frame?

@mwydmuch Would you have an insight on this?

mwydmuch commented 4 years ago

Hi @HadiSDev, thank you for reporting the problem! I used recordings multiple times and I've never encountered such issues so I don't have any insights on this. I work almost only on Linux/macOS, so it probably occurs only on Windows. I will look into this, but I don't have Windows at the moment so it will take me a few days.

Miffyli commented 4 years ago

@mwydmuch Cheers! Judging by above comments it also happens on Linux. If you need help with Windows debugging, nudge me :).

HadiSDev commented 4 years ago

Steps to reproduce:

  1. Play fair amount of episodes on any scenario. (I tried on MyWayHome with 99 episodes). You have to save all screen buffers in a folder.
  2. Count all files in the image folder that you played
  3. Now run all the replays again and save the screen buffers in a new image folder
  4. Count all the files again
  5. Compare
HadiSDev commented 4 years ago

Okay I got a chance to test it on ubuntu, and it also has the issue. To clarify both Linux and windows have this issue with the console image

mwydmuch commented 4 years ago

@HadiSDev thanks for the steps and checking on Linux, that's very helpful. Sorry for late response from my side, I will pick it up finally by the end of this week.

HadiSDev commented 4 years ago

Sounds good. My bachelor submission is today so I everything is finished in my project so no need for rush :). Thanks for taking you time :+1: