def launch():
    
    param_MB = lp.load_param('DB_0')
    #param_MB.gammat=[1,1]
    W_k_vrai_MB = tom.UPS_to_MPMB(param_MB.get_upsilon_gt())
    W_k_norm,_ = tom.normalize_MPMB_PS_Tebald(W_k_vrai_MB,param_MB.Na)
    #Données bruitées
    #data_MB=tom.TomoSARDataSet_synth(param_MB)
    #W_k_norm = data_MB.get_W_k_norm_rect(param_MB,nb_echant,Na)
       
    Np=3
    R_t,C_t,_ = tom.sm_separation(W_k_norm,Np,param_MB.Na)
    interv_a,interv_b,mat_cond,_ = tom.search_space_definition(R_t,C_t,param_MB.Na)
    interv_a,interv_b = tom.ground_selection_MB(R_t,interv_a,interv_b)
    
    b=(interv_b[0][0]+interv_b[0][1])/2
    #b = interv_b[0][0]
    g_sol1 = interv_a[0][0]*R_t[0][0,1]+(1-interv_a[0][0])*R_t[1][0,1]
    g_sol2 = interv_a[0][1]*R_t[0][0,1]+(1-interv_a[0][1])*R_t[1][0,1]    
    g_sol_possible = np.array([g_sol1,g_sol2])
    a = interv_a[0][np.argmax(np.abs(g_sol_possible))]    
    
    Rv=b*R_t[0]+(1-b)*R_t[1]
    vec_gm=tom.gamma_from_Rv(Rv)
    
    Npt_hv=100
    Npt_sig=500    
    vec_hv=np.linspace(5,30,Npt_hv)
    vec_sigv=np.linspace(0.01,0.1,Npt_sig)
def example_plot_tomo():
    Np = 3  #Fullpolar

    param_MB = lp.load_param('DB_0')
    param_MB.N = 1000
    W_k_vrai_MB = tom.UPS_to_MPMB(param_MB.get_upsilon())

    data_tomo = tom.TomoSARDataSet_synth(param_MB)

    W_k_noise = data_tomo.get_W_k_rect(param_MB, nb_echant=1000)
    Ups_noise = tom.MPMB_to_UPS(W_k_noise)

    W_k_MB = W_k_noise

    R_t_MB, C_t_MB, G_MB = tom.sm_separation(W_k_MB, Np, param_MB.Na)
    interv_a_MB, interv_b_MB, Cond, alpha = tom.search_space_definition(
        R_t_MB, C_t_MB, param_MB.Na)

    Ups = tom.UPS_to_MPMB(W_k_vrai_MB)
    pt.plot_rc_mb(Ups)
    pt.plot_rc_mb(tom.MPMB_to_UPS(W_k_noise))

    pt.plot_cu_sm_possible(Ups_noise, R_t_MB, interv_a_MB, interv_b_MB, 0, 1,
                           'kz12')
    pt.plot_cu_sm_possible(Ups_noise, R_t_MB, interv_a_MB, interv_b_MB, 0, 2,
                           'kz13')
    pt.plot_cu_sm_possible(Ups_noise, R_t_MB, interv_a_MB, interv_b_MB, 1, 2,
                           'kz23')
def launch_test():

    Na = 3
    Np = 3
    A = 0.75
    E = 71
    k_z = [0.1, 0.2]
    theta = 45 * np.pi / 180
    hv = 30
    sigmav = np.log(10**(0.4 / 20))
    zg = 1
    #Test avec matrice sans bruit de speckle
    #SB
    param_MB = lp.load_param('DB_1')
    Ups = param_MB.get_upsilon()
    N = 1000
    vec = generate_PolInSAR(Ups, N)
def exemple_SKP():

    Np = 3
    param = lp.load_param(name='DB_1')
    param.z_g = 0
    data = tom.TomoSARDataSet_synth(param)
    Wnoise = data.get_W_k_rect(param, 10**3)
    Ups_noise = tom.MPMB_to_UPS(Wnoise)

    W = Wnoise
    Ups = param.get_upsilon()
    W = tom.MPMB_to_UPS(Ups)
    #W = tom.UPS_to_MPMB(param.get_upsilon())
    W_norm, _ = tom.normalize_MPMB_PS_Tebald(W, param.Na)

    #SKP
    R_t, C_t, _ = tom.sm_separation(W_norm, Np, param.Na)

    interv_a, interv_b, _, _, _ = tom.search_space_definition_rob(
        R_t, C_t, param.Na)
    interv_a, interv_b = tom.ground_selection_MB(R_t, interv_a, interv_b)

    #choix du a
    g_sol1 = interv_a[0][0] * R_t[0][0, 1] + (1 - interv_a[0][0]) * R_t[1][0,
                                                                           1]
    g_sol2 = interv_a[0][1] * R_t[0][0, 1] + (1 - interv_a[0][1]) * R_t[1][0,
                                                                           1]
    g_sol_possible = np.array([g_sol1, g_sol2])
    a = interv_a[0][np.argmax(np.abs(g_sol_possible))]

    b = 0.5 * (interv_b[0][0] + interv_b[0][1])

    gsol, gvol = tom.gamma_a_b(R_t, a, b, ant1=0, ant2=1)

    pt.plot_cu_sm_possible(Ups, R_t, interv_a, interv_b, 0, 1, 'kz12')
    plt.hold(True)
    plt.polar(np.angle(gsol), np.abs(gsol), 'ro', markersize=7)
    plt.polar(np.angle(gvol), np.abs(gvol), 'go', markersize=7)
    plt.hold(False)
