Exemplo n.º 1
0
def plots010(saved_model,
             Net,
             LIDAR_TYPE='ABSOLUTE',
             EMBEEDING='embedded',
             intermediate_dim=1):
    ### Plot Validation Accuracy for LoS and NLoS channels
    #NLOS
    if LIDAR_TYPE == 'CENTERED':
        POS_val, LIDAR_val, Y_val, NLOS_val = load_dataset(
            './data/s010_centered.npz', FLATTENED, SUM)
    elif LIDAR_TYPE == 'ABSOLUTE':
        POS_val, LIDAR_val, Y_val, NLOS_val = load_dataset(
            './data/s010_original_labels.npz', FLATTENED, SUM)
        POS_val = POS_val[:, 0:2]
    elif LIDAR_TYPE == 'ABSOLUTE_LARGE':
        POS_val, LIDAR_val, Y_val, NLOS_val = load_dataset(
            './data/s010_large.npz', FLATTENED, SUM)
    if (Net == 'MULTIMODAL'):
        model = MULTIMODAL(FLATTENED, LIDAR_TYPE)
        model.load_weights(saved_model)
        preds = model.predict([LIDAR_val, POS_val])  # Get predictions
    elif (Net == 'MULTIMODAL_OLD'):
        model = MULTIMODAL_OLD(FLATTENED, LIDAR_TYPE)
        model.load_weights(saved_model)
        preds = model.predict([LIDAR_val * 3 - 2, POS_val])  # Get predictions
    elif (Net == 'IPC'):
        model = LIDAR(FLATTENED, LIDAR_TYPE)
        model.load_weights(saved_model)
        preds = model.predict(LIDAR_val)  # Get predictions
    elif (Net == 'GPS'):
        model = GPS()
        model.load_weights(saved_model)
        preds = model.predict(POS_val)  # Get predictions
    elif (Net == 'MIXTURE'):
        model = MIXTURE(FLATTENED, LIDAR_TYPE)
        model.load_weights(saved_model)
        preds = model.predict([LIDAR_val * 3 - 2, POS_val])  # Get predictions
    elif (Net == 'NON_LOCAL_MIXTURE'):
        model = NON_LOCAL_MIXTURE(FLATTENED, LIDAR_TYPE, EMBEEDING,
                                  intermediate_dim)
        model.load_weights(saved_model)
        preds = model.predict([LIDAR_val * 3 - 2, POS_val])  # Get predictions
    preds = np.argsort(-preds, axis=1)  #Descending order
    true = np.argmax(Y_val[:, :], axis=1)  #Best channel
    curve = np.zeros(256)
    for i in range(0, len(preds)):
        curve[np.where(preds[i, :] == true[i])] = curve[np.where(
            preds[i, :] == true[i])] + 1
    curve = np.cumsum(curve)
    return curve
Exemplo n.º 2
0
def throughtputRatioIPC(model,LIDAR_val):
    _, _, Y_val, _ =load_dataset('./data/s009_unnormalized_labels.npz',True,False)
    preds = model.predict(LIDAR_val)    # Get predictionspredictions
    preds= np.argsort(-preds, axis=1) #Descending order
    true=np.argmax(Y_val[:,:], axis=1) #Best channel
    curve=np.zeros((len(preds),256))
    max_gain=np.zeros(len(preds))
    for i in range(0,len(preds)):
        max_gain[i]=Y_val[i,true[i]]
        curve[i,0]=Y_val[i,preds[i,0]]
        for j in range(1,256):
            curve[i,j]=np.max([curve[i,j-1],Y_val[i,preds[i,j]]])
    curve=np.sum(np.log2(1+curve),axis=0)/np.sum(np.log2(max_gain+1))
    return curve
Exemplo n.º 3
0
VAL_S009 = False
NET_TYPE = 'MIXTURE'  #Type of network
FLATTENED = True  #If True Lidar is 2D
SUM = False  #If True uses the method lidar_to_2d_summing() instead of lidar_to_2d() in dataLoader.py to process the LIDAR
SHUFFLE = False
LIDAR_TYPE = 'ABSOLUTE'
TRAIN_TYPES = ['CURR', 'ANTI', 'VANILLA', 'ONLY_LOS', 'ONLY_NLOS']
TRAIN_TYPE = 'VANILLA'
if TRAIN_TYPE not in TRAIN_TYPES:
    print('Vanilla training over the entire dataset')
    TRAIN_TYPE = ''
