示例#1
0
def get_images(model,
               sample,
               return_raw_data=False,
               calc_chi2=False,
               gen_more=None,
               batch_size=128):
    X, Y = sample
    assert X.ndim == 2
    assert X.shape[1] == 4

    if gen_more is None:
        gen_features = X
    else:
        gen_features = np.tile(X, [gen_more] + [1] * (X.ndim - 1))
    gen_scaled = np.concatenate(
        [
            model.make_fake(gen_features[i:i + batch_size]).numpy()
            for i in range(0, len(gen_features), batch_size)
        ],
        axis=0,
    )
    real = model.scaler.unscale(Y)
    gen = model.scaler.unscale(gen_scaled)
    gen[gen < 0] = 0
    gen1 = np.where(gen < 1.0, 0, gen)

    features = {
        'crossing_angle': (X[:, 0], gen_features[:, 0]),
        'dip_angle': (X[:, 1], gen_features[:, 1]),
        'drift_length': (X[:, 2], gen_features[:, 2]),
        'time_bin_fraction': (X[:, 2] % 1, gen_features[:, 2] % 1),
        'pad_coord_fraction': (X[:, 3] % 1, gen_features[:, 3] % 1),
    }

    images = make_metric_plots(real,
                               gen,
                               features=features,
                               calc_chi2=calc_chi2)
    if calc_chi2:
        images, chi2 = images

    images1 = make_metric_plots(real, gen1, features=features)

    img_amplitude = make_histograms(Y.flatten(),
                                    gen_scaled.flatten(),
                                    'log10(amplitude + 1)',
                                    logy=True)

    result = [images, images1, img_amplitude]

    if return_raw_data:
        result += [(gen_features, gen)]

    if calc_chi2:
        result += [chi2]

    return result
示例#2
0
    def get_images(return_raw_data=False,
                   calc_chi2=False,
                   gen_more=None,
                   sample=(X_test, Y_test),
                   batch_size=128):
        X, Y = sample
        if gen_more is None:
            gen_features = X
        else:
            gen_features = np.tile(X, [gen_more] + [1] * (X.ndim - 1))
        gen_scaled = np.concatenate(
            [
                model.make_fake(gen_features[i:i + batch_size]).numpy()
                for i in range(0, len(gen_features), batch_size)
            ],
            axis=0,
        )
        real = unscale(Y)
        gen = unscale(gen_scaled)
        gen[gen < 0] = 0
        gen1 = np.where(gen < 1.0, 0, gen)
        images = make_metric_plots(real,
                                   gen,
                                   features={'angle': (X, gen_features)},
                                   calc_chi2=calc_chi2)
        if calc_chi2:
            images, chi2 = images

        images1 = make_metric_plots(real,
                                    gen1,
                                    features={'angle': (X, gen_features)})

        img_amplitude = make_histograms(Y_test.flatten(),
                                        gen_scaled.flatten(),
                                        'log10(amplitude + 1)',
                                        logy=True)

        result = [images, images1, img_amplitude]

        if return_raw_data:
            result += [(gen_features, gen)]

        if calc_chi2:
            result += [chi2]

        return result
def write_hist_summary(step):
    if step % 50 == 0:
        gen_scaled = baseline_10x10_normed.make_fake(len(X_test)).numpy()
        real = unscale(X_test)
        gen = unscale(gen_scaled)
        gen[gen < 0] = 0
        images = make_metric_plots(real, gen)

        with writer_val.as_default():
            for k, img in images.items():
                tf.summary.image(k, img, step)
    def write_hist_summary(step):
        if step % args.save_every == 0:
            gen_scaled = model.make_fake(len(X_test)).numpy()
            real = unscale(X_test)
            gen = unscale(gen_scaled)
            gen[gen < 0] = 0
            gen1 = np.where(gen < 1.0, 0, gen)
            images = make_metric_plots(real, gen)
            images1 = make_metric_plots(real, gen1)

            img_amplitude = make_histograms(X_test.flatten(),
                                            gen_scaled.flatten(),
                                            'log10(amplitude + 1)',
                                            logy=True)

            with writer_val.as_default():
                for k, img in images.items():
                    tf.summary.image(k, img, step)
                for k, img in images1.items():
                    tf.summary.image("{} (amp > 1)".format(k), img, step)
                tf.summary.image("log10(amplitude + 1)", img_amplitude, step)
def write_hist_summary(step):
    if step % 50 == 0:
        gen_scaled = baseline_10x15.make_fake(len(X_test)).numpy()
        real = unscale(X_test)
        gen = unscale(gen_scaled)
        gen[gen < 0] = 0
        gen30 = np.where(gen < 30.0, 0, gen)
        images = make_metric_plots(real, gen)
        images30 = make_metric_plots(real, gen30)

        img_amplitude = make_histograms(X_test.flatten(),
                                        gen_scaled.flatten(),
                                        'log10(amplitude + 1)',
                                        logy=True)

        with writer_val.as_default():
            for k, img in images.items():
                tf.summary.image(k, img, step)
            for k, img in images30.items():
                tf.summary.image("{} (amp > 30)".format(k), img, step)
            tf.summary.image("log10(amplitude + 1)", img_amplitude, step)
示例#6
0
                                     judge.pearson_corr,
                                     judge.coeff_of_determination]],
                              columns=['r', 'th',
                                       'precision', 'recall', 'fscore', 'MAHD',
                                       'MAPE', 'ME', 'MPE', 'MAE',
                                       'MSE', 'RMSE', 'r', 'R2'],
                              index=[j])
            df.index.name = 'idx'
            df_metrics = df_metrics.append(df)

        # Write CSV of metrics to disk
        df_metrics.to_csv(os.path.join(args.out, 'metrics.csv'))

        # Generate plots
        figs = make_metric_plots(csv_path=os.path.join(args.out, 'metrics.csv'),
                                 taus=args.taus,
                                 radii=args.radii)
        for label, fig in figs.items():
            # Save to disk
            fig.savefig(os.path.join(args.out,
                                     'intermediate',
                                     'metrics_plots',
                                     f'{label}.png'))


# Save plot figures of the statistics of the BMM-based threshold
if -2 in args.taus:
    for label, fig in bmm_tracker.plot().items():
        fig.savefig(os.path.join(args.out,
                                 'intermediate',
                                 'metrics_plots',
parser.add_argument('--radii',
                    type=str,
                    required=True,
                    help='List of values, each with different colors in the scatter plot. '
                         'Maximum distance to consider a True Positive. '
                         'The closest to this value will be used.')
args = parser.parse_args()


os.makedirs(args.out, exist_ok=True)

taus = [float(tau) for tau in args.taus.replace('[', '').replace(']', '').split(',')]
radii = [int(r) for r in args.radii.replace('[', '').replace(']', '').split(',')]

figs = metrics.make_metric_plots(csv_path=args.csv,
                                 taus=taus,
                                 radii=radii,
                                 title=args.title)

for label, fig in figs.items():
    # Save to disk
    fig.savefig(os.path.join(args.out, f'{label}.png'))


"""
Copyright &copyright © (c) 2019 The Board of Trustees of Purdue University and the Purdue Research Foundation.
All rights reserved.

This software is covered by US patents and copyright.
This source code is to be used for academic research purposes only, and no commercial use is allowed.

For any questions, please contact Edward J. Delp ([email protected]) at Purdue University.