Exemplo n.º 1
0
import trios.shortcuts.persistence as p
import trios
import numpy as np

if __name__ == '__main__':
    jung_op = p.load_gzip('trained-jung.op.gz')
    print(jung_op.cite_me())

Exemplo n.º 2
0
    for i in range(5):
        win = w.random_win(domain, 40, True)
        op = trios.WOperator(win, SKClassifier(DecisionTreeClassifier()),
                             RAWFeatureExtractor)
        print('Training...', i)
        op.train(images)
        ops.append(op)

    comb = CombinationPattern(*ops)
    wop2 = trios.WOperator(comb.window,
                           SKClassifier(DecisionTreeClassifier(),
                                        ordered=True),
                           comb,
                           batch=True)
    print('Training 2nd level')
    wop2.train(images2)

    # save trained operator
    p.save_gzip(wop2, 'dt-tl-jung.op')
    # and load it later
    wop2 = p.load_gzip('dt-tl-jung.op')

    # load image and apply operator. Second argument is application mask.
    img = p.load_image('images/jung-1a.png')
    print('Applying to image jung-1a.png')
    out = wop2.apply(img, img)
    p.save_image(out, 'out-isi-jung-1a.png')

    print('Accuracy', wop2.eval(test, procs=1))

    print(wop2.cite_me())
Exemplo n.º 3
0
from trios.classifiers.isi import ISI
from trios.feature_extractors import RAWBitFeatureExtractor
import trios
import numpy as np

import trios.shortcuts.persistence as p

if __name__ == '__main__':
    images = trios.Imageset.read('images/level1.set')
    win = np.ones((5, 5), np.uint8)

    # ISI requires features coded in the bits of an int32
    op = trios.WOperator(win, ISI, RAWBitFeatureExtractor)
    print('Training...')
    op.train(images)

    # save trained operator
    p.save_gzip(op, 'isi-jung.op')
    # and load it later
    op2 = p.load_gzip('isi-jung.op')

    # load image and apply operator. Second argument is application mask.
    img = p.load_image('images/jung-1a.png')
    print('Applying to image jung-1a.png')
    out = op.apply(img, img)
    p.save_image(out, 'out-isi-jung-1a.png')

    test = trios.Imageset.read('images/test.set')
    print('Accuracy', op.eval(test, procs=7))
Exemplo n.º 4
0
from trios.classifiers import SKClassifier
from sklearn.tree import DecisionTreeClassifier
from trios.feature_extractors import Aperture
import trios
import numpy as np

import trios.shortcuts.persistence as p

if __name__ == '__main__':
    images = trios.Imageset([('images_gl/einstein-noise.png',
                              'images_gl/einstein-original.png', None)])
    win = np.ones((7, 7), np.uint8)

    # use Decision Tree Classifier and raw pixels as features.
    ap = Aperture(win, 10, mul=0.5)
    op = trios.WOperator(win, SKClassifier(DecisionTreeClassifier()), ap)
    print('Training...')
    op.train(images)

    # save trained operator
    p.save_gzip(op, 'ap-einstein.op')
    # and load it later
    op2 = p.load_gzip('ap-einstein.op')

    # load image and apply operator. Second argument is application mask.
    img = p.load_image('images_gl/einstein-noise.png')
    print('Applying to image images_gl/einstein-noise.png')
    out = op.apply(img, img)
    p.save_image(out, 'out-ap-einstein.png')
Exemplo n.º 5
0
import trios
import trios.shortcuts.persistence as p
import trios.shortcuts.evaluation as ev

trios.show_eval_progress = False

if __name__ == '__main__':
    operator = p.load_gzip('trained-jung.op.gz')
    testset = trios.Imageset.read('jung-images/test.set')

    ev.apply_batch(operator, testset, 'jung-result')
    print('Error:', ev.compare_folders(testset, 'jung-result',
                                       operator.window))
    print(
        'Binary:',
        ev.compare_folders(testset,
                           'jung-result',
                           operator.window,
                           binary=True))
    print(
        'Error per image',
        ev.compare_folders(testset,
                           'jung-result',
                           operator.window,
                           per_image=True))
Exemplo n.º 6
0
import trios
import trios.shortcuts.persistence as p

if __name__ == '__main__':
    # Imageset can be defined directly in code, like below
    images = trios.Imageset([('input.png', 'output.png', None),
                             ('input2.png', 'output2.png', 'mask.png')])
    # Definitions in code can be put in a module and imported like regular
    # Python code.

    # It can also be saved to a gziped file using the persistence
    p.save_gzip(images, 'imageset.gz')

    # And loaded back
    images2 = p.load_gzip('imageset.gz')
    assert images[0] == images2[0]
    assert images[1] == images2[1]
    assert len(images) == len(images2)

    # Or saved to a text-only format using the read and write methods.
    images.write('imageset-text.txt')

    images3 = trios.Imageset.read('imageset-text.txt')
    assert images[0] == images3[0]
    assert images[1] == images3[1]
    assert len(images) == len(images3)
Exemplo n.º 7
0
import sys
from trios.classifiers import sk_classifier
from trios import woperator
import trios.shortcuts.persistence as p

if __name__ == '__main__':
    sys.modules['trios.WOperator'] = woperator
    sys.modules['trios.classifiers.SKClassifier'] = sk_classifier

    obj = p.load_gzip(sys.argv[1])
    p.save_gzip(obj, sys.argv[2])