コード例 #1
0
def get_formatted_data(file_path):
    unformatted_tr_data = load_data.load_training_data(file_path)
    unformatted_tr_labels = load_data.load_training_labels(file_path)
    unformatted_te_data = load_data.load_testing_data(file_path)
    unformatted_te_labels = load_data.load_testing_labels(file_path)

    formatted_tr_data = unformatted_tr_data
    formatted_te_data = unformatted_te_data

    formatted_tr_labels = [[], []]
    for l in unformatted_tr_labels:
        formatted_tr_labels[0].append([l[0]])
        formatted_tr_labels[1].append([1, 0] if bool(l[1]) else [0, 1])
    formatted_tr_labels = [np.array(dat) for dat in formatted_tr_labels]

    formatted_te_labels = [[], []]
    for l in unformatted_te_labels:
        formatted_te_labels[0].append([l[0]])
        formatted_te_labels[1].append([1, 0] if bool(l[1]) else [0, 1])
    formatted_te_labels = [np.array(dat) for dat in formatted_te_labels]

    print(formatted_tr_labels)

    return (((formatted_tr_data, formatted_tr_labels), (formatted_te_data,
                                                        formatted_te_labels)))
コード例 #2
0
def get_formatted_data(file_path):
    tr_d = format_data_segment(load_data.load_training_data(file_path))
    tr_l = format_label_segment(load_data.load_training_labels(file_path))

    te_d = format_data_segment(load_data.load_testing_data(file_path))
    te_l = format_label_segment(load_data.load_testing_labels(file_path))

    return (((tr_d, tr_l), (te_d, te_l)))
コード例 #3
0
ファイル: classify_data.py プロジェクト: breandan/comp551-p3
if len(sys.argv) < 2:
    model_path = 'data/temp_model.hdf5'
else:
    model_path = sys.argv[1]

if len(sys.argv) < 3:
    output_path = 'data/test_y.csv'
else:
    output_path = sys.argv[2]

print("Loading model from " + model_path + "...")
model = load_model(model_path)

print("Loading test data...")
x_test = load_testing_data()
x_test = x_test.reshape(-1, 64, 64)

print("Removing background...")
x_test = threshold(x_test)

print("Removing dots...")
#x_test = remove_dots(x_test)

#new_im = np.zeros((256, 256))
#r = 0
#for i in range(0, 256,64):
#    for j in range(0, 256, 64):
#        # paste the image at location i,j
#        new_im[i:i+64, j:j+64] = x_test[r]
#        r += 1
コード例 #4
0
def evaluate_dual_output_form(net_name,
                              temp_name,
                              format_name,
                              show=True,
                              screen_name=None):
    """Evaluates the performance of a network with two outputs.
    
    This function expects the network to have two outputs. The first should be
    the predicted SNR while the second is a representation of a boolean value
    that indicates whether there is a GW in the data or not. This boolean value
    should be an array with two entries (p, 1-p), where p is the "probabilty"
    of a GW being present. Thus the structure of a single output needs to be:
    [SNR, [p, 1-p]]
    This function also creates a few plots.
    
    Arguments
    ---------
    net_name : str
        The name of the networks '.hf5' file (file extension NOT included).
    
    temp_name : str
        The name of the datas '.hf5' file (file extension NOT included).
    
    Returns
    -------
    list
        A list with five values. The first entry represents how many signals
        the network correctly predicted to have a GW in them. The second
        represents how many signals the network correctly predicted to have no
        GW in them. The third how many it falsly predicted to have no GW in the
        data, the fourth how many it falsly predicted to have a GW in the data,
        the fifth represents the number of samples where the network had a bias
        of less then 60% towards one or the other output. (i.e. the output for
        the bool value was something like [0.55, 0.45])
    """
    saves_path = get_store_path()
    net_path = os.path.join(saves_path, net_name + '.hf5')
    temp_path = os.path.join(saves_path, temp_name + '.hf5')
    format_path = os.path.join(saves_path, format_name + '.py')

    net = keras.models.load_model(net_path)

    d_form = imp.load_source('d_form', format_path)

    te_d = d_form.format_data_segment(load_testing_data(temp_path))
    te_l = d_form.format_label_segment(load_testing_labels(temp_path))
    te_c = load_testing_calculated_snr(temp_path)

    res = net.predict(te_d, verbose=1)

    predicted_snr = [pt[0] for pt in res[0]]

    predicted_bool = [pt[0] > pt[1] for pt in res[1]]

    l = [0, 0, 0, 0, 0]

    #print('Len predicted bool: {}'.format(len(predicted_bool)))
    #print('Len res: {}'.format(len(res)))

    for i in range(len(predicted_bool)):
        if predicted_bool[i] == bool(te_l[1][i][0]):
            #Correctly predicted
            if predicted_bool[i]:
                #GW is in the signal
                l[0] += 1
            else:
                #GW is not in the signal
                l[1] += 1
        else:
            #Falsly predicted
            if predicted_bool[i]:
                #Network predicts signal but there is none in the data
                l[3] += 1
            else:
                #Network predicts no signal but there is one in the data
                l[2] += 1

        if abs(res[1][i][0] - 0.5) < 0.1:
            l[4] += 1

    plot_path = os.path.join(saves_path, net_name + '_removed_negatives.png')

    #Do the necessary plots
    x_pt_1 = [pt[0] for i, pt in enumerate(te_l[0]) if predicted_bool[i]]
    x_pt_2 = [pt for i, pt in enumerate(te_c) if predicted_bool[i]]
    y_pt = [pt[0] for i, pt in enumerate(res[0]) if predicted_bool[i]]

    #print(x_pt_1)
    #print(x_pt_2)
    #print(y_pt)

    _do_plot(net_name if screen_name == None else str(screen_name),
             np.array(x_pt_1),
             np.array(x_pt_2),
             np.array(y_pt),
             plot_path,
             show=show)

    return (l)
コード例 #5
0
ファイル: infer.py プロジェクト: puneesh00/deep_isp
os.mkdir(os.path.join(current_path, res_folder))

in_shape = (224, 224, 4)

base_vgg = VGG16(weights='imagenet',
                 include_top=False,
                 input_shape=(448, 448, 3))
vgg = Model(inputs=base_vgg.input,
            outputs=base_vgg.get_layer('block4_pool').output)
for layer in vgg.layers:
    layer.trainable = False

d_model = network(vgg, inp_shape=in_shape, trainable=False)

if eval_mode:
    raw_imgs, canon_imgs = load_testing_data(dataset_dir, 224, 224, 2)

    f = open(os.path.join(current_path, exp_folder, metrics_file + '.txt'),
             'x')
    f = open(os.path.join(current_path, exp_folder, metrics_file + '.txt'),
             'a')

    for i in range(n_epochs):
        filename = os.path.join(current_path, exp_folder,
                                weights_file + '_%04d.h5' % (i + 1))
        d_model.load_weights(filename)
        out, _, _, _, _ = d_model.predict(raw_imgs)
        psnr, ssim = metrics(canon_imgs, out, 1.0)
        f.write('%.1f psnr = %.5f, ssim = %.7f' % (i + 1, psnr, ssim))
        f.write('\n')
        print(psnr, ssim)