parser.add_argument('--backend',type=str,default='caffe+scipy',choices=['torch','caffe+scipy'],help='reconstruction implementation') parser.add_argument('--device_id',type=int,default=0,help='zero-indexed CUDA device') parser.add_argument('--K',type=int,default=100,help='number of nearest neighbors') parser.add_argument('--scaling',type=str,default='beta',choices=['none','beta'],help='type of step scaling') parser.add_argument('--iter',type=int,default=500,help='number of reconstruction iterations') parser.add_argument('--postprocess',type=str,default='color',help='comma-separated list of postprocessing operations') parser.add_argument('--delta',type=str,default='0.4',help='comma-separated list of interpolation steps') config=parser.parse_args() postprocess=set(config.postprocess.split(',')) print(json.dumps(config.__dict__)) # load CUDA model minimum_resolution=200 if config.backend=='torch': import deepmodels_torch model=deepmodels_torch.vgg19g_torch(device_id=config.device_id) elif config.backend=='caffe+scipy': model=deepmodels.vgg19g(device_id=config.device_id) else: raise ValueError('Unknown backend') # download AEGAN cropped+aligned LFW (if needed) if not os.path.exists('images/lfw_aegan'): url='https://www.dropbox.com/s/isz4ske2kheuwgr/lfw_aegan.tar.gz?dl=1' subprocess.check_call(['wget',url,'-O','lfw_aegan.tar.gz']) subprocess.check_call(['tar','xzf','lfw_aegan.tar.gz']) subprocess.check_call(['rm','lfw_aegan.tar.gz']) # read test data data=numpy.load('tests/dmt2-lfw-multiple-attribute-test.npz') pairs=list(data['pairs'][[0,1,2,4,5,6]]) # skip flushed face, not interesting
parser.add_argument('-ip', '--input_path', type=str,default='images/celeba', help='the training image folder') parser.add_argument('-gpu', type=str, default='0', help='the gpu id to use') parser.add_argument('--backend', type=str, default='torch', choices=['torch', 'caffe+scipy'], help='reconstruction implementation') parser.add_argument('--K', type=int, default=100, help='number of nearest neighbors') parser.add_argument('--delta', type=str, default='3.5', help='comma-separated list of interpolation steps') parser.add_argument('--npz_path', type=str, default='attribute_vector', help='the path to store npz data') config = parser.parse_args() # print(json.dumps(config.__dict__)) os.environ['CUDA_VISIBLE_DEVICES'] = config.gpu # load models if config.backend == 'torch': import deepmodels_torch model = deepmodels_torch.vgg19g_torch(device_id=0) elif config.backend == 'caffe+scipy': model = deepmodels.vgg19g(device_id=0) else: raise ValueError('Unknown backend') classifier = deepmodels.facemodel_attributes() fields = classifier.fields() gender = fields.index('Male') smile = fields.index('Smiling') face_d, face_p = alignface.load_face_detector() # Set the free parameters K = config.K delta_params = [float(x.strip()) for x in config.delta.split(',')] image_list = glob.glob(config.input_path+'/*') X = image_list t0 = time.time()