def sample(model, model_path, sample_path, num=100, output_name='gen/gen'): pred = PredictConfig(session_init=get_model_loader(model_path), model=model, input_names=['z'], output_names=[output_name, 'z']) batch_size = 100 #print range(num/batch_size) #pdb.set_trace() for i in range(1): pred = SimpleDatasetPredictor(pred, RandomZData( (batch_size, opt.Z_DIM))) n = 0 for o in pred.get_result(): #pdb.set_trace() o, zs = o[0] + 1, o[1] o = o * 128.0 o = np.clip(o, 0, 255) o = o[:, :, :, ::-1] #viz = stack_patches(o, nr_row=10, nr_col=10, viz=True) # for j in range(batch_size): n = n + 1 pdb.set_trace() img = o[j] img = np.dot(img[..., :3], [0.299, 0.587, 0.114]) print img.shape scipy.misc.imsave('%s%09d.jpeg' % (sample_path, n), img) print n if n >= num: break
def sample(model_path): pred = PredictConfig(session_init=get_model_loader(model_path), model=Model(), input_names=['z'], output_names=['gen/gen', 'z']) pred = SimpleDatasetPredictor(pred, RandomZData((100, 100))) for o in pred.get_result(): o, zs = o[0] + 1, o[1] o = o * 128.0 o = o[:, :, :, ::-1] viz = stack_patches(o, nr_row=10, nr_col=10, viz=True)
def sample(model, model_path, output_name='gen/gen'): pred = PredictConfig(session_init=get_model_loader(model_path), model=model, input_names=['z'], output_names=[output_name, 'z']) pred = SimpleDatasetPredictor(pred, RandomZData((100, args.z_dim))) for o in pred.get_result(): o = o[0] + 1 o = o * 128.0 o = np.clip(o, 0, 255) o = o[:, :, :, ::-1] stack_patches(o, nr_row=10, nr_col=10, viz=True)
def sample(model_path): pred = PredictConfig(session_init=get_model_loader(model_path), model=Model(), input_names=['label', 'z'], output_names=['gen/gen']) ds = MapData(RandomZData((100, 100)), lambda dp: [np.arange(100) % 10, dp[0]]) pred = SimpleDatasetPredictor(pred, ds) for o in pred.get_result(): o = o[0] * 255.0 viz = stack_patches(o, nr_row=10, nr_col=10) viz = cv2.resize(viz, (800, 800)) interactive_imshow(viz)
def sample(model, model_path, output_name='gen/gen'): pred = PredictConfig(session_init=SmartInit(model_path), model=model, input_names=['z'], output_names=[output_name, 'z']) pred = SimpleDatasetPredictor(pred, RandomZData((100, args.z_dim))) i = 0 for o in pred.get_result(): o = o[0] + 1 o = o * 128.0 o = np.clip(o, 0, 255) o = o[:, :, :, ::-1] imageio.imwrite("output/" + str(i) + ".png", o[i]) i += 1
def sample(n, model, model_path, output_name='gen/gen', output_filename=None): pred = PredictConfig( session_init=get_model_loader(model_path), model=model, input_names=['z'], output_names=[output_name, 'z']) pred = SimpleDatasetPredictor( pred, RandomZData((opt.batch_size, opt.z_dim))) max_iters = n // opt.batch_size if output_filename is None: output_filename = opt.exp_name if opt.exp_name else 'generate' timestamp = datetime.now().strftime('%m%d_%H%M%S') output_filename += '_{}'.format(timestamp) results = [] for idx, o in enumerate(pred.get_result()): results.append(o[0]) if idx + 1 == max_iters: break results = np.concatenate(results, axis=0) ptr = 0 features = {} for col_id, col_info in enumerate(opt.DATA_INFO['details']): if col_info['type'] == 'category': features['f%02d' % col_id] = results[:, ptr:ptr+1] ptr += 1 elif col_info['type'] == 'value': gaussian_components = col_info['n'] val = results[:, ptr:ptr+1] ptr += 1 pro = results[:, ptr:ptr+gaussian_components] ptr += gaussian_components features['f%02d' % col_id] = np.concatenate([val, pro], axis=1) else: assert 0 np.savez(output_filename, info=json.dumps(opt.DATA_INFO), **features)