예제 #1
0
파일: net_attr.py 프로젝트: Cysu/dlearn
        input=layers[-1].output,
        input_shape=layers[-1].output_shape,
        output_shape=11,
        dropout_input=layers[-1].dropout_output,
        active_func=actfuncs.sigmoid
    ))

    model = NeuralNet(layers, [X, S], layers[-1].output)
    model.target = A
    model.cost = costfuncs.binxent(layers[-1].dropout_output, A) + \
        1e-3 * model.get_norm(2)
    model.error = costfuncs.binerr(layers[-1].output, A)

    sgd.train(model, dataset, lr=1e-2, momentum=0.9,
              batch_size=100, n_epochs=300,
              epoch_waiting=10)

    return model


if __name__ == '__main__':
    dataset_file = 'data_{0}.pkl'.format(args.dataset[0])
    out_file = 'model_attr.pkl' if args.output is None else \
               'model_attr_{0}.pkl'.format(args.output)

    dataset = load_data(dataset_file)

    model = train_model(dataset, not args.no_scpool)

    save_data(model, out_file)
예제 #2
0
import argparse
import numpy as np
import theano

homepath = os.path.join('..', '..')

if not homepath in sys.path:
    sys.path.insert(0, homepath)

from dlearn.visualization import show_channels
from dlearn.utils.serialize import load_data

from scipy.io import loadmat

W = loadmat('first_layer_filter.mat')['W']
M = load_data('mean.pkl')

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
from skimage.color import lab2rgb

fig = plt.figure()
grid = AxesGrid(fig, 111,
                nrows_ncols=(4, 8),
                axes_pad=0.0,
                share_all=True)

for r in xrange(4):
    for c in xrange(8):
        ind = r * 8 + c
        I = W[ind]
예제 #3
0
파일: visualize.py 프로젝트: Cysu/dlearn
    )

    X = subset.input

    output_shape = (1, 37, 17)

    y = f(X.cpu_data[0:100])

    if not gt:
        for i in xrange(100):
            print 'Saving figure {0}'.format(i)
            v = y[i].reshape(output_shape)
            show_channels(v, n_cols=1,
                          ofpath=os.path.join(folder, '{:04d}.png'.format(i)))
    else:
        S = subset.target
        for i in xrange(100):
            print 'Saving figure {0}'.format(i)
            v = np.vstack((y[i].reshape(output_shape), S.cpu_data[i:i + 1]))
            show_channels(v, n_cols=2,
                          ofpath=os.path.join(folder, '{:04d}.png'.format(i)))


if __name__ == '__main__':
    dataset_file = 'data_{0}.pkl'.format(args.dataset[0])
    seg_file = 'model_{0}.pkl'.format(args.segmentation[0])

    dataset = load_data(dataset_file)
    model = load_data(seg_file)
    visualize(model, dataset.test, args.output[0], args.ground_truth)
예제 #4
0
파일: net_seg.py 프로젝트: Cysu/dlearn
    model.cost = costfuncs.binxent(layers[-1].dropout_output, S.flatten(2)) + \
        1e-3 * model.get_norm(2)
    model.error = costfuncs.binerr(layers[-1].output, S.flatten(2))
    '''

    model.cost = costfuncs.weighted_norm2(
        layers[-1].dropout_output, S.flatten(2), 1.0) + \
        1e-3 * model.get_norm(2)
    model.error = costfuncs.weighted_norm2(
        layers[-1].output, S.flatten(2), 1.0)

    sgd.train(model, dataset, lr=1e-2, momentum=0.9,
              batch_size=100, n_epochs=300,
              epoch_waiting=10)

    return model


if __name__ == '__main__':
    dataset_file = 'data_{0}.pkl'.format(args.dataset[0])
    attr_file = 'model_{0}.pkl'.format(args.attribute[0])
    out_file = 'model_seg.pkl' if args.output is None else \
               'model_seg_{0}.pkl'.format(args.output)

    dataset = load_data(dataset_file)
    attr_model = load_data(attr_file)

    model = train_model(dataset, attr_model)

    save_data(model, out_file)
예제 #5
0
파일: evaluate.py 프로젝트: Cysu/dlearn
    n_cols = 4
    n_rows = len(ret) // n_cols + 1

    for j, (auc, fpr, tpr, thresh) in enumerate(ret):
        # Plot stats
        plt.subplot(n_rows, n_cols, j)
        plt.plot(fpr, tpr)
        plt.title('AUC = {:.2f}%'.format(auc * 100))

    plt.show()


if __name__ == '__main__':
    dataset_file = 'data_{0}.pkl'.format(args.dataset[0])
    model_file = 'model_{0}.pkl'.format(args.model[0])
    out_file = 'stats.pkl' if args.output is None else \
               'stats_{0}.pkl'.format(args.output)

    if not args.display_only:
        dataset = load_data(dataset_file)
        model = load_data(model_file)

        output = compute_output(model, dataset.test)
        ret = compute_stats(output, dataset.test.target.cpu_data)

        save_data(ret, out_file)

    ret = load_data(out_file)
    show_stats(ret)
예제 #6
0
파일: produce_seg.py 프로젝트: Cysu/dlearn
    f = theano.function(
        inputs=[model.input],
        outputs=model.blocks[3].output
    )

    m = data.shape[0]
    output = [0] * m

    for i in xrange(m):
        S = f(data[i:i + 1]).reshape([37, 17])
        output[i] = imgproc.resize(S, [160, 80])

    return np.asarray(output)


def save_segmentation(images, output, fpath):
    savemat(fpath, {'images': images, 'segmentations': output})


if __name__ == '__main__':
    seg_file = 'model_{0}.pkl'.format(args.segmentation[0])
    out_file = '{0}.mat'.format(args.output[0])

    data = load_rawdata(args.dataset)
    images, data = proc_rawdata(data)
    model = load_data(seg_file)

    output = produce_segmentation(data, model)

    save_segmentation(images, output, out_file)