Esempio n. 1
0
def task_test_cnn(args):
    dataset = ImageIterator(args.input, args.output)
    dataset_batches = BatchGenerator(dataset, args.batch)
    from mitosis import model_base, model_1, model_2
    TT.debug("Compile base model.")
    model = model_base(0)
    TT.debug("Compile model 1.")
    model1 = model_1(0)
    TT.debug("Compile model 2.")
    model2 = model_2(0)
    model_saved_weights_path = os.path.join(args.path,
                                            'base-model.weights.npy')
    model1_saved_weights_path = os.path.join(args.path, 'model1.weights.npy')
    model2_saved_weights_path = os.path.join(args.path, 'model2.weights.npy')
    TT.info("Loading weights from %s" % model_saved_weights_path)
    model.load_weights(model_saved_weights_path)
    TT.info("Loading weights from %s" % model1_saved_weights_path)
    model1.load_weights(model1_saved_weights_path)
    TT.info("Loading weights from %s" % model2_saved_weights_path)
    model2.load_weights(model2_saved_weights_path)
    test_start = time.time()
    out = out1 = out2 = None
    for x, y in dataset_batches:
        tmp = model.predict(x, args.mini_batch, args.verbose)
        local1 = numpy.zeros(tmp.shape)
        local2 = numpy.zeros(tmp.shape)
        out = np_append(out, tmp)
        x = 1. - x
        x_new = []
        indices = []
        for i in range(len(tmp)):
            if tmp[i][0] > .6:
                x_new.append(x[i])
                indices.append(i)

        x_new = numpy.asarray(x_new)
        if len(x_new):
            tmp1 = model1.predict(x_new, args.mini_batch, args.verbose)
            local1[indices] = tmp1
        out1 = np_append(out1, local1)

        if len(x_new):
            tmp2 = model2.predict(x_new, args.mini_batch, args.verbose)
            local2[indices] = tmp2
        out2 = np_append(out2, local2)
    width, height = dataset.image_size
    out = numpy.reshape(out[:, 0], (height, width))
    out1 = numpy.reshape(out1[:, 0], (height, width))
    out2 = numpy.reshape(out2[:, 0], (height, width))
    numpy.save(change_ext(args.input, 'predicted.npy'), out)
    numpy.save(change_ext(args.input, 'model1.predicted.npy'), out1)
    numpy.save(change_ext(args.input, 'model2.predicted.npy'), out2)
    numpy.save(change_ext(args.input, 'expected.npy'), dataset.output)
    TT.success("Testing finished in %.2f minutes." %
               ((time.time() - test_start) / 60.))
Esempio n. 2
0
def task_test_filter(args):
    dataset = ImageIterator(args.input, args.output)
    dataset_batches = BatchGenerator(dataset, args.batch)
    from mitosis import model_base
    TT.debug("Compile base model.")
    model = model_base(args.lr)
    model_saved_weights_path = os.path.join(args.path, 'base-model.weights.npy')
    TT.info("Loading weights from %s" % model_saved_weights_path)
    model.load_weights(model_saved_weights_path)
    test_start = time.time()
    out = None
    for x, y in dataset_batches:
        tmp = model.predict(x, args.mini_batch, args.verbose)
        out = np_append(out, tmp)
    width, height = dataset.image_size
    out = numpy.reshape(out[:, 0], (height, width))
    numpy.save(change_ext(args.input, 'predicted.npy'), out)
    numpy.save(change_ext(args.input, 'expected.npy'), dataset.output)
    TT.success("Testing finished in %.2f minutes." % ((time.time() - test_start) / 60.))
Esempio n. 3
0
# Fix Import
from test import root_path
# Actual Imports
from utilities import TT
from iterators import BatchGenerator, Dataset, ImageIterator
from dataset import icpr2012

root = root_path()

# 1. Test BatchGenerator
# flt, mapper = icpr2012()
TT.verbose = True
# batches = BatchGenerator(Dataset(root+'/datasets/ICPR 2012/testing/set1', mapper=mapper, filename_filter=flt), 1000, 500)
# for batch in batches:
#     continue

batches = BatchGenerator(ImageIterator(root + '/tests/patch_at/utilities.tiff',
                                       root + '/tests/patch_at/utilities.csv'),
                         batch_size=1000)
for batch in batches:
    continue