Exemple #1
0
parser.add_argument("--test", type=str, help='load test data (optional)')

args = parser.parse_args()
print "Training data load from {}".format(args.train)
print "Test data load from {}".format(args.test)

X, y = load_my_data(args.train)

# to save time...
X = X[:200]
y = y[:200]

print "Codebook Size: {:d}".format(spm.VOC_SIZE)
print "Pyramid level: {:d}".format(spm.PYRAMID_LEVEL)
print "Dense SIFT feature extraction"
x_feature = [extract_DenseSift_descriptors(img) for img in X]
x_kp, x_des = zip(*x_feature)

print "Building the codebook, it will take some time"
codebook = build_codebook(x_des, spm.VOC_SIZE)
#import cPickle
#with open('./data/codebook_spm.pkl','w') as f:
#    cPickle.dump(codebook, f)

print "Spatial Pyramid Matching encoding"
X = [spm.spatial_pyramid_matching(X[i],
                              x_des[i],
                              codebook,
                              level=spm.PYRAMID_LEVEL)
                              for i in xrange(len(x_des))]
Exemple #2
0
Fichier : spm.py Projet : CS534/SVM

VOC_SIZE = 100
PYRAMID_LEVEL = 1

DSIFT_STEP_SIZE = 4
# DSIFT_STEP_SIZE is related to the function
# extract_DenseSift_descriptors in utils.py
# and build_spatial_pyramid in spm.py

if __name__ == '__main__':
    x_train, y_train = load_cifar10_data(dataset='train')
    x_test, y_test = load_cifar10_data(dataset='test')

    print("Dense SIFT feature extraction")
    x_train_feature = [extract_DenseSift_descriptors(img) for img in x_train]
    x_test_feature = [extract_DenseSift_descriptors(img) for img in x_test]
    x_train_kp, x_train_des = zip(*x_train_feature)
    x_test_kp, x_test_des = zip(*x_test_feature)

    print("Train/Test split: {:d}/{:d}".format(len(y_train), len(y_test)))
    print("Codebook Size: {:d}".format(VOC_SIZE))
    print("Pyramid level: {:d}".format(PYRAMID_LEVEL))
    print("Building the codebook, it will take some time")
    codebook = build_codebook(x_train_des, VOC_SIZE)
    # import cPickle
    #
    # with open('./spm_lv1_codebook.pkl', 'w') as f:
    #     cPickle.dump(codebook, f)

    print("Spatial Pyramid Matching encoding")
Exemple #3
0
VOC_SIZE = 200
PYRAMID_LEVEL = 2

DSIFT_STEP_SIZE = 4
# DSIFT_STEP_SIZE is related to the function
# extract_DenseSift_descriptors in utils.py
# and build_spatial_pyramid in spm.py


if __name__ == '__main__':

    x_train, y_train = load_cifar10_data(dataset='train')
    x_test, y_test = load_cifar10_data(dataset='test')

    print "Dense SIFT feature extraction"
    x_train_feature = [extract_DenseSift_descriptors(img) for img in x_train]
    x_test_feature = [extract_DenseSift_descriptors(img) for img in x_test]
    x_train_kp, x_train_des = zip(*x_train_feature)
    x_test_kp, x_test_des = zip(*x_test_feature)

    print "Train/Test split: {:d}/{:d}".format(len(y_train), len(y_test))
    print "Codebook Size: {:d}".format(VOC_SIZE)
    print "Pyramid level: {:d}".format(PYRAMID_LEVEL)
    print "Building the codebook, it will take some time"
    codebook = build_codebook(x_train_des, VOC_SIZE)
    import cPickle
    with open('./spm_lv1_codebook.pkl','w') as f:
        cPickle.dump(codebook, f)

    print "Spatial Pyramid Matching encoding"
    x_train = [spatial_pyramid_matching(x_train[i],