@@ -364,8 +364,18 @@ def run_projection(
364364 )
365365 print (f'Elapsed: { (perf_counter ()- start_time ):.1f} s' )
366366
367- # Render debug output: optional video and projected image and W vector.
368367 os .makedirs (outdir , exist_ok = True )
368+ # Save final projected frame and W vector.
369+ if target_fname :
370+ target_pil .save (f'{ outdir } /target.png' )
371+ projected_w = projected_w_steps [- 1 ]
372+ synth_image = G .synthesis (projected_w .unsqueeze (0 ), noise_mode = 'const' )
373+ synth_image = (synth_image + 1 ) * (255 / 2 )
374+ synth_image = synth_image .permute (0 , 2 , 3 , 1 ).clamp (0 , 255 ).to (torch .uint8 )[0 ].cpu ().numpy ()
375+ PIL .Image .fromarray (synth_image , 'RGB' ).save (f'{ outdir } /proj.png' )
376+ np .savez (f'{ outdir } /projected_w.npz' , w = projected_w .unsqueeze (0 ).cpu ().numpy ())
377+
378+ # Render debug output: optional video and projected image and W vector.
369379 if save_video :
370380 video = imageio .get_writer (f'{ outdir } /proj.mp4' , mode = 'I' , fps = 10 , codec = 'libx264' , bitrate = '16M' )
371381 print (f'Saving optimization progress video "{ outdir } /proj.mp4"' )
@@ -379,16 +389,6 @@ def run_projection(
379389 video .append_data (synth_image )
380390 video .close ()
381391
382- # Save final projected frame and W vector.
383- if target_fname :
384- target_pil .save (f'{ outdir } /target.png' )
385- projected_w = projected_w_steps [- 1 ]
386- synth_image = G .synthesis (projected_w .unsqueeze (0 ), noise_mode = 'const' )
387- synth_image = (synth_image + 1 ) * (255 / 2 )
388- synth_image = synth_image .permute (0 , 2 , 3 , 1 ).clamp (0 , 255 ).to (torch .uint8 )[0 ].cpu ().numpy ()
389- PIL .Image .fromarray (synth_image , 'RGB' ).save (f'{ outdir } /proj.png' )
390- np .savez (f'{ outdir } /projected_w.npz' , w = projected_w .unsqueeze (0 ).cpu ().numpy ())
391-
392392#----------------------------------------------------------------------------
393393
394394if __name__ == "__main__" :
0 commit comments