def compute_mean_std(files, batch_size=128):
    """Load images in files in batches and compute mean."""
    m = np.zeros((3,256,256))
    s2 = np.zeros((3,256,256))
    for i in range(0, len(files), batch_size):
        print("done with {:>3} / {} images".format(i, len(files)))
        try:
            images = np.array([imageData.load_augment(f,256,256) for f in files[i : i + batch_size]])
        except:
            print (i)
            raise
        m += images.sum(axis=(0 ))
        s2 += np.power(images, 2).sum(axis=(0))
    shape = s2.shape
    m = m / len(files)
    m = np.mean(m,axis=(1,2))
    n = len(files) * shape[1] * shape[2]
    var = (s2/(n-1)).sum(axis=(1,2)) - (((m**2.0)*n) / (n - 1))
    return m,np.sqrt(var)
예제 #2
0
def main(filelist):
    filenames = imageData.get_files(filelist) 

    bs = 1000
    batches = [filenames[i * bs : (i + 1) * bs] 
               for i in range(int(len(filenames) / bs) + 1)]

    Us, evs = [], []
    for batch in batches:
        images = np.array([imageData.load_augment(f, 256, 256) for f in batch])
        X = images.transpose(0, 2, 3, 1).reshape(-1, 3)
        cov = np.dot(X.T, X) / X.shape[0]
        U, S, V = np.linalg.svd(cov)
        ev = np.sqrt(S)
        Us.append(U)
        evs.append(ev)
    print('U')
    print(np.mean(Us, axis=0))
    print('eigenvalues')
    print(np.mean(evs, axis=0))
def load_shared(args):
    i, array_name, fname, kwargs = args
    array = SharedArray.attach(array_name)
    array[i] = imageData.load_augment(fname, **kwargs)