Beispiel #1
0
def extract_from_indices_file():
    base_output_dir = (
        "/mnt/data/tiny_images/py-tiny-image-access/loaded_images/cifar100"
    )
    # the first 50'000 indices are for training
    train_dir = base_output_dir + "/train"
    # the last 10'000 indices are for testing
    test_dir = base_output_dir + "/test"

    tinyimage.openTinyImage()
    cifar100_indices = get_indices()
    for i, index in enumerate(progressbar(cifar100_indices)):
        if i < 50000:
            output_dir = train_dir
        else:
            output_dir = test_dir
        meta = tinyimage.getMetaData(index)
        tinyimage.sliceToImage(tinyimage.sliceToBin(index), output_dir + "/" + meta[1])
    tinyimage.closeTinyImage()
Beispiel #2
0
means = []
convergence = 10
max_iterations = 5

#get the samples
samples = []

print "Loading images..."

tinyimage.openTinyImage()

for keyword in keywords:
	indexes = tinyimage.retrieveByTerm(keyword, max_pics)	
	temp = []
	for indx in indexes:
		samples.append(tinyimage.sliceToBin(indx).reshape(32,32,3, order="F"))

tinyimage.closeTinyImage()

print str(len(samples)) + " samples loaded..."
print "Seeding..."

#select random seeds from the samples
for i in range(0, cluster_count):
	r = random.randint(0, max_pics * cluster_count)
	means.append(numpy.empty(cluster_dimension))
	means[i][:] = samples[r]

#perform k means
print "Clustering..."
a1 = assignclusters(means, samples)
import sys
sys.path.append("/home/charles/PyTinyImage")
import tinyimage as tinyimage
import leargist
import scipy
import struct

start = int(sys.argv[1])
stop = int(sys.argv[2])

f = open('/mnt/ti-%i.gists' % start, "w+")

tinyimage.openTinyImage()

for i in xrange(start, stop):
	s = tinyimage.sliceToBin(i)
	image = scipy.misc.toimage(s.reshape(32,32,3, order="F").copy())
	gist = leargist.color_gist(image)	
	print len(gist)
	f.write(struct.pack('f' * 960, *gist))
	print "Remaining: %i" % (stop - i)

tinyimage.closeTinyImage()
f.close()
Beispiel #4
0
		for label in f:
			labels.append(label.rstrip())
	return labels


def get_indices():
	indices = []
	with open('./indices_cifar100','r') as f:
		for index in f:
			indices.append(int(index.rstrip()))
	return indices


if __name__ == "__main__":
	keywords = get_labels()
	tinyimage.openTinyImage()
	images = []
	ignore_indices = get_indices()
	pick = len(ignore_indices)
	for keyword in progressbar(keywords):
		indexes = tinyimage.retrieveByTerm(keyword)
		for i in indexes:
			if i not in ignore_indices:
				image = tinyimage.sliceToBin(i).reshape(32,32,3, order="F").astype('float32') / 255.
				images.append(image)
	relevant = np.array(images)
	np.random.shuffle(relevant)
	relevant = relevant[:pick]
	np.save("relevant_images",relevant)
	tinyimage.closeTinyImage()
Beispiel #5
0
import sys
import os
import tinyimage

if (len(sys.argv) < 4):
  print "usage: python loadFromKeywords <keyword,keyword,keyword,...> <max> <output path>"
  sys.exit(1)


#todo - start here
keywords = sys.argv[1].split(',')
max_pics = int(sys.argv[2])
output_path = sys.argv[3]

tinyimage.openTinyImage()

for keyword in keywords:
	os.mkdir(output_path+"/"+keyword)
	indexes = tinyimage.retrieveByTerm(keyword, max_pics)
	for i in indexes:
		tinyimage.sliceToImage(tinyimage.sliceToBin(i), output_path+"/"+keyword +"/"+str(i)+".png") 			

tinyimage.closeTinyImage()


import sys
import os
import tinyimage

if (len(sys.argv) < 4):
    print "usage: python loadFromKeywords <keyword,keyword,keyword,...> <max> <output path>"
    sys.exit(1)

#todo - start here
keywords = sys.argv[1].split(',')
max_pics = int(sys.argv[2])
output_path = sys.argv[3]

tinyimage.openTinyImage()

for keyword in keywords:
    os.mkdir(output_path + "/" + keyword)
    indexes = tinyimage.retrieveByTerm(keyword, max_pics)
    for i in indexes:
        tinyimage.sliceToImage(
            tinyimage.sliceToBin(i),
            output_path + "/" + keyword + "/" + str(i) + ".png")

tinyimage.closeTinyImage()
Beispiel #7
0
import sys
import os
import tinyimage

if len(sys.argv) < 4:
    print(
        "usage: python loadFromKeywords <keyword,keyword,keyword,...> <max> <output path>"
    )
    sys.exit(1)

keywords = sys.argv[1].split(",")
max_pics = int(sys.argv[2])
output_path = sys.argv[3]

tinyimage.openTinyImage()

for keyword in keywords:
    keyword_output_dir = output_path + "/" + keyword
    if not os.path.exists(keyword_output_dir):
        os.mkdir(keyword_output_dir)

    indexes = tinyimage.retrieveByTerm(keyword, max_pics)
    for i in indexes:
        tinyimage.sliceToImage(tinyimage.sliceToBin(i),
                               keyword_output_dir + "/" + str(i) + ".png")

tinyimage.closeTinyImage()