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

    print('Getting Fisher vectors from training set...')
    fisher, labels = bovw.fisher_vectors(D, L, I, gmm)
    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_linear_svm(fisher, train_labels, C=1, 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, gmm, pca) for
        test_image, test_label in
        zip(test_images_filenames, test_labels))

    pred_results = [x[0] for x in test_results]
    pred_class = [x[1] for x in test_results]
    pred_prob = [x[2] for x in test_results]

    num_correct = np.count_nonzero(pred_results)
    print('Elapsed time: {:.2f} s'.format(time.time() - temp))
Exemple #2
0
weigths_file = '/home/master/santi/weights/final_system_full.hdf5'

""" CONSTANTS """
test_data_dir = './dataset/MIT_split/test'
img_width = 224
img_height = 224

# Hyperparameters
dropout = 0.5
regularization = 0.01
batch_size = 20
lr = 1e-5
optimizer = Adam(lr=lr)

""" TEST DATASET """
test_images, test_labels = io.load_test_set()

""" MODEL """
# Get the base pre-trained model
base_model = VGG16(weights='imagenet', include_top=False, input_shape=(img_width, img_height, 3))

# Get output from last convolutional layer in block 4
x = base_model.get_layer('block4_conv3').output
x = MaxPooling2D(pool_size=(4, 4))(x)
x = Flatten(name='flat')(x)
x = Dense(2048, activation='relu', name='fc', W_regularizer=l2(regularization))(x)
x = Dropout(dropout)(x)
x = Dense(2048, activation='relu', name='fc2', W_regularizer=l2(regularization))(x)
x = Dropout(dropout)(x)
x = Dense(8, activation='softmax', name='predictions')(x)