diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-12-10 22:44:49 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-12-10 22:44:49 +0100 |
| commit | 3562a70cccb842becb9a33d867f83e6a00dc3635 (patch) | |
| tree | 2d03339cc3b94d22a47549c7bf0bef6a4b2a1e44 /cli/app | |
| parent | 3852f8b30183f87633151aab017d7fbe4891bdd6 (diff) | |
write json params
Diffstat (limited to 'cli/app')
| -rw-r--r-- | cli/app/commands/biggan/search.py | 11 | ||||
| -rw-r--r-- | cli/app/search/json.py | 92 |
2 files changed, 100 insertions, 3 deletions
diff --git a/cli/app/commands/biggan/search.py b/cli/app/commands/biggan/search.py index 0b31a0d..5844855 100644 --- a/cli/app/commands/biggan/search.py +++ b/cli/app/commands/biggan/search.py @@ -17,6 +17,7 @@ import tensorflow_hub as hub import shutil import h5py +from app.search.json import save_params_latent, save_params_dense from app.search.image import image_to_uint8, imconvert_uint8, imconvert_float32, \ imread, imwrite, imgrid from app.search.vector import truncated_z_sample, truncated_z_single, create_labels @@ -28,11 +29,13 @@ from app.search.vector import truncated_z_sample, truncated_z_single, create_lab help='Dimensions of BigGAN network (128, 256, 512)') @click.option('-v', '--video', 'opt_video', is_flag=True, help='Export a video for each dataset') +@click.option('-t', '--tag', 'opt_tag', default='inverse_' + int(time.time() * 1000), + help='Tag this dataset') # @click.option('-r', '--recursive', 'opt_recursive', is_flag=True) @click.pass_context def cli(ctx, opt_fp_in, opt_dims, opt_video): """ - Search for an image in BigGAN using gradient descent + Search for an image (class vector) in BigGAN using gradient descent """ generator = hub.Module('https://tfhub.dev/deepmind/biggan-' + str(opt_dims) + '/2') @@ -56,9 +59,11 @@ def cli(ctx, opt_fp_in, opt_dims, opt_video): else: paths = [opt_fp_in] - fp_inverses = os.path.join(app_cfg.INVERSES_DIR, 'inverse_' + int(time.time() * 1000)) + fp_inverses = os.path.join(app_cfg.INVERSES_DIR, opt_tag) os.makedirs(fp_inverses, exist_ok=True) - out_file = h5py.File(fp_inverses, 'w') + save_params_latent(fp_inverses, opt_tag) + save_params_dense(fp_inverses, opt_tag) + out_file = h5py.File(join(fp_inverses, 'dataset.hdf5'), 'w') out_images = out_file.create_dataset('xtrain', (len(paths), 3, 512, 512,), dtype='float32') out_labels = out_file.create_dataset('ytrain', (len(paths), vocab_size,), dtype='float32') diff --git a/cli/app/search/json.py b/cli/app/search/json.py new file mode 100644 index 0000000..0f6c71c --- /dev/null +++ b/cli/app/search/json.py @@ -0,0 +1,92 @@ +from os.path import join +from app.utils.file_utils import write_json + +def save_params_latent(fp_out_dir, tag): + data = { + "tag": tag, + "decay_n": 2, + "features": True, + "clip": 1.0, + "stochastic_clipping": False, + "clipping": False, + "dataset": "inverses/{}/dataset.hdf5".format(tag), + "inv_layer": "latent", + "decay_lr": True, + "inv_it": 15000, + "generator_path": "https://tfhub.dev/deepmind/biggan-512/2", + "attention_map_layer": "Generator_2/attention/Softmax:0", + "pre_trained_latent": False, + "lambda_dist": 0.0, + "likeli_loss": True, + "init_hi": 0.001, + "lr": 0.1, + "norm_loss": False, + "generator_fixed_inputs": { + "truncation": 1.0 + }, + "log_z_norm": True, + "feature_extractor_path": "https://tfhub.dev/google/imagenet/inception_v3/feature_vector/1", + "mse": True, + "custom_grad_relu": False, + "random_label": False, + "lambda_feat": 1.0, + "init_gen_dist": False, + "log_activation_layer": "Generator_2/GBlock/Relu:0", + "batch_size": 4, + "fixed_z": False, + "feature_extractor_output": "InceptionV3/Mixed_7a", + "init_lo": -0.001, + "lambda_mse": 1.0, + "lambda_reg": 0.1, + "dist_loss": False, + "sample_size": 4, + "dataset": "inverses/{}/dataset.encodings.hdf5".format(tag), + "save_progress": True, + } + fp_out_fn = join(fp_out_dir, "params_latent.json") + write_json(data, fp_out_fn) + +def save_params_dense(fp_out_dir, tag): + data = { + "tag": tag, + "decay_n": 2, + "features": True, + "clip": 1.0, + "stochastic_clipping": False, + "clipping": False, + "dataset": "inverses/{}/dataset.encodings.hdf5".format(tag), + "inv_layer": "Generator_2/G_Z/Reshape:0", + "decay_lr": True, + "inv_it": 15000, + "generator_path": "https://tfhub.dev/deepmind/biggan-512/2", + "attention_map_layer": "Generator_2/attention/Softmax:0", + "pre_trained_latent": True, + "lambda_dist": 10.0, + "likeli_loss": False, + "init_hi": 0.001, + "lr": 0.01, + "norm_loss": False, + "generator_fixed_inputs": { + "truncation": 1.0 + }, + "log_z_norm": False, + "feature_extractor_path": "https://tfhub.dev/google/imagenet/inception_v3/feature_vector/1", + "mse": True, + "custom_grad_relu": False, + "random_label": False, + "lambda_feat": 1.0, + "init_gen_dist": False, + "log_activation_layer": "Generator_2/GBlock/Relu:0", + "batch_size": 4, + "fixed_z": True, + "feature_extractor_output": "InceptionV3/Mixed_7a", + "init_lo": -0.001, + "lambda_mse": 1.0, + "lambda_reg": 0.1, + "dist_loss": True, + "sample_size": 4, + "dataset": "inverses/{}/dataset.encodings.dense.hdf5".format(tag), + "save_progress": True, + } + fp_out_fn = join(fp_out_dir, "params_dense.json") + write_json(data, fp_out_fn) |
