Exemple #1
0
parser.add_argument("--dcompress",
                    help="Number of dimensions to compress "
                    "features to.",
                    type=int,
                    default=None)
parser.add_argument("--npatches",
                    help="Number of image patches to use to learn"
                    " dictionary.",
                    type=int,
                    default=200000)
args = parser.parse_args()

# Make a list of images
filelist = glob.glob(os.path.join(args.imagedir, '*.' + args.extension))

nimages = len(filelist)
print "Found {0} images.".format(nimages)
if nimages == 0:
    print "Quiting..."
    sys.exit(1)

# Train a dictionary
desc = ScSPM(dsize=args.nbases, compress_dim=args.dcompress)
desc.learn_dictionary(filelist, npatches=args.npatches, niter=5000)

# Save the dictionary
with open(args.dicname, 'wb') as f:
    pk.dump(desc, f, protocol=2)

print "Done! Dictionary object saved to {0}.".format(args.dicname)
from imdescrip.extractor import extract_smp
from imdescrip.descriptors.ScSPM import ScSPM


# Make a list of images
imgdir   = '/home/dsteinberg/Datasets/Tas2008_12/Images/'
savdir   = '/home/dsteinberg/Datasets/Tas2008_12/Images/imdesc/'
filelist = glob.glob(imgdir + '*.png')

#imgdir  = '/home/dsteinberg/Datasets/outdoor_scenes/Images/'
#savdir  = '/home/dsteinberg/Datasets/outdoor_scenes/Images/imdesc/'
#filelist += glob.glob(imgdir + '*.jpg')

#imgdir   = '/home/dsteinberg/Datasets/Caltech101_sub/'
#filelist += glob.glob(imgdir + '*.jpg')
#print len(filelist)

# Train a dictionary
desc = ScSPM(dsize=512, compress_dim=None)
desc.learn_dictionary(filelist, npatches=200000, niter=5000)

# Save the dictionary
with open('ScSPM.p', 'wb') as f:
    pk.dump(desc, f, protocol=2)

# OR Load a pre-learned dictionary 
#with open('ScSPM.p', 'rb') as f:
    #desc = pk.load(f)

extract_smp(filelist, savdir, desc, verbose=True) 
Exemple #3
0
import cPickle as pk
from imdescrip.extractor import extract_smp
from imdescrip.descriptors.ScSPM import ScSPM

# Make a list of images
imgdir = '/home/dsteinberg/Datasets/Tas2008_12/Images/'
savdir = '/home/dsteinberg/Datasets/Tas2008_12/Images/imdesc/'
filelist = glob.glob(imgdir + '*.png')

#imgdir  = '/home/dsteinberg/Datasets/outdoor_scenes/Images/'
#savdir  = '/home/dsteinberg/Datasets/outdoor_scenes/Images/imdesc/'
#filelist += glob.glob(imgdir + '*.jpg')

#imgdir   = '/home/dsteinberg/Datasets/Caltech101_sub/'
#filelist += glob.glob(imgdir + '*.jpg')
#print len(filelist)

# Train a dictionary
desc = ScSPM(dsize=512, compress_dim=None)
desc.learn_dictionary(filelist, npatches=200000, niter=5000)

# Save the dictionary
with open('ScSPM.p', 'wb') as f:
    pk.dump(desc, f, protocol=2)

# OR Load a pre-learned dictionary
#with open('ScSPM.p', 'rb') as f:
#desc = pk.load(f)

extract_smp(filelist, savdir, desc, verbose=True)
parser.add_argument("extension", help="Image file extension (eg. 'png').")
parser.add_argument("--dicname", help="Name and path of dictionary file to " 
                    "save.", default="ScSPM.p")
parser.add_argument("--nbases", help="Number of dictionary bases.", type=int, 
                    default=512)
parser.add_argument("--dcompress", help="Number of dimensions to compress "
                    "features to.", type=int, default=None)
parser.add_argument("--npatches", help="Number of image patches to use to learn"
                    " dictionary.", type=int, default=200000)
args = parser.parse_args()

# Make a list of images
filelist = glob.glob(os.path.join(args.imagedir, '*.' + args.extension))

nimages = len(filelist)
print "Found {0} images.".format(nimages)
if nimages == 0:
    print "Quiting..."
    sys.exit(1)

# Train a dictionary
desc = ScSPM(dsize=args.nbases, compress_dim=args.dcompress)
desc.learn_dictionary(filelist, npatches=args.npatches, niter=5000)

# Save the dictionary
with open(args.dicname, 'wb') as f:
    pk.dump(desc, f, protocol=2)

print "Done! Dictionary object saved to {0}.".format(args.dicname)