def main(): """main function""" args = arg_parse() message = ProbeMessage(args.verbose) measurements = get_measurements(args.measurement_id, args.key) parsed_measurements = parse_measurements(measurements, args.name, message) check_measurements(parsed_measurements, args, message) if len(measurements) < args.crit_probes: print 'ERROR: only recived {} messages'.format(len(measurements)) sys.exit(2) elif len(measurements) < args.warn_probes: print 'WARN: only recived {} messages'.format(len(measurements)) sys.exit(1) message.exit(args)
def main(): """main function""" args = arg_parse() message = ProbeMessage(args.verbose) measurements = get_measurements(args.measurement_id, args.key) parsed_measurements = parse_measurements( measurements, args.name, message) check_measurements(parsed_measurements, args, message) if len(measurements) < args.crit_probes: print 'ERROR: only recived {} messages'.format(len(measurements)) sys.exit(2) elif len(measurements) < args.warn_probes: print 'WARN: only recived {} messages'.format(len(measurements)) sys.exit(1) message.exit(args)
def main(hparams): # set up perceptual loss device = 'cuda:0' percept = PerceptualLoss( model="net-lin", net="vgg", use_gpu=device.startswith("cuda") ) utils.print_hparams(hparams) # get inputs xs_dict = model_input(hparams) estimators = utils.get_estimators(hparams) utils.setup_checkpointing(hparams) measurement_losses, l2_losses, lpips_scores, z_hats = utils.load_checkpoints(hparams) x_hats_dict = {model_type : {} for model_type in hparams.model_types} x_batch_dict = {} A = utils.get_A(hparams) noise_batch = hparams.noise_std * np.random.standard_t(2, size=(hparams.batch_size, hparams.num_measurements)) for key, x in xs_dict.items(): if not hparams.not_lazy: # If lazy, first check if the image has already been # saved before by *all* estimators. If yes, then skip this image. save_paths = utils.get_save_paths(hparams, key) is_saved = all([os.path.isfile(save_path) for save_path in save_paths.values()]) if is_saved: continue x_batch_dict[key] = x if len(x_batch_dict) < hparams.batch_size: continue # Reshape input x_batch_list = [x.reshape(1, hparams.n_input) for _, x in x_batch_dict.items()] x_batch = np.concatenate(x_batch_list) # Construct noise and measurements y_batch = utils.get_measurements(x_batch, A, noise_batch, hparams) # Construct estimates using each estimator for model_type in hparams.model_types: estimator = estimators[model_type] x_hat_batch, z_hat_batch, m_loss_batch = estimator(A, y_batch, hparams) for i, key in enumerate(x_batch_dict.keys()): x = xs_dict[key] y_train = y_batch[i] x_hat = x_hat_batch[i] # Save the estimate x_hats_dict[model_type][key] = x_hat # Compute and store measurement and l2 loss measurement_losses[model_type][key] = m_loss_batch[key] l2_losses[model_type][key] = utils.get_l2_loss(x_hat, x) lpips_scores[model_type][key] = utils.get_lpips_score(percept, x_hat, x, hparams.image_shape) z_hats[model_type][key] = z_hat_batch[i] print('Processed upto image {0} / {1}'.format(key+1, len(xs_dict))) # Checkpointing if (hparams.save_images) and ((key+1) % hparams.checkpoint_iter == 0): utils.checkpoint(x_hats_dict, measurement_losses, l2_losses, lpips_scores, z_hats, save_image, hparams) x_hats_dict = {model_type : {} for model_type in hparams.model_types} print('\nProcessed and saved first ', key+1, 'images\n') x_batch_dict = {} # Final checkpoint if hparams.save_images: utils.checkpoint(x_hats_dict, measurement_losses, l2_losses, lpips_scores, z_hats, save_image, hparams) print('\nProcessed and saved all {0} image(s)\n'.format(len(xs_dict))) if hparams.print_stats: for model_type in hparams.model_types: print(model_type) measurement_loss_list = list(measurement_losses[model_type].values()) l2_loss_list = list(l2_losses[model_type].values()) mean_m_loss = np.mean(measurement_loss_list) mean_l2_loss = np.mean(l2_loss_list) print('mean measurement loss = {0}'.format(mean_m_loss)) print('mean l2 loss = {0}'.format(mean_l2_loss)) if hparams.image_matrix > 0: utils.image_matrix(xs_dict, x_hats_dict, view_image, hparams) # Warn the user that some things were not processsed if len(x_batch_dict) > 0: print('\nDid NOT process last {} images because they did not fill up the last batch.'.format(len(x_batch_dict))) print('Consider rerunning lazily with a smaller batch size.')
# makes signals xs = np.random.normal(size=(3, image_size**2)) xs[2] = xs[0] + xs[1] # random anchors anchors = np.random.normal(size=(number_of_anchors, image_size**2)) # interefere with anchors x1_inter = interfere_with_anchors(image_size, xs[0], anchors) x2_inter = interfere_with_anchors(image_size, xs[1], anchors) x1_plus_x2_inter = interfere_with_anchors(image_size, xs[2], anchors) opu_input = np.vstack((x1_inter, x2_inter, x1_plus_x2_inter)) # get quantized measurements y, A = get_measurements(opu_input, num_of_rows_in_A) y, y_quant = quantise_measurements(y, num_bits) floor = 0 y_quant[y_quant < floor] = 0 # put measurements into distance matrices all_D_quant_x1, all_D_quant_x2, all_D_quant_x1_plus_x2 = make_D_ensembles( y_quant, number_of_anchors) # for storing results manual = np.zeros([num_of_rows_in_A, number_of_anchors + 1 - 2]).astype('complex128') direct = np.zeros([num_of_rows_in_A, number_of_anchors + 1 - 2]).astype('complex128') manual_gd = np.zeros([num_of_rows_in_A, number_of_anchors + 1 - 2]).astype('complex128')