Example #1
0
def load_dataset():
    from scipy.io import loadmat
    from dlearn.data.dataset import Dataset

    matdata = loadmat(os.path.join('..', '..', 'data', 'human_sar', 'CUHK_SAR.mat'))
    m, n = matdata['images'].shape
    S = [choose_seg(matdata['segmentations'][i, 0], 'Upper')
         for i in xrange(m)]
    S = np.asarray(S)

    matdata = loadmat('XY_CUHK_SAR.mat')
    X = matdata['X'].T.astype('float32')
    X = X / 100.0
    X = X - X.mean(axis=0)

    dataset = Dataset(X, S)
    dataset.split(0.7, 0.2)

    return dataset
Example #2
0
def create_dataset(rawdata):
    from dlearn.data.dataset import Dataset
    from dlearn.utils import imgproc

    def imgprep(img):
        img = imgproc.resize(img, [160, 80], keep_ratio='height')
        img = imgproc.subtract_luminance(img)
        img = np.rollaxis(img, 2)
        return (img / 100.0).astype(np.float32)

    def choose_attr_uni(attr, title):
        ind = conf.attr_uni_titles.index(title)
        vals = conf.attr_uni[ind]
        ind = [conf.attr_names.index(v) for v in vals]
        return np.where(attr[ind] == 1)[0][0]

    def choose_attr_mul(attr, title):
        ind = conf.attr_mul_titles.index(title)
        vals = conf.attr_mul[ind]
        ind = [conf.attr_names.index(v) for v in vals]
        return attr[ind].astype(np.float32)

    m = len(rawdata)
    X = [0] * m
    A = [0] * m

    i = 0
    for (img, attr) in rawdata:
        X[i] = imgprep(img)
        A[i] = choose_attr_mul(attr, 'Upper Body Colors')
        i += 1

    X = np.asarray(X)
    A = np.asarray(A)

    X = X - X.mean(axis=0)

    dataset = Dataset(X, A)
    dataset.split(0.7, 0.2)

    return dataset
Example #3
0
def create_dataset(rawdata):
    from dlearn.data.dataset import Dataset
    from dlearn.utils import imgproc

    def imgprep(img):
        if img.shape != (160, 80):
            img = imgproc.resize(img, [160, 80], keep_ratio='height')
        img = imgproc.subtract_luminance(img)
        img = np.rollaxis(img, 2)
        return (img / 100.0).astype(np.float32)

    def choose_attr_uni(attr, title):
        ind = conf.attr_uni_titles.index(title)
        vals = conf.attr_uni[ind]
        ind = [conf.attr_names.index(v) for v in vals]
        return np.where(attr[ind] == 1)[0][0]

    def choose_attr_mul(attr, title):
        ind = conf.attr_mul_titles.index(title)
        vals = conf.attr_mul[ind]
        ind = [conf.attr_names.index(v) for v in vals]
        return attr[ind].astype(np.float32)

    def choose_seg(seg, title):
        val = conf.seg_pix[title]
        img = (seg == val).astype(np.float32)
        img = imgproc.resize(img, [37, 17])
        return img.astype(np.float32)

    m = len(rawdata)
    X = [0] * (2 * m)
    A = [0] * (2 * m)
    S = [0] * (2 * m)

    i = 0
    for (img, attr, seg) in rawdata:
        X[i] = imgprep(img)
        A[i] = choose_attr_mul(attr, 'Upper Body Colors')
        S[i] = choose_seg(seg, 'Upper')
        # S[i] = (seg >= 0.5).astype(np.float32)
        # S[i] = imgproc.resize(S[i], [37, 17]).astype(np.float32)

        # Mirror
        X[i + 1] = X[i][:, :, ::-1].copy()
        A[i + 1] = A[i].copy()
        S[i + 1] = S[i][:, ::-1].copy()

        i += 2

    X = np.asarray(X)
    A = np.asarray(A)
    S = np.asarray(S)

    X = X - X.mean(axis=0)

    def parse_list(arglist):
        d = {'X': X, 'A': A, 'S': S}
        l = map(lambda x: d[x], arglist)
        return l[0] if len(l) == 1 else l

    dataset = Dataset(parse_list(args.input), parse_list(args.target))
    dataset.split(0.7, 0.2)

    return dataset