Beispiel #1
0
def process(options, collection, annotationName):
    rootpath = options.rootpath
    overwrite = options.overwrite

    concepts = readConcepts(collection,annotationName,rootpath)
    resultdir = os.path.join(rootpath, collection, "SimilarityIndex", "ngd")

    todo = [x for x in concepts if not os.path.exists(os.path.join(resultdir,x+'.txt')) or overwrite]
    if not todo:
        printStatus(INFO, 'nothing to do')
        return

    fcs = FlickrContextSim(collection, rootpath=rootpath)
    vob = fcs.vob
    resultdir = os.path.join(rootpath, collection, "SimilarityIndex", "ngd")
    printStatus(INFO, 'expanding tags for %s-%s -> %s' % (collection, annotationName, resultdir))
    
    for concept in todo:
        resultfile = os.path.join(resultdir, concept + '.txt')
            
        vals = []
        for tag in vob:
            dist = fcs.computeNGD(concept, tag, img=1)
            if dist < 10:
                vals.append((tag,dist))
        vals.sort(key=lambda v:v[1])
        printStatus(INFO, '%s -> %s' % (concept, ' '.join([x[0] for x in vals[:3]])))
        writeRankingResults(vals, resultfile)
Beispiel #2
0
def process(options, collection, annotationName):
    rootpath = options.rootpath
    overwrite = options.overwrite

    concepts = readConcepts(collection, annotationName, rootpath)
    resultdir = os.path.join(rootpath, collection, "SimilarityIndex", "ngd")

    todo = [
        x for x in concepts
        if not os.path.exists(os.path.join(resultdir, x + '.txt')) or overwrite
    ]
    if not todo:
        printStatus(INFO, 'nothing to do')
        return

    fcs = FlickrContextSim(collection, rootpath=rootpath)
    vob = fcs.vob
    resultdir = os.path.join(rootpath, collection, "SimilarityIndex", "ngd")
    printStatus(
        INFO, 'expanding tags for %s-%s -> %s' %
        (collection, annotationName, resultdir))

    for concept in todo:
        resultfile = os.path.join(resultdir, concept + '.txt')

        vals = []
        for tag in vob:
            dist = fcs.computeNGD(concept, tag, img=1)
            if dist < 10:
                vals.append((tag, dist))
        vals.sort(key=lambda v: v[1])
        printStatus(INFO,
                    '%s -> %s' % (concept, ' '.join([x[0] for x in vals[:3]])))
        writeRankingResults(vals, resultfile)
Beispiel #3
0
class AvgCombinedSim:
    def __init__(self, collection, rootpath=ROOT_PATH):
        self.wnsim = WordnetSim("wup")
        self.fcsim = FlickrContextSim(collection, rootpath)

    def compute(self, tagx, tagy, gamma=None, img=1):
        fcs = self.fcsim.compute(tagx, tagy, gamma, img)
        wns = self.wnsim.compute(tagx, tagy)
        return (fcs + wns) * 0.5
class AvgCombinedSim:
    
    def __init__(self, collection, rootpath=ROOT_PATH):
        self.wnsim = WordnetSim("wup")
        self.fcsim = FlickrContextSim(collection, rootpath)
        
    def compute(self, tagx, tagy, gamma=None, img=1):
        fcs = self.fcsim.compute(tagx, tagy, gamma, img)
        wns = self.wnsim.compute(tagx, tagy)
        return (fcs + wns) * 0.5
 def __init__(self, collection, rootpath=ROOT_PATH):
     self.wnsim = WordnetSim("wup")
     self.fcsim = FlickrContextSim(collection, rootpath)
Beispiel #6
0
 def __init__(self, collection, rootpath=ROOT_PATH):
     self.wnsim = WordnetSim("wup")
     self.fcsim = FlickrContextSim(collection, rootpath)
Beispiel #7
0
        fcs = self.fcsim.compute(tagx, tagy, gamma, img)
        wns = self.wnsim.compute(tagx, tagy)
        return (fcs + wns) * 0.5


class MulCombinedSim(AvgCombinedSim):
    def compute(self, tagx, tagy, gamma=None, img=1):
        fcs = self.fcsim.compute(tagx, tagy, gamma, img)
        wns = self.wnsim.compute(tagx, tagy)
        return fcs * wns


if __name__ == "__main__":

    collection = 'train10k'
    fcs = FlickrContextSim(collection)
    avgcos = AvgCombinedSim(collection)
    mulcos = MulCombinedSim(collection)
    wns = WordnetSim('wup')

    tags = str.split(
        'nature waterfall mountain 2012 bmw airshow jet airport beach food dog car cat animal street'
    )
    for tagx in tags:
        for simclass in [wns, fcs, avgcos, mulcos]:
            taglist = [(tagy, simclass.compute(tagx, tagy))
                       for tagy in tags]  # fcs.vob]
            taglist.sort(key=lambda v: v[1], reverse=True)
            print '%s(%s)' % (simclass.__class__.__name__, tagx), ' '.join(
                ['%s %g' % (x[0], x[1]) for x in taglist[:10]])
            print ''