Ejemplo n.º 1
0
def show_shear(sent):
    she = 7
    img = ochre.get_sentence(sent)

    img_ = ochre.generators.shear(ochre.get_sentence(sent), shearing=she)
    img = np.concatenate((img, img_), axis=1)

    img_ = ochre.generators.shear(ochre.get_sentence(sent), shearing=-she)
    img = np.concatenate((img, img_), axis=1)

    plt.imshow(img)
    plt.show()
Ejemplo n.º 2
0
def show_shift(sent):
    shi = 2  # number of shifts each direction
    img = ochre.get_sentence(sent)
    for i in range(shi * 2):
        img_ = ochre.generators.shift(ochre.get_sentence(sent), 2 * (i - shi),
                                      0)
        img = np.concatenate((img, img_), axis=1)
    for i in range(shi * 2):
        img_ = ochre.generators.shift(ochre.get_sentence(sent), 0,
                                      2 * (i - shi))
        img = np.concatenate((img, img_), axis=1)

    plt.imshow(img)
    plt.show()
Ejemplo n.º 3
0
Archivo: train.py Proyecto: pgdr/ochre
def main(sentence, collection=True):
    print(sentence)
    box = lambda idx: (0, idx * 14, 14, (idx + 1) * 14)
    sentence_img = ochre.get_sentence(sentence)

    letters = sorted(set(sentence.replace(" ", "")))
    if collection:
        ts = {
            c: list(ochre.collection.collection(ochre.get_letter(c)))
            for c in letters
        }
    else:
        ts = {c: [ochre.get_letter(c)] for c in letters}
    nn = ochre.training.train(ts)

    prediction = [
        ochre.training.predict(nn, sentence_img, box=box(idx))
        for idx in range(len(sentence))
    ]
    print("".join(prediction))

    for idx, c in enumerate(sentence):
        if c == " ":
            print(f"Skipping space at idx={idx}")
            continue
        letter = ochre.training.predict(nn, sentence_img, box=box(idx))
        cor = "ok" if letter == c else "fail"
        print(f"{letter} == {c}     {cor}")
Ejemplo n.º 4
0
def test_sentence():
    box = lambda idx: (0, idx * 14, 14, (idx + 1) * 14)
    sentence = "my first word".lower()
    sentence_img = ochre.get_sentence(sentence)

    letters = sorted(set(sentence.replace(" ", "")))
    nn = _get_nn(letters)

    for idx, c in enumerate(sentence):
        if c == " ":
            print(f"Skipping space at idx={idx}")
            continue
        letter = ochre.training.predict(nn, sentence_img, box=box(idx))
        assert letter == c
Ejemplo n.º 5
0
Archivo: vis.py Proyecto: pgdr/ochre
def vis_sentence(sent):
    coll = list(
        ochre.collection.collection(
            ochre.get_sentence(sent, serif=os.getenv("SERIF"))))
    return coll