def exemple_estimateur_SKP():

    param = lp.load_param(name='DB_1')
    W_k_vrai = tom.UPS_to_MPMB(param.get_upsilon_gt())
    data = tom.TomoSARDataSet_synth(param)
    Wnoise = data.get_W_k_rect(param, 10**6)

    #W = W_k_vrai
    W = Wnoise
    W_norm, _ = tom.normalize_MPMB_PS_Tebald(W, param.Na)

    bvrai = tom.b_true(param)
    hv, sigv, vec_gt, bopt = e.estim_ecart_ang_scal(
        W,
        param,
        critere='J2',
        zg_connu=param.z_g,
        U0=np.array([param.h_v, param.sigma_v]),
        b0=bvrai)

    print 'b_vrai {0} b {1}'.format(bvrai, bopt)
    print 'hv_vrai {0} hv {1}'.format(param.h_v, hv)
    print 'sig_vrai {0} sig {1}'.format(param.sigma_v, sigv)
    print 'vec_gt_vrai {0}\n vec_gt {1}'.format(param.get_gtlist(), vec_gt)
    **Entrées**
        * *Na* : nombre d'antennes (acquisitions)
        * *m* : nombre de choix possibles pour une composante
        
    **Sortie**
        * *matM* : matrice Nax(m^Na)"""

    matM = np.zeros((Na, m**Na))
    for i in range(m**Na):
        matM[:, i] = np.array([np.floor(i / m**j) % m for j in range(Na)])
    return matM


if __name__ == '__main__':

    param = lp.load_param('DB_3')
    param.h_v = 30
    param.gammat = np.ones((3, 3)) * 0.95

    verbose = 0
    arg = (param.get_upsilon_gt(), param.get_kzlist(), np.cos(param.theta),
           param.Na, param.N, param.z_g, verbose)

    cons = (
        #{'type':'ineq','fun': c.constr_hv_posit},
        #{'type':'ineq','fun': c.constr_sigv_posit},
        {
            'type': 'ineq',
            'fun': c.constr_Tvol_posit
        },
        {
def recherche_min_optimize_noise(param):
    param = lp.load_param('DB_1')
    param.gammat = 0.95 * np.ones((3, 3))
    param.N = 1e2
    """ Recherche du min (opti.fmin) : algo d'opti en presence de bruit"""
    vec_bcr = np.diag(npl.inv(param.get_fisher_zg_known()))
    dX = np.sqrt(vec_bcr) * 1
    #dX[:-4] = np.zeros(19)

    Xvrai = np.concatenate(
        (mb.get_vecTm_from_Tm(param.T_vol),
         mb.get_vecTm_from_Tm(param.T_ground), np.array([param.h_v]),
         np.array([param.sigma_v]), param.get_gtlist()))

    var1 = np.sum(vec_bcr[:9])
    var2 = np.sum(vec_bcr[9:18])
    #k1 = 0.5*np.sqrt(var1)*(np.random.randn(3,1)+1j*np.random.randn(3,1))
    k1 = 0.5 * 0.1 * (np.random.randn(3, 1) + 1j * np.random.randn(3, 1))
    #k2 = 0.5*np.sqrt(var2)*(np.random.randn(3,1)+1j*np.random.randn(3,1))
    k2 = 0.5 * 0.1 * (np.random.randn(3, 1) + 1j * np.random.randn(3, 1))
    Tvoln = param.T_vol + k1.dot(k1.T.conj())
    Tgroundn = param.T_ground + k2.dot(k2.T.conj())

    X0 = np.concatenate(
        (mb.get_vecTm_from_Tm(Tvoln), mb.get_vecTm_from_Tm(Tgroundn),
         np.array([param.h_v + dX[18]]), np.array([param.sigma_v + dX[19]]),
         0.8 * np.ones(3)))

    #X0 = Xvrai
    data = tom.TomoSARDataSet_synth(param)
    Ups_n = data.get_covar_rect(param, param.N)
    #Ups_n = param.get_upsilon_gt()

    verbose = 1
    #arg[0]: Upsilon bruité
    arg = (Ups_n, param.get_kzlist(), np.cos(param.theta), param.Na, param.N,
           param.z_g, verbose)

    bds = [(0,None) for i in range(3)]+\
          [(None,None) for i in range(6)]+\
          [(0,None) for i in range(3)]+\
          [(None,None) for i in range(6)]+\
          [(0,None)]*2+\
          [(0,1)]*3

    X = opti.minimize(fun=e.mlogV_zg_known,
                      method='SLSQP',
                      x0=X0,
                      options={
                          'xtol': 1e-10,
                          'ftol': 1e-10,
                          'disp': 1,
                          'iprint': 2,
                          'maxiter': 200
                      },
                      bounds=bds,
                      args=arg)

    Crit_vrai = e.mlogV_zg_known(Xvrai, *arg)
    print '|C-Cvrai|={0}'.format(np.abs(X['fun'] - Crit_vrai))
    Xopt = X['x'][0]  #Mdofi Capdessus : X['x'] contient [x,list_x,list_fx]

    vec_Tvol = Xopt[:9]
    Tvol = mb.get_Tm_from_vecTm(vec_Tvol)
    vec_Tground = Xopt[9:18]
    Tground = mb.get_Tm_from_vecTm(vec_Tground)
    hv = Xopt[18]
    sigv = Xopt[19]
    Ngt = mb.get_Nb_from_Na(param.Na)
    if 20 + Ngt != len(Xopt):
        print 'estim_mlogV_zg_known: pb taille Xopt'
    else:
        vec_gt = Xopt[20:20 + Ngt]

    print 'hv={0} hvvrai={1}'.format(hv, param.h_v)
    print 'sigv={0} sigvvvrai={1}'.format(sigv, param.sigma_v)
    print 'gt12={0} gt12vrai={1}'.format(vec_gt[0], param.get_gtlist()[0])
    print 'gt13={0} gt13vrai={1}'.format(vec_gt[1], param.get_gtlist()[1])
    print 'gt23={0} gt23vrai={1}'.format(vec_gt[2], param.get_gtlist()[2])
    print '------ Tvol ------ '
    bl.printm(Tvol)
    print '------ Tvolvrai ------ '
    bl.printm(param.T_vol)
    print '------ Tground ------ '
    bl.printm(Tground)
    print '------ Tgroundvrai ------ '
    bl.printm(param.T_ground)

    #Erreur sur hv,sigv,gt12,gt13,gt23
    vec_err_hv = np.abs(
        np.array([X['x'][1][i][18]
                  for i in range(len(X['x'][1]))]) - param.h_v)  #-param.h_v)
    vec_err_sigv = np.abs(
        np.array([X['x'][1][i][19] for i in range(len(X['x'][1]))]) -
        param.sigma_v)  #-param.sigma_v)
    vec_err_gt12 = np.abs(
        np.array([X['x'][1][i][20] for i in range(len(X['x'][1]))]) -
        param.gammat[0, 1])  #-param.gammat[0,1])
    vec_err_gt13 = np.abs(
        np.array([X['x'][1][i][21] for i in range(len(X['x'][1]))]) -
        param.gammat[0, 2])  #-param.gammat[0,2])
    vec_err_gt23 = np.abs(
        np.array([X['x'][1][i][22] for i in range(len(X['x'][1]))]) -
        param.gammat[1, 2])  #-param.gammat[1,2])
    mat_err1 = np.hstack(
        (vec_err_hv[:, None], vec_err_sigv[:, None], vec_err_gt12[:, None],
         vec_err_gt13[:, None], vec_err_gt23[:, None]))
    name_err1 = ['hv', 'sigv', 'gt12', 'gt13', 'gt23']
    pt.pplot(range(len(vec_err_hv)), mat_err1, names=name_err1, yscale='log')

    #Erreur sur Tvol (1,2,3,4,5,6,7,8,9)
    vec_Tvol = mb.get_vecTm_from_Tm(param.T_vol)
    vec_err_tvol1 = np.abs(
        np.array([X['x'][1][i][0]
                  for i in range(len(X['x'][1]))]) - vec_Tvol[0])
    vec_err_tvol2 = np.abs(
        np.array([X['x'][1][i][1]
                  for i in range(len(X['x'][1]))]) - vec_Tvol[1])
    vec_err_tvol3 = np.abs(
        np.array([X['x'][1][i][2]
                  for i in range(len(X['x'][1]))]) - vec_Tvol[2])
    vec_err_tvol4 = np.abs(
        np.array([X['x'][1][i][3]
                  for i in range(len(X['x'][1]))]) - vec_Tvol[3])
    vec_err_tvol5 = np.abs(
        np.array([X['x'][1][i][4]
                  for i in range(len(X['x'][1]))]) - vec_Tvol[4])
    vec_err_tvol6 = np.abs(
        np.array([X['x'][1][i][5]
                  for i in range(len(X['x'][1]))]) - vec_Tvol[5])
    vec_err_tvol7 = np.abs(
        np.array([X['x'][1][i][6]
                  for i in range(len(X['x'][1]))]) - vec_Tvol[6])
    vec_err_tvol8 = np.abs(
        np.array([X['x'][1][i][7]
                  for i in range(len(X['x'][1]))]) - vec_Tvol[7])
    vec_err_tvol9 = np.abs(
        np.array([X['x'][1][i][8]
                  for i in range(len(X['x'][1]))]) - vec_Tvol[8])

    mat_err2 = np.hstack((
        vec_err_tvol1[:, None],
        vec_err_tvol2[:, None],
        vec_err_tvol3[:, None],
        vec_err_tvol4[:, None],
        vec_err_tvol5[:, None],
        vec_err_tvol6[:, None],
        vec_err_tvol7[:, None],
        vec_err_tvol8[:, None],
        vec_err_tvol9[:, None],
    ))

    name_err2 = [
        'tvol1', 'tvol2', 'tvol3', 'tvol4', 'tvol5', 'tvol6', 'tvol7', 'tvol8',
        'tvol9'
    ]

    pt.pplot(range(len(vec_err_tvol1)),
             mat_err2,
             names=name_err2,
             yscale='log')

    #Erreur sur Tgro (1,2,3,4,5,6,7,8,9)
    vec_Tgro = mb.get_vecTm_from_Tm(param.T_ground)
    vec_err_tgro1 = np.abs(
        np.array([X['x'][1][i][9]
                  for i in range(len(X['x'][1]))]) - vec_Tgro[0])
    vec_err_tgro2 = np.abs(
        np.array([X['x'][1][i][10]
                  for i in range(len(X['x'][1]))]) - vec_Tgro[1])
    vec_err_tgro3 = np.abs(
        np.array([X['x'][1][i][11]
                  for i in range(len(X['x'][1]))]) - vec_Tgro[2])
    vec_err_tgro4 = np.abs(
        np.array([X['x'][1][i][12]
                  for i in range(len(X['x'][1]))]) - vec_Tgro[3])
    vec_err_tgro5 = np.abs(
        np.array([X['x'][1][i][13]
                  for i in range(len(X['x'][1]))]) - vec_Tgro[4])
    vec_err_tgro6 = np.abs(
        np.array([X['x'][1][i][14]
                  for i in range(len(X['x'][1]))]) - vec_Tgro[5])
    vec_err_tgro7 = np.abs(
        np.array([X['x'][1][i][15]
                  for i in range(len(X['x'][1]))]) - vec_Tgro[6])
    vec_err_tgro8 = np.abs(
        np.array([X['x'][1][i][16]
                  for i in range(len(X['x'][1]))]) - vec_Tgro[7])
    vec_err_tgro9 = np.abs(
        np.array([X['x'][1][i][17]
                  for i in range(len(X['x'][1]))]) - vec_Tgro[8])

    mat_err3 = np.hstack((
        vec_err_tgro1[:, None],
        vec_err_tgro2[:, None],
        vec_err_tgro3[:, None],
        vec_err_tgro4[:, None],
        vec_err_tgro5[:, None],
        vec_err_tgro6[:, None],
        vec_err_tgro7[:, None],
        vec_err_tgro8[:, None],
        vec_err_tgro9[:, None],
    ))

    name_err3 = [
        'tgro1', 'tgro2', 'tgro3', 'tgro4', 'tgro5', 'tgro6', 'tgro7', 'tgro8',
        'tgro9'
    ]

    pt.pplot(range(len(vec_err_tgro1)),
             mat_err3,
             names=name_err3,
             yscale='log')

    vec_crit = np.array([X['x'][2][i] for i in range(len(X['x'][2]))])
    pt.plot_converg(vec_crit, crit_vrai=Crit_vrai, mode='diff', show_inf=True)
    pt.plot_converg(vec_crit)
Пример #8
0
from __future__ import print_function

import numpy as np
import sys
import os
import torch
from load_param import load_param

#begin
dataset = 'VOC'
img_dim = 320
num_classes = (21, 81)[dataset == 'COCO']

sys.path.append('../')
from models import ATiny_pelee
net = ATiny_pelee.build_net(img_dim, num_classes)

#load parameter, but needn't do it in fact.
resume_net_path = os.path.join(
    '../weights','Atinypelee','SSD_Atinypelee_VOC_320','20190114','SSD_Atinypelee_VOC_epoches_680.pth')
if not os.path.exists(resume_net_path):
    print('pth file not exit!')
    exit()
load_param(net,resume_net_path)