Example #1
0
                              dataset.text_encoder_type)
        # generate images from pre-extracted embeddings
        if not cfg.B_VALIDATION:
            # generate images for input test set (i.e. custom captions)
            print(
                '\nRunning on example captions...\n++++++++++++++++++++++++++++++'
            )
            root_dir_g = gen_example(dataset.wordtoix,
                                     dataset.text_encoder_type, evaluator)
            end_t = time.time()
            print('Total time for running on example captions:',
                  end_t - start_t)
        else:
            # generate images for the whole valid dataset
            print('\nValidating...\n+++++++++++++')
            root_dir_g = evaluator.sampling(split_dir)
            end_t = time.time()
            print('Total time for validation:', end_t - start_t)
            print()

            # GAN Metrics
            if cfg.B_FID or cfg.B_PPL:  # or cfg.B_IS:
                device = torch.device('cuda' if (
                    torch.cuda.is_available()) else 'cpu')
                num_metrics = 0
                final_dir_g = str(Path(root_dir_g).parent / 'metrics')
                # compute FID
                if cfg.B_FID:
                    print(
                        '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
                    )