Ejemplo n.º 1
0
import numpy as np
import os

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'  # BE QUIET!!!!
import tensorflow as tf

np.random.seed(1)  # numpy is good about making repeatable output
tf.set_random_seed(
    1)  # on the other hand, this is basically useless (see issue 9171)

# import our problems, networks and training modules
from tools import problems, networks, train

# Create the basic problem structure.
prob = problems.bernoulli_gaussian_trial(
    kappa=None, M=250, N=500, L=1000, pnz=.1,
    SNR=40)  #a Bernoulli-Gaussian x, noisily observed through a random matrix
#prob = problems.random_access_problem(2) # 1 or 2 for compressive random access or massive MIMO

# build a LAMP network to solve the problem and get the intermediate results so we can greedily extend and then refine(fine-tune)
layers = networks.build_LAMP(prob, T=6, shrink='bg', untied=False)

# plan the learning
training_stages = train.setup_training(layers,
                                       prob,
                                       trinit=1e-3,
                                       refinements=(.5, .1, .01))

# do the learning (takes a while)
sess = train.do_training(training_stages, prob, 'LAMP_bg_giid.npz')
Ejemplo n.º 2
0
"""
This file serves as an example of how to 
a) select a problem to be solved 
b) select a network type
c) train the network to minimize recovery MSE

"""
import numpy as np
import os

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'  # BE QUIET!!!!
# os.environ['CUDA_VISIBLE_DEVICES'] = '7'
import tensorflow as tf

np.random.seed(1)  # numpy is good about making repeatable output
tf.set_random_seed(
    1)  # on the other hand, this is basically useless (see issue 9171)

from tools import problems, networks, train
A = np.load('A_250_500.npy')

prob = problems.bernoulli_gaussian_trial(
    A=A, M=250, N=500, L=10000, is_train=False
)  #a Bernoulli-Gaussian x, noisily observed through a random matrix

T = 14

layers = networks.build_LAMP(prob, T=T, shrink='soft', untied=False)
train.do_testing_another(layers, prob, T,
                         'LAMP-soft T=' + str(T) + ' trainrate=0.001.npz')
Ejemplo n.º 3
0
    prob = problems.bernoulli_gaussian_trial(M=parsed.M,
                                             N=parsed.N,
                                             L=parsed.L,
                                             pnz=parsed.pnz,
                                             kappa=parsed.kappa,
                                             SNR=parsed.SNR)
    # save problems
    base = parsed.dest_probs + "/problem_k{0:04.1f}_{1}".format(
        parsed.kappa, parsed.id)
    problems.save_problem(base, prob)

    if parsed.model == 'LVAMP':
        layers = networks.build_LVAMP(prob, T=parsed.T, shrink=parsed.shrink)
    elif parsed.model == 'LAMP':
        layers = networks.build_LAMP(prob,
                                     T=parsed.T,
                                     shrink=parsed.shrink,
                                     untied=False)
    elif parsed.model == 'LISTA':
        layers = networks.build_LISTA(prob, T=parsed.T, untied=False)
    else:
        raise ValueError('Wrong model designated')

    # plan the training
    training_stages = train.setup_training(layers,
                                           prob,
                                           trinit=1e-3,
                                           refinements=(.5, .1, .01))

    # get saved model file name as 'models/LAMP_bg_k05.1_2.npz'
    model_name = parsed.dest_models + '/' + parsed.model + '_' + parsed.shrink + \
                    '_k{0:04.1f}_{1}.npz'.format(parsed.kappa, parsed.id)