Example #1
0
def generate_for_f_and_p(f, p, output):
    print f, p
    batch_is = numpy.zeros((m.k, m.d), dtype=theano.config.floatX)
    batch_js = numpy.zeros((m.k, ), dtype=numpy.int32)
    for z in xrange(m.k):
        batch_is[z] = a * (1 - p) + b * p
        batch_js[z] = z

    img = model.draw_grid(run_fn(input_i, input_j))
    path = output + '.png'
    img.save(path)
Example #2
0
def run_game():
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode((settings.game_width, settings.game_height))
    pygame.display.set_caption("Snakes")

    screen.fill(settings.bg_color)
    model.draw_grid(screen, settings)
    model.new_food(screen, settings)

    while True:
        keypress.keycheck(screen, settings)

        if settings.game_over:
            model.game_over(screen, settings)
            if settings.play_again:
                break
        else:
            model.update(screen, settings)
            model.collisions_check(screen, settings)

        pygame.display.flip()

    return settings.play_again
Example #3
0
def generate():

    print 'generating...'
    frame = 0
    with open('data.csv', 'w') as csvfile:
        fieldnames = ['path', 'f', 'p']
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

        writer.writeheader()
        for input_i, input_j, f2, p in generate_input(100):
            img = model.draw_grid(run_fn(input_i, input_j))
            path = 'font_' + str(frame) + '.png'
            img.save(path)
            writer.writerow({'path': path, 'f': f2, 'p': p})
            frame += 1
Example #4
0
import numpy
import model
avg = numpy.mean(model.get_data()[:], axis=0)
model.draw_grid(avg / 255.).save('avg.png')
Example #5
0
import random
import numpy
import model

data = model.get_data()
n = data.shape[0]
alphabet = numpy.zeros((62, 64, 64))
for z in xrange(62):
    alphabet[z] = random.choice(data)[z] * 1.0/255

model.draw_grid(alphabet).save('alphabet.png')
Example #6
0
import random
import numpy
import random
import model

data = model.get_data()
n, k = data.shape[0], data.shape[1]

m = model.Model(n, k)
m.try_load()
run_fn = m.get_run_fn()

train_set, test_set = m.sets()
chars = {}
for i, j in test_set:
    chars.setdefault(j, []).append(i)

batch_is = numpy.zeros((k,), dtype=numpy.int32)
batch_js = numpy.zeros((k,), dtype=numpy.int32)
for z in xrange(k):
    batch_is[z] = random.choice(chars[z])  # random.randint(0, n-1)
    batch_js[z] = z

batch_pred = run_fn(batch_is, batch_js)
combined = numpy.zeros((2 * k, 64 * 64))
for z in xrange(k):
    combined[2 * z] = data[batch_is[z]][z].flatten() * 1.0 / 255
    combined[2 * z + 1] = batch_pred[z]

model.draw_grid(combined).save("real_vs_pred.png")
Example #7
0
import random
import numpy
import theano
import model

m = model.Model(artificial_font=True)
m.try_load()
run_fn = m.get_run_fn()
W = m.get_font_embeddings()

a, b, c, d = [random.choice(W) for z in xrange(4)]
grid = 10

batch_is = numpy.zeros((grid*grid, m.d), dtype=theano.config.floatX)
batch_js = numpy.zeros((grid*grid,), dtype=numpy.int32)
for x in xrange(grid):
    for y in xrange(grid):
        z = y * grid + x
        p, q = 1.0 * x / (grid-1), 1.0 * y / (grid-1)
        batch_is[z] = p * q * a + (1 - p) * q * b + p * (1 - q) * c + (1 - p) * (1 - q) * d
        batch_js[z] = 26 # lowercase a

pred = run_fn(batch_is, batch_js)
model.draw_grid(pred, grid).save('grid.png')
Example #8
0
import random
import numpy
import random
import model

data = model.get_data()
n, k = data.shape[0], data.shape[1]

m = model.Model(n, k)
m.try_load()
run_fn = m.get_run_fn()

train_set, test_set = m.sets()
chars = {}
for i, j in test_set:
    chars.setdefault(j, []).append(i)

batch_is = numpy.zeros((k, ), dtype=numpy.int32)
batch_js = numpy.zeros((k, ), dtype=numpy.int32)
for z in xrange(k):
    batch_is[z] = random.choice(chars[z])  # random.randint(0, n-1)
    batch_js[z] = z

batch_pred = run_fn(batch_is, batch_js)
combined = numpy.zeros((2 * k, 64 * 64))
for z in xrange(k):
    combined[2 * z] = data[batch_is[z]][z].flatten() * 1.0 / 255
    combined[2 * z + 1] = batch_pred[z]

model.draw_grid(combined).save('real_vs_pred.png')
Example #9
0
m = model.Model(artificial_font=True)
m.try_load()
run_fn = m.get_run_fn()
W = m.get_font_embeddings()
cov = numpy.cov(W.T)

def generate_font():
    return numpy.random.multivariate_normal(mean=numpy.zeros(m.d), cov=cov)

def generate_input(n_fonts=5):
    fonts = [generate_font() for f in xrange(n_fonts)]
    for f in xrange(n_fonts):
        a, b = fonts[f], fonts[(f+1)%n_fonts]
        for p in numpy.linspace(0, 1, 10):
            print f, p
            batch_is = numpy.zeros((m.k, m.d), dtype=theano.config.floatX)
            batch_js = numpy.zeros((m.k,), dtype=numpy.int32)
            for z in xrange(m.k):
                batch_is[z] = a * (1-p) + b * p
                batch_js[z] = z

            yield batch_is, batch_js

print 'generating...'
frame = 0
for input_i, input_j in generate_input():
    img = model.draw_grid(run_fn(input_i, input_j))
    img.save('font_%06d.png' % frame)
    frame += 1
Example #10
0
import random
import numpy
import model

data = model.get_data()
n = data.shape[0]
alphabet = numpy.zeros((62, 64, 64))
for z in xrange(62):
    alphabet[z] = random.choice(data)[z] * 1.0 / 255

model.draw_grid(alphabet).save('alphabet.png')