Esempio n. 1
0
def show_collection(char):
    ori = ochre.get_letter(char)
    img = ochre.get_letter(char)
    for img_ in ochre.collection.collection(ori):
        img = np.concatenate((img, img_), axis=1)
    plt.imshow(img)
    plt.show()
Esempio n. 2
0
File: train.py Progetto: 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}")
Esempio n. 3
0
def _get_nn(letters, n_copies=1, collection=False):
    if not collection:
        ts = {c: [ochre.get_letter(c) for _ in range(n_copies)] for c in letters}
    else:
        for c in letters:
            ts = {
                c: list(ochre.collection.collection(ochre.get_letter(c)))
                for c in letters
            }
    nn = ochre.training.train(ts)
    return nn
Esempio n. 4
0
def test_training():
    letters = ["a", "b", "c", "x", "y", "z"]
    nn = _get_nn(letters)

    for letter in letters:
        c = ochre.get_letter(letter)
        assert ochre.training.predict(nn, c) == letter
Esempio n. 5
0
def test_mulitple_training():
    letters = ["a", "b", "c", "x", "y", "z"]
    nn = _get_nn(letters, n_copies=1)

    for letter in letters:
        c = ochre.get_letter(letter)
        vec = ochre.training.predict_vector(nn, c)
        assert ochre.training.predict(nn, c) == letter, vec
Esempio n. 6
0
def test_collection_training():
    letters = "abcdefghijklxyz"
    nn = _get_nn(letters, n_copies=1, collection=True)

    for letter in letters:
        c = ochre.get_letter(letter)
        vec = ochre.training.predict_vector(nn, c)
        assert ochre.training.predict(nn, c) == letter, vec
Esempio n. 7
0
def train_collection(chars):
    ts = {
        c: list(ochre.collection.collection(ochre.get_letter(c), num=1))
        for c in chars
    }
    nn = ochre.training.train(ts)
Esempio n. 8
0
def test_letter():
    x = ochre.get_letter("x")
    assert isinstance(x, np.ndarray)