コード例 #1
0
ファイル: classifier.py プロジェクト: Erotemic/ibeis
def classify_thumbnail_list(thumbnail_list, model='v1'):
    print('[classifier] Loading the classifier training data')
    data_list = np.array(thumbnail_list, dtype=np.uint8)

    print('[mnist] Loading the data into a JPCNN_Data')
    data = JPCNN_Data()
    data.set_data_list(data_list)

    print('[classifier] Create the JPCNN_Model used for testing')
    url = MODEL_DOMAIN + MODEL_URLS[model]
    model_path = ut.grab_file_url(url, appname='ibeis')
    model = Classifier_Model(model_path)

    print('[mnist] Create the JPCNN_network and start testing')
    net = JPCNN_Network(model, data)
    test_results = net.test('.', best_weights=True)
    prediction_list = test_results['label_list']
    confidence_list = test_results['confidence_list']

    result_list = list(zip(confidence_list, prediction_list))

    # Release memory
    data = None
    model = None
    net = None

    return result_list
コード例 #2
0
ファイル: labeler.py プロジェクト: whaozl/ibeis
def label_chip_list(chip_list, model='v1'):
    print('[classifier] Loading the classifier training data')

    data_list = np.array(chip_list, dtype=np.uint8)

    print('[mnist] Loading the data into a JPCNN_Data')
    data = JPCNN_Data()
    data.set_data_list(data_list)

    print('[classifier] Create the JPCNN_Model used for testing')
    url = MODEL_DOMAIN + MODEL_URLS[model]
    model_path = ut.grab_file_url(url, appname='ibeis')
    model = Labeler_Model(model_path)

    print('[mnist] Create the JPCNN_network and start testing')
    net = JPCNN_Network(model, data)
    test_results = net.test('.', best_weights=True)

    class_list = list(net.config['data_label_encoder'].classes_)
    prediction_list = test_results['label_list']
    confidence_list = test_results['confidence_list']
    probability_list = test_results['probability_list']

    species_list = []
    viewpoint_list = []
    for prediction in prediction_list:
        prediction = prediction.strip()
        if ':' in prediction:
            prediction = prediction.split(':')
            species, viewpoint = prediction
        else:
            species = prediction
            viewpoint = None
        if species.lower() == 'ignore':
            species = const.UNKNOWN
        species_list.append(species)
        viewpoint_list.append(viewpoint)

    quality_list = [const.QUAL_UNKNOWN] * len(prediction_list)
    orientation_list = [0.0] * len(prediction_list)

    probability_dict_list = []
    for probability in probability_list:
        probability_dict = {
            class_ : prob
            for class_, prob in zip(class_list, probability)
        }
        probability_dict_list.append(probability_dict)

    result_list = list(zip(confidence_list, species_list, viewpoint_list,
                       quality_list, orientation_list, probability_dict_list))

    # Release memory
    data = None
    model = None
    net = None

    return result_list
コード例 #3
0
ファイル: orientation.py プロジェクト: Erotemic/ibeis
def train_orientation(output_path):
    from jpcnn.core import JPCNN_Network, JPCNN_Data
    print('[orientation] Loading the Orientation training data')
    data_list, label_list = load_orientation()

    print('[orientation] Loading the data into a JPCNN_Data')
    data = JPCNN_Data()
    data.set_data_list(data_list)
    data.set_label_list(label_list)

    print('[orientation] Create the JPCNN_Model used for training')
    model = Orientation_Model()

    print('[orientation] Create the JPCNN_network and start training')
    net = JPCNN_Network(model, data)
    net.train(
        output_path,
        train_learning_rate=0.01,
        train_batch_size=128,
        train_max_epochs=100,
    )
