예제 #1
0
def make_feature_arrays(ipl):

    params = ipl.get_params()
    thisparams = rdict(params['random_forest'])
    targetfile = params['resultfolder'] + params['resultsfile']

    # Load the necessary images
    load_images(ipl)
    ipl.logging('\nInitial datastructure: \n\n{}',
                ipl.datastructure2string(maxdepth=3))

    result = IPL()
    evaluation = rdict()

    for d, k, v, kl in ipl.data_iterator(yield_short_kl=True):

        if k == '0':

            ipl.logging(
                '===============================\nWorking on group: {}', kl)

            # TODO: Implement copy full logger
            ipl[kl].set_logger(ipl.get_logger())

            # Load the image data into memory
            ipl[kl].populate()

            # def shp(x):
            #     return x.shape

            # print ipl[kl]['0', 'true']
            # print ipl[kl].dss(function=shp)

            ipl[kl]['0', 'true'] = libip.rf_make_feature_array(ipl[kl]['0',
                                                                       'true'])
            ipl.logging(
                "Computed feature array for ['0', 'true'] with shape {}",
                ipl[kl]['0', 'true'].shape)
            ipl[kl]['0',
                    'false'] = libip.rf_make_feature_array(ipl[kl]['0',
                                                                   'false'])
            ipl.logging(
                "Computed feature array for ['0', 'false'] with shape {}",
                ipl[kl]['0', 'false'].shape)
            ipl[kl]['1', 'true'] = libip.rf_make_feature_array(ipl[kl]['1',
                                                                       'true'])
            ipl.logging(
                "Computed feature array for ['1', 'true'] with shape {}",
                ipl[kl]['1', 'true'].shape)
            ipl[kl]['1',
                    'false'] = libip.rf_make_feature_array(ipl[kl]['1',
                                                                   'false'])
            ipl.logging(
                "Computed feature array for ['1', 'false'] with shape {}",
                ipl[kl]['1', 'false'].shape)

            ipl.write(filepath=params['intermedfolder'] + 'feature_arrays.h5',
                      keys=[kl])
def make_feature_arrays(ipl):

    params = ipl.get_params()
    thisparams = rdict(params['random_forest'])
    targetfile = params['resultfolder'] + params['resultsfile']

    # Load the necessary images
    load_images(ipl)
    ipl.logging('\nInitial datastructure: \n\n{}', ipl.datastructure2string(maxdepth=3))

    result = IPL()
    evaluation = rdict()

    for d, k, v, kl in ipl.data_iterator(yield_short_kl=True):

        if k == '0':

            ipl.logging('===============================\nWorking on group: {}', kl)

            # TODO: Implement copy full logger
            ipl[kl].set_logger(ipl.get_logger())

            # Load the image data into memory
            ipl[kl].populate()

            # def shp(x):
            #     return x.shape

            # print ipl[kl]['0', 'true']
            # print ipl[kl].dss(function=shp)

            ipl[kl]['0', 'true'] = libip.rf_make_feature_array(ipl[kl]['0', 'true'])
            ipl.logging("Computed feature array for ['0', 'true'] with shape {}", ipl[kl]['0', 'true'].shape)
            ipl[kl]['0', 'false'] = libip.rf_make_feature_array(ipl[kl]['0', 'false'])
            ipl.logging("Computed feature array for ['0', 'false'] with shape {}", ipl[kl]['0', 'false'].shape)
            ipl[kl]['1', 'true'] = libip.rf_make_feature_array(ipl[kl]['1', 'true'])
            ipl.logging("Computed feature array for ['1', 'true'] with shape {}", ipl[kl]['1', 'true'].shape)
            ipl[kl]['1', 'false'] = libip.rf_make_feature_array(ipl[kl]['1', 'false'])
            ipl.logging("Computed feature array for ['1', 'false'] with shape {}", ipl[kl]['1', 'false'].shape)

            ipl.write(filepath=params['intermedfolder'] + 'feature_arrays.h5', keys=[kl])
