JCBrouwer / maua-stylegan2

This is the repo for my experiments with StyleGAN2. There are many like it, but this one is mine. Contains code for the paper Audio-reactive Latent Interpolations with StyleGAN.
https://wavefunk.xyz/audio-reactive-stylegan
179 stars 29 forks source link

Broken pipe error when running supplied Colab notebook. #19

Closed jackylu97 closed 3 years ago

jackylu97 commented 3 years ago

When I run the colab notebook as is, I'm seeing the following error:

rendering 1440 frames...
  0%|                                        | 3/1440 [00:06<1:16:34,  3.20s/it]Exception in thread Thread-28:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/content/maua-stylegan2/render.py", line 110, in make_video
    video.stdin.write(img.tobytes())
BrokenPipeError: [Errno 32] Broken pipe

I'm also seeing the same thing when I try running the notebook with a custom checkpoint. Any idea what might be causing this? My guess is that something is leading to render.py trying to write a malformed image?

JCBrouwer commented 3 years ago

Hmmm, I see that I had the wrong out_size set by default, maybe that was causing it, although I got a different error. Did you uncomment the get_bends=get_bends line?

It would be easier to debug if you give the exact generate() command you're running, the size your network was trained at, and what repo you used.

jackylu97 commented 3 years ago

Ah yes, looks like I'm getting a different error now. Running with

generate(
  ckpt="FreaGAN.pt",
  audio_file=audio_file,
  output_dir="../",
  out_size=1024, # at the moment only 512x512, 1024x1024, 1920x1080 outputs are supported (out_size = 512, 1024, or 1920 respectively)
  G_res=1024,
  batch=4,  # CUDA out of memory errors => smaller batch (also try running the previous cell, to clear some GPU memory)
  ffmpeg_preset="faster",  # RAM crashes => faster preset (see https://trac.ffmpeg.org/wiki/Encode/H.264)
  fps=24,
  duration=60, # remove this line for full video
  initialize=initialize,
  get_latents=get_latents,
  get_noise=get_noise,
  # get_bends=get_bends, # if you're running a 1024px network you can uncomment this for 1920x1080 output
)

is giving me a _queue.Empty error. When I try the same command on 1920 with these arguments:

generate(
  ckpt="FreaGAN.pt",
  audio_file=audio_file,
  output_dir="../",
  out_size=1920, # at the moment only 512x512, 1024x1024, 1920x1080 outputs are supported (out_size = 512, 1024, or 1920 respectively)
  G_res=1024,
  batch=1,  # CUDA out of memory errors => smaller batch (also try running the previous cell, to clear some GPU memory)
  ffmpeg_preset="faster",  # RAM crashes => faster preset (see https://trac.ffmpeg.org/wiki/Encode/H.264)
  fps=24,
  duration=60, # remove this line for full video
  initialize=initialize,
  get_latents=get_latents,
  get_noise=get_noise,
  get_bends=get_bends, # if you're running a 1024px network you can uncomment this for 1920x1080 output
)

I end up getting that Broken Pipe Error.

I'm using the FreaGAN model thats listed in the colab, which I understand should be a 1024x1024 StyleGAN2 model. Any idea what might be happening here?

JCBrouwer commented 3 years ago

Ahh OK, the queue.Empty error is just colab being slow. The first time you run it'll compile the custom CUDA ops which takes more than the 10 second timeouts of the render queues. I've just upped the timeouts, although it would probably be better to figure out a way to compile the ops before starting the queues. Even with the short timeout, just trying the cell again would probably already work.

I'm having trouble reproducing the broken pipe error. I think maybe it was also just a downstream error being caused by the ffmpeg queue timing out. With these kinds of errors a full stack trace would really help me debug. Often times the cause of the error is clear just a couple lines above the final message.

Can you try again now? I've just been able to render a full 1920x1080 video by hitting run all. Sorry about the rocky user experience haha

I'm hoping to start on a big reboot of this repo for a course this quarter. Currently a lot of things are kind of hacked together which makes it hard to maintain and hard to use. If I can convince our supervisor that this is a good enough topic then there should be a lot of upgrades coming over then next 8-10 weeks.

jackylu97 commented 3 years ago

Thanks! I figured out what was going wrong - for whatever reason the test mp3 I've been using has been failing, but the colab seems to be working for different songs. No clue why this might be, but here's the stacktrace (frustratingly, it doesn't give much in the way of detail:

Exception in thread Thread-17:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/content/maua-stylegan2/render.py", line 110, in make_video
    video.stdin.write(img.tobytes())
BrokenPipeError: [Errno 32] Broken pipe

Since it's just the one mp3 that seems to not work, feel free to close this issue out; I can do some digging on my own to figure out why this might be the case.

Exciting that you're planning on working on this more! Happy to contribute here and there depending on your future plans.

JCBrouwer commented 3 years ago

Ahh ok, weird that the error is so bad. I've looked around but can't really find anything about this online, I guess this will just stay as it is for now :/

dvschultz commented 3 years ago

I don’t think know if this needs to be re-opened, but I also get the broken pipe error when running the generate.py script directly from a cell in Colab. I’ll dig around more to try and figure out what’s going on.

Ran: !python generate_audiovisual.py --ckpt "/content/ladiesblack.pt" --audio_file "/content/Lunice - Run Around.mp3"

Got:

rendering 4173 frames...
  0%|                                        | 1/4173 [00:03<3:38:36,  3.14s/it]./output/lunice - run around_ladiesblack_b1c44fcc.mp4: No such file or directory
  0%|                                        | 1/4173 [00:03<3:39:53,  3.16s/it]
Exception in thread Thread-6:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/content/maua-stylegan2/render.py", line 110, in make_video
    video.stdin.write(img.tobytes())
BrokenPipeError: [Errno 32] Broken pipe
dvschultz commented 3 years ago

ok I think my issue was that the default --output_dir is ./output and that folder didn’t exist. Once I set a new path and made sure it existed it worked fine. Might be helpful to have an os.makedirs in there to be sure. I can submit a PR for that.