コード例 #4
0
ファイル: classifier.py プロジェクト: Erotemic/ibeis
def train_classifier(output_path, **kwargs):
    print('[classifier] Loading the classifier training data')
    data_list, label_list = load_classifier(**kwargs)

    print('[classifier] Loading the data into a JPCNN_Data')
    data = JPCNN_Data()
    data.set_data_list(data_list)
    data.set_label_list(label_list)

    print('[classifier] Create the JPCNN_Model used for training')
    model = Classifier_Model()

    print('[classifier] Create the JPCNN_network and start training')
    net = JPCNN_Network(model, data)
    model_path = net.train(
        output_path,
        train_learning_rate=0.01,
        train_batch_size=64,
        train_max_epochs=40,
        train_mini_batch_augment=False,
    )
    return model_path
コード例 #5
0
ファイル: labeler.py プロジェクト: whaozl/ibeis
def test_labeler(output_path):
    print('[labeler] Loading the labeler training data')
    data_list, label_list = load_images()

    print('[mnist] Loading the data into a JPCNN_Data')
    data = JPCNN_Data()
    data.set_data_list(data_list)
    data.set_label_list(label_list)

    print('[labeler] Create the JPCNN_Model used for testing')
    model = Labeler_Model('model.npy')

    print('[mnist] Create the JPCNN_network and start testing')
    net = JPCNN_Network(model, data)
    test_results = net.test(output_path, best_weights=True)
    prediction_list = test_results['label_list']
    confidence_list = test_results['confidence_list']

    best_errors = np.inf
    conf_list = [ _ / 100.0 for _ in range(0, 101) ]
    # conf_list = [ 0.81 ]  # FOR MODEL.5.NPY
    for conf in conf_list:
        failure_path = join(output_path, 'failures')
        ut.ensuredir(failure_path)
        error_list = [0, 0, 0, 0]
        zipped = zip(data_list, label_list, prediction_list, confidence_list)
        for index, (data, label, prediction, confidence) in enumerate(zipped):
            if prediction == 'negative' and confidence < conf:
                prediction = 'positive'
                confidence == 1.0 - confidence
            if label == prediction and label == 'positive':
                error_list[0] += 1
            elif label == prediction and label == 'negative':
                error_list[1] += 1
            elif label != prediction:
                if label == 'positive':
                    error_list[2] += 1
                elif label == 'negative':
                    error_list[3] += 1
                args = (confidence, index, label, prediction)
                failure_filename = 'failure_%0.05f_%06d_%s_%s.png' % args
                failure_filepath = join(failure_path, failure_filename)
                cv2.imwrite(failure_filepath, data)
        errors = error_list[2] + error_list[3]
        total = sum(error_list)
        if errors < best_errors:
            best_errors = errors
            print(error_list)
            args = (conf, errors / total, errors, total, )
            print('Error rate %0.2f: %0.03f [ %d / %d ]' % args)
コード例 #6
0
def train_orientation(output_path):
    from jpcnn.core import JPCNN_Network, JPCNN_Data
    print('[orientation] Loading the Orientation training data')
    data_list, label_list = load_orientation()

    print('[orientation] Loading the data into a JPCNN_Data')
    data = JPCNN_Data()
    data.set_data_list(data_list)
    data.set_label_list(label_list)

    print('[orientation] Create the JPCNN_Model used for training')
    model = Orientation_Model()

    print('[orientation] Create the JPCNN_network and start training')
    net = JPCNN_Network(model, data)
    net.train(
        output_path,
        train_learning_rate=0.01,
        train_batch_size=128,
        train_max_epochs=100,
    )
コード例 #7
0
ファイル: labeler.py プロジェクト: whaozl/ibeis
def train_labeler(output_path, **kwargs):
    print('[labeler] Loading the labeler training data')
    data_list, label_list = load_labeler(**kwargs)

    print('[labeler] Loading the data into a JPCNN_Data')
    data = JPCNN_Data()
    data.set_data_list(data_list)
    data.set_label_list(label_list)

    print('[labeler] Create the JPCNN_Model used for training')
    model = Labeler_Model()

    print('[labeler] Create the JPCNN_network and start training')
    net = JPCNN_Network(model, data)
    model_path = net.train(
        output_path,
        train_learning_rate=0.01,
        train_batch_size=64,
        train_max_epochs=5,
        train_mini_batch_augment=False,
    )
    return model_path