batch_size = 32
num_epochs = 30
'''Loading Data'''
if LIDAR_TYPE == 'CENTERED':
    POS_tr, LIDAR_tr, Y_tr, NLOS_tr = load_dataset('./data/s008_centered.npz',
                                                   FLATTENED, SUM)
    POS_val, LIDAR_val, Y_val, NLOS_val = load_dataset(
        './data/s009_centered.npz', FLATTENED, SUM)
    POS_te, LIDAR_te, Y_te, _ = load_dataset('./data/s010_centered.npz',
                                             FLATTENED, SUM)
elif LIDAR_TYPE == 'ABSOLUTE':
    POS_tr, LIDAR_tr, Y_tr, NLOS_tr = load_dataset(
        './data/s008_original_labels.npz', FLATTENED, SUM)
    POS_val, LIDAR_val, Y_val, NLOS_val = load_dataset(
        './data/s009_original_labels.npz', FLATTENED, SUM)
    POS_te, LIDAR_te, Y_te, _ = load_dataset('./data/s010_original_labels.npz',
                                             FLATTENED, SUM)
elif LIDAR_TYPE == 'ABSOLUTE_LARGE':
    POS_tr, LIDAR_tr, Y_tr, NLOS_tr = load_dataset('./data/s008_large.npz',
                                                   FLATTENED, SUM)
    POS_val, LIDAR_val, Y_val, NLOS_val = load_dataset('./data/s009_large.npz',
BETA = [0.8]  #Beta values for the KD loss function
VAL_S009 = True
NET_TYPE = 'MIXTURE'  #Type of network
FLATTENED = True  #If True Lidar is 2D
SUM = False  #If True uses the method lidar_to_2d_summing() instead of lidar_to_2d() in dataLoader.py to process the LIDAR
SHUFFLE = False
LIDAR_TYPE = 'ABSOLUTE'
TRAIN_TYPES = ['CURR', 'ANTI', 'VANILLA', 'ONLY_LOS', 'ONLY_NLOS']
TRAIN_TYPE = 'CURR'
if TRAIN_TYPE not in TRAIN_TYPES:
    print('Vanilla training over the entire dataset')
    TRAIN_TYPE = ''
batch_size = 32
num_epochs = 45
'''Loading Data'''
POS_tr, LIDAR_tr, Y_tr, NLOS_tr = load_dataset(
    './data/s008_original_labels.npz', FLATTENED, SUM)
POS_val, LIDAR_val, Y_val, NLOS_val = load_dataset(
    './data/s009_original_labels.npz', FLATTENED, SUM)
'''Discard Z-component'''
POS_tr = POS_tr[:, 0:2]
POS_val = POS_val[:, 0:2]
if (SHUFFLE):
    ind = np.random.shuffle(np.arange(Y_tr.shape[0]) - 1)
    POS_tr = POS_tr[ind, :][0]
    LIDAR_tr = LIDAR_tr[ind, :, :, :][0]
    Y_tr = Y_tr[ind, :][0]
    NLOS_tr = NLOS_tr[ind][0]
'''Creating Curriculum Pacing Values'''
if TRAIN_TYPE in TRAIN_TYPES:
    stumps = 5
    Perc = np.linspace(0, 1, stumps)
Exemplo n.º 5
0
import numpy as np
import matplotlib.pyplot as plt
import h5py
import scipy
from PIL import Image
from scipy import ndimage
from dataLoader import load_dataset
from models import logisticRegression

train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset(
)

m_train = train_set_y.shape[1]
m_test = test_set_y.shape[1]
num_px = train_set_x_orig.shape[1]

### Initial input information ###

print("Number of training examples: m_train = " + str(m_train))
print("Number of testing examples: m_test = " + str(m_test))
print("Height/Width of each image: num_px = " + str(num_px))
print("Each image is of size: (" + str(num_px) + ", " + str(num_px) + ", 3)")
print("train_set_x shape: " + str(train_set_x_orig.shape))
print("train_set_y shape: " + str(train_set_y.shape))
print("test_set_x shape: " + str(test_set_x_orig.shape))
print("test_set_y shape: " + str(test_set_y.shape))

### Flattening dataset for ease of use ###
train_set_x_flatten = train_set_x_orig.reshape(train_set_x_orig.shape[0], -1).T
test_set_x_flatten = test_set_x_orig.reshape(test_set_x_orig.shape[0], -1).T
Exemplo n.º 6
0
def plotNLOSvsLOS(saved_model, Net, LIDAR_TYPE='ABSOLUTE'):
    ### Plot Validation Accuracy for LoS and NLoS channels
    #NLOS
    if LIDAR_TYPE == 'CENTERED':
        POS_val, LIDAR_val, Y_val, NLOS_val = load_dataset(
            './data/s009_centered.npz', FLATTENED, SUM)
    elif LIDAR_TYPE == 'ABSOLUTE':
        POS_val, LIDAR_val, Y_val, NLOS_val = load_dataset(
            './data/s009_original_labels.npz', FLATTENED, SUM)
        POS_val = POS_val[:, 0:2]
    elif LIDAR_TYPE == 'ABSOLUTE_LARGE':
        POS_val, LIDAR_val, Y_val, NLOS_val = load_dataset(
            './data/s009_large.npz', FLATTENED, SUM)
    NLOSind = np.where(NLOS_val == 0)[0]  # Get the NLoS users
    LOSind = np.where(NLOS_val == 1)[0]  # Get the LoS users
    if (Net == 'MULTIMODAL'):
        model = MULTIMODAL(FLATTENED, LIDAR_TYPE)
        model.load_weights(saved_model)
        preds_gains_NLOS = model.predict(
            [LIDAR_val[NLOSind, :, :, :],
             POS_val[NLOSind, :]])  # Get predictions
        preds_gains_LOS = model.predict(
            [LIDAR_val[LOSind, :, :, :],
             POS_val[LOSind, :]])  # Get predictions
    elif (Net == 'IPC'):
        model = LIDAR(FLATTENED, LIDAR_TYPE)
        model.load_weights(saved_model)
        preds_gains_NLOS = model.predict(
            LIDAR_val[NLOSind, :, :, :])  # Get predictions
        preds_gains_LOS = model.predict(
            LIDAR_val[LOSind, :, :, :])  # Get predictions
    elif (Net == 'GPS'):
        model = GPS()
        model.load_weights(saved_model)
        preds_gains_NLOS = model.predict(
            POS_val[NLOSind, :])  # Get predictions
        preds_gains_LOS = model.predict(POS_val[LOSind, :])  # Get predictions
    elif (Net == 'MIXTURE'):
        model = MIXTURE(FLATTENED, LIDAR_TYPE)
        model.load_weights(saved_model)
        preds_gains_NLOS = model.predict(
            [LIDAR_val[NLOSind, :, :, :] * 3 - 2,
             POS_val[NLOSind, :]])  # Get predictions
        preds_gains_LOS = model.predict(
            [LIDAR_val[LOSind, :, :, :] * 3 - 2,
             POS_val[LOSind, :]])  # Get predictions
    pred_NLOS = np.argsort(-preds_gains_NLOS, axis=1)  #Descending order
    true_NLOS = np.argmax(Y_val[NLOSind, :], axis=1)  #Best channel
    curve_NLOS = np.zeros(256)
    for i in range(0, len(pred_NLOS)):
        curve_NLOS[np.where(
            pred_NLOS[i, :] == true_NLOS[i])] = curve_NLOS[np.where(
                pred_NLOS[i, :] == true_NLOS[i])] + 1
    curve_NLOS = np.cumsum(curve_NLOS)
    pred_LOS = np.argsort(-preds_gains_LOS, axis=1)  #Descending order
    true_LOS = np.argmax(Y_val[LOSind, :], axis=1)  #Best channel
    curve_LOS = np.zeros(256)
    for i in range(0, len(pred_LOS)):
        curve_LOS[np.where(
            pred_LOS[i, :] == true_LOS[i])] = curve_LOS[np.where(
                pred_LOS[i, :] == true_LOS[i])] + 1
    curve_LOS = np.cumsum(curve_LOS)
    return curve_LOS, curve_NLOS
    curve=np.sum(np.log2(1+curve),axis=0)/np.sum(np.log2(max_gain+1))
    return curve
def testModel(preds,Y_val):    # Get predictions
    preds= np.argsort(-preds, axis=1) #Descending order
    true=np.argmax(Y_val[:,:], axis=1) #Best channel
    curve=np.zeros(256)
    for i in range(0,len(preds)):
        curve[np.where(preds[i,:] == true[i])]=curve[np.where(preds[i,:] == true[i])]+1
    curve=np.cumsum(curve)
    return curve

if(Create):
    FLATTENED=True      #If True Lidar is 2D
    SUM=False     #If True uses the method lidar_to_2d_summing() instead of lidar_to_2d() in dataLoader.py to process the LIDAR
    LIDAR_TYPE='ABSOLUTE'
    POS_te, LIDAR_te, Y_te, NLOS_te =load_dataset('./data/s008_original_labels.npz',FLATTENED,SUM)
    LIDAR_te = LIDAR_te * 3 - 2
    #Y_te= np.abs(np.load('./data/beams_output_test.npz')['output_classification']).reshape(-1,256)

    for beta in [8]:
        if (NLOS):
            th_LOS = []
            acc_LOS = []
            th_NLOS = []
            acc_NLOS = []
            NLOSind_te = np.where(NLOS_te == 0)[0]
            LOSind_te = np.where(NLOS_te == 1)[0]
        else:
            th = []
            acc = []
        for k in range(0,10):