(args: argparse.Namespace)
compute the fid for a given trained pro-gan model
    Args:
        args: configuration used for the fid computation
    Returns: None
compute the fid for a given trained pro-gan model
    Args:
        args: configuration used for the fid computation
    Returns: None
compute the fid for a given trained pro - gan model Args : args : configuration used for the fid computation Returns : None
def compute_fid(args: argparse.Namespace) -> None:
    """
    compute the fid for a given trained pro-gan model
    Args:
        args: configuration used for the fid computation
    Returns: None

    """
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

    # load the data from the trained-model
    print(f"loading data from the trained model at: {args.model_path}")
    generator = create_generator_from_saved_model(args.model_path).to(device)

    # create the generated images directory:
    if args.generated_images_path is not None:
        args.generated_images_path.mkdir(parents=True, exist_ok=True)
    generated_images_path = (
        args.generated_images_path
        if args.generated_images_path is not None
        else tempfile.TemporaryDirectory()
    )
    if args.generated_images_path is None:
        image_writing_path = Path(generated_images_path.name)
    else:
        image_writing_path = generated_images_path

    print("generating random images from the trained generator ...")
    with torch.no_grad():
        for img_num in tqdm(range(0, args.num_generated_images, args.batch_size)):
            num_imgs = min(args.batch_size, args.num_generated_images - img_num)
            random_latents = torch.randn(num_imgs, generator.latent_size, device=device)
            gen_imgs = post_process_generated_images(generator(random_latents))

            # write the batch of generated images:
            for batch_num, gen_img in enumerate(gen_imgs, start=1):
                imageio.imwrite(
                    image_writing_path / f"{img_num + batch_num}.png",
                    gen_img,
                )

    # compute the fid once all images are generated
    print("computing fid ...")
    score = fid.compute_fid(
        fdir1=args.dataset_path,
        fdir2=image_writing_path,
        mode="clean",
        num_workers=4,
    )
    print(f"fid score: {score: .3f}")

    # most importantly, don't forget to do the cleanup on the temporary directory:
    if hasattr(generated_images_path, "cleanup"):
        generated_images_path.cleanup()
def compute_fid ( args : argparse . Namespace ) -> None : device = torch . device ( "cuda" if torch . cuda . is_available ( ) else "cpu" ) # load the data from the trained-model print ( f"loading data from the trained model at: {args.model_path}" ) generator = create_generator_from_saved_model ( args . model_path ) . to ( device ) # create the generated images directory: if args . generated_images_path is not None : args . generated_images_path . mkdir ( parents = True , exist_ok = True ) generated_images_path = ( args . generated_images_path if args . generated_images_path is not None else tempfile . TemporaryDirectory ( ) ) if args . generated_images_path is None : image_writing_path = Path ( generated_images_path . name ) else : image_writing_path = generated_images_path print ( "generating random images from the trained generator ..." ) with torch . no_grad ( ) : for img_num in tqdm ( range ( 0 , args . num_generated_images , args . batch_size ) ) : num_imgs = min ( args . batch_size , args . num_generated_images - img_num ) random_latents = torch . randn ( num_imgs , generator . latent_size , device = device ) gen_imgs = post_process_generated_images ( generator ( random_latents ) ) # write the batch of generated images: for batch_num , gen_img in enumerate ( gen_imgs , start = 1 ) : imageio . imwrite ( image_writing_path / f"{img_num + batch_num}.png" , gen_img , ) # compute the fid once all images are generated print ( "computing fid ..." ) score = fid . compute_fid ( fdir1 = args . dataset_path , fdir2 = image_writing_path , mode = "clean" , num_workers = 4 , ) print ( f"fid score: {score: .3f}" ) # most importantly, don't forget to do the cleanup on the temporary directory: if hasattr ( generated_images_path , "cleanup" ) : generated_images_path . cleanup ( )