コード例 #1
0
def save_sino_summaries(gen='g2'):
    """Create and save the sinogram summaries

    Parameters
    ----------
    gen : str
        Must be in ['g1', 'g2'], string to identify which data gen
    """

    # Load the data and metadata
    if gen in ['g1']:

        data = load_pickle(os.path.join(__DATA_DIR, 'g1/g1_fd.pickle'))
        metadata = load_pickle(
            os.path.join(__DATA_DIR, 'g1/g1_metadata.pickle'))

    else:  # If Gen-2

        data = load_pickle(os.path.join(__DATA_DIR, 'g2/g2_fd.pickle'))
        metadata = load_pickle(
            os.path.join(__DATA_DIR, 'g2/g2_metadata.pickle'))

    # Convert to the time-domain
    data = np.abs(to_td(data))
    metadata = np.array(metadata)

    # Get the sinogram summaries (average and stdev signals)
    sino_summaries, sino_md = get_sino_summaries(dataset=data,
                                                 metadata=metadata)

    # Save to .pickle files
    save_pickle(sino_summaries,
                os.path.join(__OUT_DIR, '%s_sino_summaries.pickle' % gen))
    save_pickle(sino_md,
                os.path.join(__OUT_DIR, '%s_sino_summaries_md.pickle' % gen))
コード例 #2
0
def load_sino_summaries(gen='g2'):
    """Loads sinogram summaries from .pickle files

    Parameters
    ----------
    gen : str
        Must be in ['g1', 'g2'], string to identify which data gen

    Returns
    -------
    sino_summaries : array_like
        The average and standard deviation of the signals for each
        sinogram
    sino_md : array_like
        Metadata for the scans from which the average and stdev
        signals were obtained
    """

    summaries = load_pickle(
        os.path.join(__OUT_DIR, '%s_sino_summaries.pickle' % gen))
    metadata = load_pickle(
        os.path.join(__OUT_DIR, '%s_sino_summaries_md.pickle' % gen))

    return summaries, metadata
コード例 #3
0
from umbms import get_proj_path, verify_path
from umbms.loadsave import load_pickle

###############################################################################

__DATA_DIR = os.path.join(get_proj_path(), 'output/roc-figs/')

__OUT_DIR = os.path.join(get_proj_path(), 'output/figs/')
verify_path(__OUT_DIR)

###############################################################################

if __name__ == "__main__":

    # Load ROC data obtained from testing on G1 after training on G1
    cnn_roc = load_pickle(os.path.join(__DATA_DIR, 'cnn_run_8_roc.pickle'))
    dnn_roc = load_pickle(os.path.join(__DATA_DIR, 'dnn_run_15_roc.pickle'))
    logreg_roc = load_pickle(
        os.path.join(__DATA_DIR, 'logreg_run_0_roc.pickle'))

    # Define colours for the figure
    mid_grey = [118, 113, 113]
    mid_grey = [ii / 255 for ii in mid_grey]

    light_grey = [200, 200, 200]
    light_grey = [ii / 255 for ii in light_grey]

    # Make the figure
    plt.figure(figsize=(10, 10))
    plt.rc('font', family='Times New Roman')
    plt.tick_params(labelsize=24)
コード例 #4
0
__DATA_DIR = os.path.join(get_proj_path(), 'data/umbmid/')

###############################################################################

__N_EPOCHS = 496

__N_RUNS = 20

###############################################################################

if __name__ == "__main__":

    logger = get_script_logger(__file__)

    # Load the training data and metadata from Gen-2
    g2_d = load_pickle(os.path.join(__DATA_DIR, 'g2/g2_fd.pickle'))
    g2_md = load_pickle(os.path.join(__DATA_DIR, 'g2/g2_metadata.pickle'))
    g2_md = np.array(g2_md)

    # Convert to the time-domain, crop the signals, take magnitude
    g2_d = np.abs(to_td(g2_d))

    # Get all of the Adipose IDs
    adi_ids = np.array([md['phant_id'].split('F')[0] for md in g2_md])
    unique_adi_ids = np.unique(adi_ids)

    adi_results = dict()  # Init dict for storing results

    # Init lists for storing metadata of samples which are
    # incorrectly / correctly classified
    incor_preds = []
