Beispiel #1
0
"""
.. module:: read_images
   :synopsis: Example for reading and viewing of image data
"""

from nutsflow import Consume, Print
from nutsml import ReadLabelDirs, ReadImage, ViewImageAnnotation, PrintColType

if __name__ == "__main__":
    show_image = ViewImageAnnotation(0, 1, pause=1, figsize=(3, 3))

    (ReadLabelDirs('images', '*.png') >> Print() >> ReadImage(0) >>
     PrintColType() >> show_image >> Consume())
Beispiel #2
0
"""

from __future__ import print_function

from glob import glob
from nutsflow import Collect, Consume, Get, Zip, Map, ArgMax, Print
from nutsml import (TransformImage, BuildBatch, ReadImage, ViewImageAnnotation,
                    ConvertLabel)

BATCH_SIZE = 128

if __name__ == "__main__":
    from cnn_train import create_network, load_names

    convert_label = ConvertLabel(None, load_names())
    rerange = TransformImage(0).by('rerange', 0, 255, 0, 1, 'float32')
    show_image = ViewImageAnnotation(0, 1, pause=1, figsize=(3, 3),
                                     interpolation='spline36')
    pred_batch = BuildBatch(BATCH_SIZE).input(0, 'image', 'float32')

    print('loading network...')
    network = create_network()
    network.load_weights()

    print('predicting...')
    samples = glob('images/*.png') >> Print() >> ReadImage(None) >> Collect()

    predictions = (samples >> rerange >> pred_batch >>
                   network.predict() >> convert_label)
    samples >> Get(0) >> Zip(predictions) >> show_image >> Consume()
Beispiel #3
0
"""

from __future__ import print_function

from nutsflow import Consume, Zip, Unzip, Map, ArgMax, nut_filter
from nutsml import TransformImage, BuildBatch, ViewImageAnnotation

BATCH_SIZE = 128

if __name__ == "__main__":
    from mlp_train import create_network, load_samples

    TransformImage.register('flatten', lambda img: img.flatten())
    transform = (TransformImage(0).by('rerange', 0, 255, 0, 1,
                                      'float32').by('flatten'))
    show_image = ViewImageAnnotation(0, (1, 2), pause=3, figsize=(3, 3))
    pred_batch = BuildBatch(BATCH_SIZE).by(0, 'vector', 'float32')
    IsMisclassified = nut_filter(lambda (i, t, p): p != t)

    print('loading samples ...')
    train_samples, test_samples = load_samples()

    print('loading network...')
    network = create_network()
    network.load_weights()

    print('predicting...')
    samples = train_samples + test_samples
    images, trues = samples >> Unzip()
    preds = (samples >> transform >> pred_batch >> network.predict() >> Map(
        ArgMax()))
Beispiel #4
0
"""

from __future__ import print_function

from nutsflow import Collect, Consume, Get, Zip, Map, Format, ArgMax
from nutsml import (TransformImage, BuildBatch, ReadImage, ReadLabelDirs,
                    ViewImageAnnotation)

BATCH_SIZE = 128

if __name__ == "__main__":
    from mlp_train import create_network

    TransformImage.register('flatten', lambda img: img.flatten())
    transform = (TransformImage(0).by('rerange', 0, 255, 0, 1,
                                      'float32').by('flatten'))
    show_image = ViewImageAnnotation(0, (1, 2), pause=1, figsize=(4, 4))
    pred_batch = BuildBatch(BATCH_SIZE).by(0, 'vector', 'float32')

    print('loading network...')
    network = create_network()
    network.load_weights()

    print('predicting...')
    samples = ReadLabelDirs('images', '*.png') >> ReadImage(0) >> Collect()
    truelabels = samples >> Get(1) >> Format('true: {}')
    predictions = (samples >> transform >> pred_batch >> network.predict() >>
                   Map(ArgMax()) >> Format('pred: {}'))
    samples >> Get(0) >> Zip(predictions,
                             truelabels) >> show_image >> Consume()
Beispiel #5
0
"""
.. module:: view_train_images
   :synopsis: Example for showing images with annotation
"""

from nutsflow import Take, Consume
from nutsml import ViewImageAnnotation

if __name__ == "__main__":
    from mlp_train import load_samples

    samples, _ = load_samples()
    (samples >> Take(10) >> ViewImageAnnotation(0, 1, pause=1) >> Consume())