Exemplo n.º 1
0
def aoi2_train(ibs,
               species_list=None,
               train_gid_list=None,
               purge=True,
               cache=False):
    from wbia_cnn.ingest_wbia import get_aoi2_training_data
    from wbia_cnn.process import numpy_processed_directory5
    from wbia_cnn.models.aoi2 import train_aoi2
    from wbia_cnn.utils import save_model

    data_path = join(ibs.get_cachedir(), 'extracted')
    extracted_path = get_aoi2_training_data(
        ibs,
        dest_path=data_path,
        target_species_list=species_list,
        train_gid_list=train_gid_list,
        purge=purge,
        cache=cache,
    )
    id_file, X_file, y_file = numpy_processed_directory5(extracted_path)
    output_path = join(ibs.get_cachedir(), 'training', 'aoi2')
    model_path = train_aoi2(output_path, X_file, y_file)
    model_state = ut.load_cPkl(model_path)
    assert 'species_list' not in model_state
    model_state['species_list'] = species_list
    save_model(model_state, model_path)
    return model_path
Exemplo n.º 2
0
def labeler_train_wbia_cnn(ibs,
                           species_list=None,
                           species_mapping=None,
                           viewpoint_mapping=None,
                           **kwargs):
    from wbia_cnn.ingest_wbia import get_cnn_labeler_training_images
    from wbia_cnn.process import numpy_processed_directory2
    from wbia_cnn.models.labeler import train_labeler
    from wbia_cnn.utils import save_model

    data_path = join(ibs.get_cachedir(), 'extracted')
    extracted_path = get_cnn_labeler_training_images(
        ibs,
        data_path,
        category_list=species_list,
        category_mapping=species_mapping,
        viewpoint_mapping=viewpoint_mapping,
        **kwargs,
    )
    id_file, X_file, y_file = numpy_processed_directory2(extracted_path)
    output_path = join(ibs.get_cachedir(), 'training', 'labeler')
    model_path = train_labeler(output_path, X_file, y_file)
    # Add the species_list to the model
    model_state = ut.load_cPkl(model_path)
    assert 'category_list' not in model_state
    model_state['category_list'] = species_list
    assert 'viewpoint_mapping' not in model_state
    model_state['viewpoint_mapping'] = viewpoint_mapping
    save_model(model_state, model_path)
    return model_path
Exemplo n.º 3
0
def classifier2_train(ibs,
                      species_list=None,
                      species_mapping={},
                      train_gid_set=None,
                      **kwargs):
    from wbia_cnn.ingest_wbia import get_cnn_classifier2_training_images
    from wbia_cnn.process import numpy_processed_directory3
    from wbia_cnn.models.classifier2 import train_classifier2
    from wbia_cnn.utils import save_model

    if species_list is not None:
        species_list = sorted(species_list)
    data_path = join(ibs.get_cachedir(), 'extracted')
    values = get_cnn_classifier2_training_images(
        ibs,
        species_list,
        category_mapping=species_mapping,
        train_gid_set=train_gid_set,
        dest_path=data_path,
        **kwargs,
    )
    extracted_path, category_list = values
    id_file, X_file, y_file = numpy_processed_directory3(extracted_path)
    output_path = join(ibs.get_cachedir(), 'training', 'classifier2')
    model_path = train_classifier2(output_path, X_file, y_file, purge=True)
    # Add the species_list to the model
    model_state = ut.load_cPkl(model_path)
    assert 'category_list' not in model_state
    model_state['category_list'] = category_list
    save_model(model_state, model_path)
    # Return model path
    return model_path
Exemplo n.º 4
0
def aoi_train(ibs, species_list=None):
    from wbia_cnn.ingest_wbia import get_aoi_training_data
    from wbia_cnn.process import numpy_processed_directory4
    from wbia_cnn.models.aoi import train_aoi
    from wbia_cnn.utils import save_model

    data_path = join(ibs.get_cachedir(), 'extracted')
    extracted_path = get_aoi_training_data(ibs,
                                           data_path,
                                           target_species_list=species_list)
    id_file, X_file, y_file = numpy_processed_directory4(extracted_path)
    output_path = join(ibs.get_cachedir(), 'training', 'aoi')
    model_path = train_aoi(output_path, X_file, y_file)
    model_state = ut.load_cPkl(model_path)
    assert 'species_list' not in model_state
    model_state['species_list'] = species_list
    save_model(model_state, model_path)
    return model_path
Exemplo n.º 5
0
def classifier_binary_train(ibs, species_list, **kwargs):
    from wbia_cnn.ingest_wbia import get_cnn_classifier_binary_training_images
    from wbia_cnn.process import numpy_processed_directory2
    from wbia_cnn.models.classifier import train_classifier
    from wbia_cnn.utils import save_model

    data_path = join(ibs.get_cachedir(), 'extracted')
    extracted_path = get_cnn_classifier_binary_training_images(
        ibs, species_list, dest_path=data_path, **kwargs)
    id_file, X_file, y_file = numpy_processed_directory2(extracted_path)
    output_path = join(ibs.get_cachedir(), 'training', 'classifier-binary')
    model_path = train_classifier(output_path, X_file, y_file)
    # Add the species_list to the model
    model_state = ut.load_cPkl(model_path)
    assert 'species_list' not in model_state
    model_state['species_list'] = species_list
    save_model(model_state, model_path)
    # Return model path
    return model_path
Exemplo n.º 6
0
def background_train(ibs,
                     species,
                     train_gid_set=None,
                     global_limit=500000,
                     **kwargs):
    """
    Example:
    >>> values = output_path, X_file, y_file
    >>> print(values)
    >>> output_path, X_file, y_file = values
    >>> from ibeis_cnn.models.background import train_background
    >>> values = (
    >>>     '/data/ibeis/IMS_Master/_ibsdb/_ibeis_cache/training/background',
    >>>     '/data/ibeis/IMS_Master/_ibsdb/_ibeis_cache/extracted/background/raw/X.npy',
    >>>     '/data/ibeis/IMS_Master/_ibsdb/_ibeis_cache/extracted/background/labels/y.npy'
    >>> )
    >>> output_path, X_file, y_file = values
    """
    from wbia_cnn.ingest_wbia import get_background_training_patches2
    from wbia_cnn.process import numpy_processed_directory2
    from wbia_cnn.models.background import train_background
    from wbia_cnn.utils import save_model

    data_path = join(ibs.get_cachedir(), 'extracted')
    extracted_path = get_background_training_patches2(
        ibs,
        species,
        data_path,
        patch_size=50,
        train_gid_set=train_gid_set,
        global_limit=global_limit,
        **kwargs,
    )
    id_file, X_file, y_file = numpy_processed_directory2(extracted_path)
    output_path = join(ibs.get_cachedir(), 'training', 'background')
    model_path = train_background(output_path, X_file, y_file)
    model_state = ut.load_cPkl(model_path)
    assert 'species' not in model_state
    model_state['species'] = species
    save_model(model_state, model_path)
    return model_path