Esempio n. 1
0
def add_padding(num, size, t):
    name = '{}-images.idx3-ubyte'
    msb = 2051
    x = get_samples(num, name.format(t))
    x = x.reshape((num, 28, 28))
    px = np.zeros((num, size, size), dtype=np.uint8)
    px[:, 2:30, 2:30] = x
    px = px.reshape(num, size**2)
    filename = name.format(t+str(size))
    with open(filename, mode='xb') as f:
        f.write(pack('>IIII', msb, num, size, size))
        for i in range(num):
            f.write(pack('B'*size**2, *px[i, :]))
Esempio n. 2
0
def distortion(num, size=28):
    msb = 2051
    name = '{}-images.idx3-ubyte'
    t = 'train'
    if size != 28:
        t = t + str(size)
    filename = name.format(t)
    x = get_samples(num, filename)
    x = x.reshape((num, size, size))
    with open(filename, mode='xb') as f:
        f.write(pack('>IIII', msb, num, size, size))
        for i in range(num):
            d = np.array(np.floor(elastic_distortion(x[i])), dtype=np.uint8)
            f.write(pack('B'*size**2, *d.flatten()))