"""
.. module:: view_train_images
   :synopsis: Example nuts-ml pipeline reading and viewing image data
"""

from nutsflow import Take, Consume, MapCol
from nutsml import ViewImageAnnotation, PrintColType

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

    train_samples, _ = load_samples()
    names = load_names()

    id2name = MapCol(1, lambda i: names[i])
    show_image = ViewImageAnnotation(0, 1, pause=1, figsize=(2, 2),
                                     interpolation='spline36')

    (train_samples >> Take(10) >> id2name >> PrintColType() >>
     show_image >> Consume())
Exemple #2
0
   :synopsis: Example pipeline for viewing annotations and classification
"""

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()
"""
.. module:: write_images
   :synopsis: Example nuts-ml pipeline for writing of images 
"""

from nutsflow import (Take, Print, Consume, Enumerate, Zip, Format, MapCol,
                      Get)
from nutsml import WriteImage, ConvertLabel

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

    train_samples, _ = load_samples()

    convert_label = ConvertLabel(1, load_names())
    fnames = (Enumerate() >> Zip(train_samples >> Get(1)) >> convert_label >>
              Format('{0}_{1}') >> Print())
    imagepath = 'images/img*.png'
    train_samples >> Take(10) >> WriteImage(0, imagepath, fnames) >> Consume()