brycedrennan / imaginAIry

Pythonic AI generation of images and videos
MIT License
7.94k stars 441 forks source link

Slow face restore #156

Closed RichardMcSorley closed 1 year ago

RichardMcSorley commented 1 year ago

Anything can be done for improving speeds when attempting to restore faces + upscale?

Each prompt takes roughly 25s

Image Generated. Timings: conditioning:0.08s sampling:4.07s safety-filter:3.57s 
 78%|███████▊  | 31/40 [00:03<00:00, 10.23it/s]
 82%|████████▎ | 33/40 [00:03<00:00, 10.23it/s]
 88%|████████▊ | 35/40 [00:03<00:00, 10.23it/s]
 92%|█████████▎| 37/40 [00:03<00:00, 10.22it/s]
 98%|█████████▊| 39/40 [00:03<00:00, 10.23it/s]
100%|██████████| 40/40 [00:04<00:00,  9.84it/s]
2023-01-10T23:23:57.546510041Z     Fixing 😊 's in 🖼  using CodeFormer...
2023-01-10T23:23:57.776882963Z     Enhancing 1 faces
2023-01-10T23:24:12.542777308Z     Upscaling 🖼  using real-ESRGAN...
2023-01-10T23:24:13.557640499Z     Image Generated. Timings: conditioning:0.08s sampling:4.07s safety-filter:3.57s total:24.00s
2023-01-10T23:24:13.559871646Z     🖼  [generated] saved to: /workspace/prompt_images/generated/000087_606395999_keulera40_PS10.0_modelshoot_style,_a_portrait_of_a_white_me_man_photorealistic,_hand_on_hip,_sitting,_from_side,_award_winning_photography,_color,__[generated].jpg
2023-01-10T23:24:13.581817137Z     🖼  [upscaled] saved to: /workspace/prompt_images/upscaled/000087_606395999_keulera40_PS10.0_modelshoot_style,_a_portrait_of_a_white_me_man_photorealistic,_hand_on_hip,_sitting,_from_side,_award_winning_photography,_color,__[upscaled].jpg
2023-01-10T23:24:13.581837627Z Generating 🖼  89/200: "modelshoot style, a portrait of a white @me man photorealistic, hand_on_hip, from_behind, award winning photography, color, photo" 576x704px negative-prompt:"white man, woman, glasses , canvas frame, cartoon, 3d, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&w)), wierd colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, 3d render" seed:20002305 prompt-strength:10.0 steps:40 sampler-type:k_euler_a
2023-01-10T23:24:13.648416240Z 

CPU utilization to go up to 100% seems when restoring faces.

Prompt inference seems to be using GPU fine as I see it spike up and back down.

RichardMcSorley commented 1 year ago

--fix-faces adds an additional 7-10 seconds.

2023-01-11T09:06:14.208159005Z     Fixing 😊 's in 🖼  using CodeFormer...
2023-01-11T09:06:14.434474197Z     Enhancing 1 faces
2023-01-11T09:06:24.090127494Z     Image Generated. Timings: conditioning:0.02s sampling:4.03s safety-filter:1.43s total:15.61s
brycedrennan commented 1 year ago

I dont think it takes that long for me. What system are you on?

brycedrennan commented 1 year ago

Face enhancement is run partially on the CPU to save memory. For me it's taking ~3.2s per face. I did some quick hacks to run it on CUDA and it runs in 0.33s per face.

brycedrennan commented 1 year ago

I just released 7.4.2 which moves face enhancement to the GPU. should provide a large speedup.