コード例 #1
0
ファイル: select_anno.py プロジェクト: Peratham/jingwei
if __name__ == '__main__':
    args = sys.argv[1:]
    rootpath = '/var/scratch2/xirong/VisualSearch'
    srcCollection = args[0]
    annotationName = args[1]
    dstCollection = args[2]
    overwrite = 0

    concepts = readConcepts(srcCollection, annotationName, rootpath)
    todo = []
    for concept in concepts:
        resfile = os.path.join(rootpath, dstCollection, 'Annotations', 'Image', annotationName, '%s.txt'%concept)
        if checkToSkip(resfile, overwrite):
            continue
        todo.append(concept)
    if not todo:
        print ('nothing to do')
        sys.exit(0)


    imset = set(readImageSet(dstCollection, dstCollection, rootpath))

    for concept in todo:
        names,labels = readAnnotationsFrom(srcCollection, annotationName, concept, rootpath=rootpath)
        selected = [x for x in zip(names,labels) if x[0] in imset]
        print concept, len(selected)
        writeAnnotationsTo([x[0] for x in selected], [x[1] for x in selected], dstCollection, annotationName,  concept, rootpath=rootpath)

    writeConceptsTo(concepts, dstCollection, annotationName, rootpath)
コード例 #2
0
ファイル: combineAnnotations.py プロジェクト: xiaojiew1/KDGAN
    for concept in concepts:
        simfile = os.path.join(rootpath, collection, 'SimilarityIndex',
                               collection, 'tagged,lemm', tagrelMethod,
                               '%s.txt' % concept)
        searchresults = readRankingResults(simfile)
        searchresults = [x for x in searchresults if x[0] not in holdoutSet]
        positiveSet = [x[0] for x in searchresults[:numPos]]

        for t in range(T):
            newAnnotationName = sourceAnnotationName % t
            newAnnotationName = newAnnotationName.replace(
                'rand%d.0' % numPos, posName)
            names, labels = readAnnotationsFrom(collection,
                                                sourceAnnotationName % t,
                                                concept, rootpath)

            negativeSet = [x[0] for x in zip(names, labels) if -1 == x[1]]
            renamed = positiveSet + negativeSet
            relabeled = [1] * len(positiveSet) + [-1] * len(negativeSet)
            print('[%s] %s +%d, -%d -> %s' %
                  (concept, sourceAnnotationName % t, len(positiveSet),
                   len(negativeSet), newAnnotationName))
            writeAnnotationsTo(renamed, relabeled, collection,
                               newAnnotationName, concept, rootpath)

    for t in range(T):
        newAnnotationName = sourceAnnotationName % t
        newAnnotationName = newAnnotationName.replace('rand%d.0' % numPos,
                                                      posName)
        writeConceptsTo(concepts, collection, newAnnotationName, rootpath)
コード例 #3
0
    overwrite = 0

    concepts = readConcepts(srcCollection, annotationName, rootpath)
    todo = []
    for concept in concepts:
        resfile = os.path.join(rootpath, dstCollection, 'Annotations', 'Image',
                               annotationName, '%s.txt' % concept)
        if checkToSkip(resfile, overwrite):
            continue
        todo.append(concept)
    if not todo:
        print('nothing to do')
        sys.exit(0)

    imset = set(readImageSet(dstCollection, dstCollection, rootpath))

    for concept in todo:
        names, labels = readAnnotationsFrom(srcCollection,
                                            annotationName,
                                            concept,
                                            rootpath=rootpath)
        selected = [x for x in zip(names, labels) if x[0] in imset]
        print concept, len(selected)
        writeAnnotationsTo([x[0] for x in selected], [x[1] for x in selected],
                           dstCollection,
                           annotationName,
                           concept,
                           rootpath=rootpath)

    writeConceptsTo(concepts, dstCollection, annotationName, rootpath)
コード例 #4
0
    #tagrelMethod = 'flickr1m/ccgd,knn,1000'

    concepts = readConcepts(collection, sourceAnnotationName%0, rootpath)

    holdoutfile = os.path.join(rootpath, collection, "ImageSets", "holdout.txt") 
    holdoutSet = set(map(str.strip, open(holdoutfile).readlines()))
    print ('%s holdout %d' % (collection,len(holdoutSet)))
 
    for concept in concepts:
        simfile = os.path.join(rootpath, collection, 'SimilarityIndex', collection, 'tagged,lemm', tagrelMethod, '%s.txt' % concept)
        searchresults = readRankingResults(simfile)
        searchresults = [x for x in searchresults if x[0] not in holdoutSet]
        positiveSet = [x[0] for x in searchresults[:numPos]]
                
        for t in range(T):
            newAnnotationName = sourceAnnotationName % t
            newAnnotationName = newAnnotationName.replace('rand%d.0'%numPos, posName)
            names,labels = readAnnotationsFrom(collection,sourceAnnotationName%t,concept,rootpath)
            
            negativeSet = [x[0] for x in zip(names,labels) if -1 == x[1]]
            renamed = positiveSet + negativeSet
            relabeled = [1] * len(positiveSet) + [-1] * len(negativeSet)
            print ('[%s] %s +%d, -%d -> %s' % (concept,sourceAnnotationName % t,len(positiveSet),len(negativeSet),newAnnotationName)) 
            writeAnnotationsTo(renamed, relabeled, collection, newAnnotationName, concept, rootpath)
            
    for t in range(T):
        newAnnotationName = sourceAnnotationName % t
        newAnnotationName = newAnnotationName.replace('rand%d.0'%numPos, posName)
        writeConceptsTo(concepts, collection, newAnnotationName, rootpath)