コード例 #5
0
                 '%s' % unique_adi_ids[ii],
                 size=16,
                 color='k',
                 horizontalalignment='center',
                 verticalalignment='center',
                 bbox={
                     'facecolor': 'w',
                     'alpha': 0.9
                 })

    plt.tight_layout()
    plt.show()
    plt.savefig(os.path.join(__OUT_DIR, 'adi_id_fracs.png'),
                dpi=600,
                transparent=False)


###############################################################################

if __name__ == "__main__":

    logger = get_script_logger(__file__)

    # Load metadata lists of correct and incorrect predictions
    cor_preds = load_pickle(os.path.join(__DATA_DIR, 'byadi_cor_preds.pickle'))
    incor_preds = load_pickle(
        os.path.join(__DATA_DIR, 'byadi_incor_preds.pickle'))

    plt_adi_id_distros(wrong_preds=incor_preds,
                       all_preds=np.concatenate((cor_preds, incor_preds)))
コード例 #6
0
    for birads_class in unique_birads:

        # Find fraction of samples with this BI-RADS class
        frac_here = np.sum(birads_classes == birads_class) / n_samples
        logger.info('\t\tClass %d:\t%.2f' % (birads_class, 100 * frac_here))


###############################################################################


if __name__ == "__main__":

    logger = get_script_logger(__file__)

    # Load all Gen-1 frequency-domain data and metadata
    fd_data = load_pickle(os.path.join(__DATA_DIR, 'g1_fd.pickle'))
    metadata = load_pickle(os.path.join(__DATA_DIR, 'g1_metadata.pickle'))

    # Init vars for train/test fractions
    tr_frac = 0
    te_frac = 0

    # Until the train tumor fraction is approx 50%
    while not (0.45 <= tr_frac <= 0.55):

        # Shuffle the arrays
        [fd_data, metadata] = shuffle_arrs([fd_data, metadata])

        # Split data/metadata into train and test sets
        tr_data = fd_data[:125, :, :]
        tr_md = metadata[:125]
コード例 #7
0
        out_path = os.path.join(get_proj_path(), 'output/roc-figs/')

        plt.savefig(os.path.join(out_path, '%s.png' % save_str), dpi=150)
        plt.close()
        save_pickle(np.array([fprs, tprs]),
                    os.path.join(out_path, '%s.pickle' % save_str))


###############################################################################

if __name__ == "__main__":

    logger = get_script_logger(__file__)

    # Load the training data and metadata from Gen-2
    g2_d = load_pickle(os.path.join(__DATA_DIR, 'g2/g2_fd.pickle'))
    g2_md = load_pickle(os.path.join(__DATA_DIR, 'g2/g2_metadata.pickle'))

    # Load the training data and metadata from Gen-1
    g1_d = load_pickle(os.path.join(__DATA_DIR,
                                    'g1-train-test/test_fd.pickle'))
    g1_md = load_pickle(
        os.path.join(__DATA_DIR, 'g1-train-test/test_md.pickle'))

    # Convert data to time domain, take magnitude, apply window
    g1_d = correct_g1_ini_ant_ang(g1_d)
    g1_d = np.abs(to_td(g1_d))
    g2_d = np.abs(to_td(g2_d))

    # Perform data augmentation
    g2_d, g2_md = full_aug(g2_d, g2_md)
コード例 #8
0
from umbms.plot.sinogramplot import plot_sino
from umbms.ai.preproc import to_td

###############################################################################

__DATA_DIR = os.path.join(get_proj_path(), 'data/umbmid/g2/')

__FIG_OUT_DIR = os.path.join(get_proj_path(), 'output/figs/')
verify_path(__FIG_OUT_DIR)

###############################################################################

if __name__ == "__main__":

    # Load phantom dataset (UM-BMID Gen1)
    phant_data = load_pickle(os.path.join(__DATA_DIR, 'g2_fd.pickle'))

    # Convert dataset to the time-domain
    sinograms = to_td(phant_data)

    # Take sample sinogram
    sinogram = sinograms[201, :, :]

    # Define scan times
    scan_ts = np.linspace(0.5e-9, 5.5e-9, 35)

    plot_sino(td_data=sinogram,
              ini_t=scan_ts[0],
              fin_t=scan_ts[-1],
              save_fig=True,
              save_str=os.path.join(__FIG_OUT_DIR, 'sino_example'),