Exemple #1
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))
Exemple #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())
Exemple #3
0
from trios.classifiers import SKClassifier
from sklearn.tree import DecisionTreeClassifier
from trios.feature_extractors import RAWFeatureExtractor
import trios
import numpy as np

import trios.shortcuts.persistence as p
import trios.shortcuts.window as trios_win

if __name__ == '__main__':
    training_set = trios.Imageset.read('jung-images/training.set')
    test = trios.Imageset.read('jung-images/test.set')

    win = trios_win.rectangle(9, 7)
    classifier = SKClassifier(DecisionTreeClassifier())
    fext = RAWFeatureExtractor(win)
    op = trios.WOperator(win, classifier, fext)

    op.train(training_set)
    p.save_gzip(op, 'basic-jung.op.gz')

    print('Error: ', op.eval(test))
Exemple #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')
Exemple #5
0
trios.show_eval_progress = False

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

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

    # save trained operator
    p.save_gzip(op, 'dt-jung.op')
    # and load it later
    op2 = p.load_gzip('dt-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-dt-jung-1a.png')

    test = trios.Imageset.read('images/test.set')
    print('Accuracy', op.eval(test, procs=1, per_image=True))
    print('Accuracy', op.eval(test, procs=2, per_image=True))
    print('Accuracy', op.eval(test, procs=8, per_image=True))

    op.extractor.batch_size = 100
Exemple #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)
Exemple #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])