def random_forest(ipl, debug=False):

    params = ipl.get_params()
    thisparams = rdict(params['random_forest'])
    targetfile = params['resultfolder'] + params['resultsfile']

    # Load the necessary images
    load_images(ipl)
    ipl.logging('\nInitial datastructure: \n\n{}', ipl.datastructure2string(maxdepth=3))

    result = IPL()
    new_eval = rdict()
    evaluation = rdict()

    for d, k, v, kl in ipl.data_iterator(yield_short_kl=True):

        if k == '0':

            ipl.logging('===============================\nWorking on group: {}', kl)

            # TODO: Implement copy full logger
            ipl[kl].set_logger(ipl.get_logger())

            # Load the image data into memory
            ipl[kl].populate()

            # def shp(x):
            #     return x.shape

            # print ipl[kl]['0', 'true']
            # print ipl[kl].dss(function=shp)

            ipl[kl]['0', 'true'] = libip.rf_make_feature_array(ipl[kl]['0', 'true'])
            ipl.logging("Computed feature array for ['0', 'true'] with shape {}", ipl[kl]['0', 'true'].shape)
            ipl[kl]['0', 'false'] = libip.rf_make_feature_array(ipl[kl]['0', 'false'])
            ipl.logging("Computed feature array for ['0', 'false'] with shape {}", ipl[kl]['0', 'false'].shape)
            ipl[kl]['1', 'true'] = libip.rf_make_feature_array(ipl[kl]['1', 'true'])
            ipl.logging("Computed feature array for ['1', 'true'] with shape {}", ipl[kl]['1', 'true'].shape)
            ipl[kl]['1', 'false'] = libip.rf_make_feature_array(ipl[kl]['1', 'false'])
            ipl.logging("Computed feature array for ['1', 'false'] with shape {}", ipl[kl]['1', 'false'].shape)

            # print '...'
            # print ipl[kl]['0']

            result[kl + ['0']] = libip.random_forest(ipl[kl]['0'], ipl[kl]['1'], debug=debug)
            result[kl + ['1']] = libip.random_forest(ipl[kl]['1'], ipl[kl]['0'], debug=debug)

            new_eval[kl + ['0']] = libip.new_eval([x[0] for x in result[kl]['0']], [x[1] for x in result[kl]['0']])
            new_eval[kl + ['1']] = libip.new_eval([x[0] for x in result[kl]['1']], [x[1] for x in result[kl]['1']])

            evaluation[kl + ['0']] = libip.evaluation(result[kl]['0'])
            evaluation[kl + ['1']] = libip.evaluation(result[kl]['1'])

            ipl.logging('+++ RESULTS +++')
            ipl.logging("[kl]['0']")
            # for i in result[kl]['0']:
            #     ipl.logging('{}', i)
            for key, value in evaluation[kl]['0'].iteritems():
                ipl.logging('{} = {}', key, value)
            for key, value in new_eval[kl]['0'].iteritems():
                ipl.logging('{} = {}', key, value)

            ipl.logging('+++')
            ipl.logging("[kl]['1']")
            # for i in result[kl]['1']:
            #     ipl.logging('{}', i)
            for key, value in evaluation[kl]['1'].iteritems():
                ipl.logging('{} = {}', key, value)
            for key, value in new_eval[kl]['1'].iteritems():
                ipl.logging('{} = {}', key, value)

            # # Write the result to file
            # ipl.write(filepath=targetfile, keys=[kl])
            # Free memory
            ipl[kl] = None

    return IPL(data=result), IPL(data=evaluation)
예제 #4
0
def random_forest(ipl, debug=False):

    params = ipl.get_params()
    thisparams = rdict(params['random_forest'])
    targetfile = params['resultfolder'] + params['resultsfile']

    # Load the necessary images
    load_images(ipl)
    ipl.logging('\nInitial datastructure: \n\n{}',
                ipl.datastructure2string(maxdepth=3))

    result = IPL()
    new_eval = rdict()
    evaluation = rdict()

    for d, k, v, kl in ipl.data_iterator(yield_short_kl=True):

        if k == '0':

            ipl.logging(
                '===============================\nWorking on group: {}', kl)

            # TODO: Implement copy full logger
            ipl[kl].set_logger(ipl.get_logger())

            # Load the image data into memory
            ipl[kl].populate()

            # def shp(x):
            #     return x.shape

            # print ipl[kl]['0', 'true']
            # print ipl[kl].dss(function=shp)

            ipl[kl]['0', 'true'] = libip.rf_make_feature_array(ipl[kl]['0',
                                                                       'true'])
            ipl.logging(
                "Computed feature array for ['0', 'true'] with shape {}",
                ipl[kl]['0', 'true'].shape)
            ipl[kl]['0',
                    'false'] = libip.rf_make_feature_array(ipl[kl]['0',
                                                                   'false'])
            ipl.logging(
                "Computed feature array for ['0', 'false'] with shape {}",
                ipl[kl]['0', 'false'].shape)
            ipl[kl]['1', 'true'] = libip.rf_make_feature_array(ipl[kl]['1',
                                                                       'true'])
            ipl.logging(
                "Computed feature array for ['1', 'true'] with shape {}",
                ipl[kl]['1', 'true'].shape)
            ipl[kl]['1',
                    'false'] = libip.rf_make_feature_array(ipl[kl]['1',
                                                                   'false'])
            ipl.logging(
                "Computed feature array for ['1', 'false'] with shape {}",
                ipl[kl]['1', 'false'].shape)

            # print '...'
            # print ipl[kl]['0']

            result[kl + ['0']] = libip.random_forest(ipl[kl]['0'],
                                                     ipl[kl]['1'],
                                                     debug=debug)
            result[kl + ['1']] = libip.random_forest(ipl[kl]['1'],
                                                     ipl[kl]['0'],
                                                     debug=debug)

            new_eval[kl +
                     ['0']] = libip.new_eval([x[0] for x in result[kl]['0']],
                                             [x[1] for x in result[kl]['0']])
            new_eval[kl +
                     ['1']] = libip.new_eval([x[0] for x in result[kl]['1']],
                                             [x[1] for x in result[kl]['1']])

            evaluation[kl + ['0']] = libip.evaluation(result[kl]['0'])
            evaluation[kl + ['1']] = libip.evaluation(result[kl]['1'])

            ipl.logging('+++ RESULTS +++')
            ipl.logging("[kl]['0']")
            # for i in result[kl]['0']:
            #     ipl.logging('{}', i)
            for key, value in evaluation[kl]['0'].iteritems():
                ipl.logging('{} = {}', key, value)
            for key, value in new_eval[kl]['0'].iteritems():
                ipl.logging('{} = {}', key, value)

            ipl.logging('+++')
            ipl.logging("[kl]['1']")
            # for i in result[kl]['1']:
            #     ipl.logging('{}', i)
            for key, value in evaluation[kl]['1'].iteritems():
                ipl.logging('{} = {}', key, value)
            for key, value in new_eval[kl]['1'].iteritems():
                ipl.logging('{} = {}', key, value)

            # # Write the result to file
            # ipl.write(filepath=targetfile, keys=[kl])
            # Free memory
            ipl[kl] = None

    return IPL(data=result), IPL(data=evaluation)