1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import click
from app.search.search_class import find_nearest_vector_for_images
@click.command('')
@click.option('-i', '--input', 'opt_fp_in', required=True,
help='Path to input image')
@click.option('-d', '--dims', 'opt_dims', default=512, type=int,
help='Dimensions of BigGAN network (128, 256, 512)')
@click.option('-s', '--steps', 'opt_steps', default=2000, type=int,
help='Number of optimization iterations')
@click.option('-l', '--limit', 'opt_limit', default=1000, type=int,
help='Limit the number of images to process')
@click.option('-v', '--video', 'opt_video', is_flag=True,
help='Export a video for each dataset')
@click.option('-t', '--tag', 'opt_tag', default='inverse_' + str(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_steps, opt_limit, opt_video, opt_tag):
"""
Search for an image (class vector) in BigGAN using gradient descent
"""
if os.path.isdir(opt_fp_in):
paths = glob(os.path.join(opt_fp_in, '*.jpg')) + \
glob(os.path.join(opt_fp_in, '*.jpeg')) + \
glob(os.path.join(opt_fp_in, '*.png'))
else:
paths = [opt_fp_in]
find_nearest_vector_for_images(paths, opt_dims, opt_steps, opt_video, opt_tag, opt_limit)
|