Example #1
0
def main():

    trainX = get_salt_images(folder='mytrain')
    train_pix_num = sd.salt_pixel_num(folder='mytrain')
    trainY = np.array(train_pix_num > 0).astype(int)

    valX = get_salt_images(folder='myval')
    val_pix_num = sd.salt_pixel_num(folder='myval')
    valY = np.array(val_pix_num > 0).astype(int)
    # Build the Estimator
    model_dir = '/scratch0/ilya/locDoc/data/kaggle-seismic-dataset/models/binaryhalf1'
    model = tf.estimator.Estimator(model_fn, model_dir=model_dir)

    for i in range(100000):
        # Define the input function for training
        input_fn = tf.estimator.inputs.numpy_input_fn(
            x={'images': trainX[:3584,:,:,:]}, y=trainY[:3584],
            batch_size=batch_size, num_epochs=1, shuffle=True)
        # Train the Model
        tf.logging.set_verbosity(tf.logging.INFO)
        model.train(input_fn, steps=None)

        # if i % 2 == 0:
        # Evaluate the Model
        # Define the input function for evaluating
        input_fn = tf.estimator.inputs.numpy_input_fn(
            x={'images': valX[:384,:,:,:]}, y=valY[:384],
            batch_size=batch_size, shuffle=False)
        # Use the Estimator 'evaluate' method
        e = model.evaluate(input_fn)

        print("Testing Accuracy:", e['accuracy'])
Example #2
0
def view_mistakes():
    foldername = 'myval'
    id_to_pred = get_decisions(
        foldername,
        '/scratch0/ilya/locDoc/data/kaggle-seismic-dataset/models/binary13b')
    fileids = sb.clean_glob(
        glob.glob(
            '/scratch0/ilya/locDoc/data/kaggle-seismic-dataset/%s/images/*.png'
            % foldername))

    # imgs = sd.get_salt_labels(folder='myval')
    # imgs = np.reshape(imgs, (imgs.shape[0], 101,101))
    imgs = sd.get_salt_images(folder='myval')
    val_pix_num = sd.salt_pixel_num(folder='myval')
    valY = np.array(val_pix_num > 0).astype(int)

    mistake_i = 0
    for file_id_i, file_id in enumerate(fileids):
        fileid, file_extension = os.path.splitext(file_id)
        if valY[file_id_i] != id_to_pred[fileid]:
            imgs[mistake_i, :, :] = imgs[file_id_i, :, :]
            mistake_i += 1

    print('made %i mistakes' % mistake_i)
    X = np.swapaxes(np.swapaxes(imgs[:mistake_i, :, :], 0, 2), 0,
                    1).astype(float)
    fig, ax = plt.subplots(1, 1)
    tracker = ScrollThruPlot(ax, X, fig)
    fig.canvas.mpl_connect('scroll_event', tracker.onscroll)
    plt.show()