print('Elapsed time: {:.2f} s'.format(time.time() - start))
    temp = time.time()

    print('Creating codebook with {} visual words'.format(K))
    codebook = bovw.create_codebook(D, codebook_name='default_codebook')
    print('Elapsed time: {:.2f} s'.format(time.time() - temp))
    temp = time.time()

    print('Getting visual words from training set...')
    vis_words, labels = bovw.visual_words(D, L, I, codebook, spatial_pyramid=True)
    print('Elapsed time: {:.2f} s'.format(time.time() - temp))
    temp = time.time()

    # Train Linear SVM classifier
    print('Training the SVM classifier...')
    pyramid_svm, std_scaler, pca = classification.train_pyramid_svm(vis_words, labels, C=0.0004, dim_reduction=None, model_name='svm_pyramid_dense' )


    print('Elapsed time: {:.2f} s'.format(time.time() - temp))

    temp = time.time()

    # Read the test set
    test_images_filenames, test_labels = io.load_test_set()
    print('Loaded {} test images.'.format(len(test_images_filenames)))

    # Feature extraction with sift, prediction with SVM and aggregation to obtain final class
    print('Predicting test data...')
    test_results = joblib.Parallel(n_jobs=N_JOBS, backend='threading')(
        joblib.delayed(parallel_testing)(test_image, test_label, codebook, pyramid_svm, std_scaler, pca) for
        test_image, test_label in
示例#2
0
    print('Creating codebook with {} visual words'.format(settings.codebook_size))
    #gmm = bovw.create_gmm(D, codebook_name='gmm_{}_dense'.format(settings.codebook_size))
    codebook = bovw.create_codebook(D)
    print('Elapsed time: {:.2f} s'.format(time.time() - temp))
    temp = time.time()

    print('Getting visual words from training set...')
    #fisher, labels = bovw.fisher_vectors(D, L, I, gmm)
    pyramid, labels = bovw.visual_words(D, L, I, codebook, spatial_pyramid=True)
    print('Elapsed time: {:.2f} s'.format(time.time() - temp))
    temp = time.time()

    # Train Linear SVM classifier
    print('Training the SVM classifier...')
    lin_svm, std_scaler, _ = classification.train_pyramid_svm(pyramid, train_labels, C=0.0009, dim_reduction=None)
    print('Elapsed time: {:.2f} s'.format(time.time() - temp))
    temp = time.time()

    # Read the test set
    test_images_filenames, test_labels = io.load_test_set()
    print('Loaded {} test images.'.format(len(test_images_filenames)))

    # Feature extraction with sift, prediction with SVM and aggregation to obtain final class
    print('Predicting test data...')
    test_results = joblib.Parallel(n_jobs=settings.n_jobs, backend='threading')(
        joblib.delayed(parallel_testing)(test_image, test_label, lin_svm, std_scaler) for
        test_image, test_label in
        zip(test_images_filenames, test_labels))

    pred_results = [x[0] for x in test_results]
    codebook = bovw.create_codebook(D)  #, codebook_name='default_codebook'
    print('Elapsed time: {:.2f} s'.format(time.time() - temp))
    temp = time.time()

    print('Getting visual words from training set...')
    vis_words, labels = bovw.visual_words(D,
                                          L,
                                          I,
                                          codebook,
                                          spatial_pyramid=True)
    print('Elapsed time: {:.2f} s'.format(time.time() - temp))
    temp = time.time()

    # Train Linear SVM classifier
    print('Training the SVM classifier...')
    pyramid_svm, std_scaler, pca = classification.train_pyramid_svm(
        vis_words, labels, C=0.0009, dim_reduction=None)

    print('Elapsed time: {:.2f} s'.format(time.time() - temp))
    temp = time.time()

    # Read the test set
    test_images_filenames, test_labels = io.load_test_set()
    print('Loaded {} test images.'.format(len(test_images_filenames)))

    # Feature extraction with sift, prediction with SVM and aggregation to obtain final class
    print('Predicting test data...')
    test_results = joblib.Parallel(
        n_jobs=settings.n_jobs,
        backend='threading')(joblib.delayed(parallel_testing)(
            test_image, test_label, codebook, pyramid_svm, std_scaler, pca)
                             for test_image, test_label in zip(
    print('Getting visual words from training set...')
    vis_words, labels = bovw.visual_words(D,
                                          L,
                                          I,
                                          codebook,
                                          spatial_pyramid=True,
                                          normalization='l1')
    print('Elapsed time: {:.2f} s'.format(time.time() - temp))
    temp = time.time()

    # Train Linear SVM classifier
    print('Training the SVM classifier...')
    pyramid_svm, std_scaler, pca = classification.train_pyramid_svm(
        vis_words,
        labels,
        C=840.42,
        dim_reduction=None,
        model_name='svm_pyramid_l1')

    print('Elapsed time: {:.2f} s'.format(time.time() - temp))

    temp = time.time()

    # Read the test set
    test_images_filenames, test_labels = io.load_test_set()
    print('Loaded {} test images.'.format(len(test_images_filenames)))

    # Feature extraction with sift, prediction with SVM and aggregation to obtain final class
    print('Predicting test data...')
    test_results = joblib.Parallel(n_jobs=N_JOBS, backend='threading')(
        joblib.delayed(parallel_testing)(test_image, test_label, codebook,