示例#1
0
文件: nDCG.py 项目: toeybaa/FCN
def anconvert(d, l, inpath):
  #  print inpath
    path = '/home/peth/Databases/rPascal/features/caffe/queries/'
    finput = inpath + '.npy'
    check = True
    isfileaf = glob.glob("/home/peth/Databases/rPascal/features/nDCG/*.txt")
    isfilebf = glob.glob('/home/peth/Databases/rPascal/features/caffe/queries/*.npy')
    if len(isfileaf) == len(isfilebf):
        check = False
        return tosort(inpath, l)
    if check and len(isfileaf) < len(isfilebf):
        for fname in sorted(os.listdir(path)):
            if finput == fname:
                file = open("/home/peth/Databases/rPascal/features/nDCG/" + inpath + ".txt", 'w')
                for key in d:
                    # print key
                    if inpath == key:
                        value = d[key]
                        for element in value:
                            dist = str(dist_cal(key, element))
                            ref = str(element).rstrip(".jpg")
                            file.write(ref)
                            file.write(" ")
                            file.write(dist)
                            file.write("\n")
                file.close()
                print 'All reference and distance of ' + str(inpath) + " is written"
        return tosort(inpath, l)
示例#2
0
文件: nDCG.py 项目: toeybaa/FCN
def convert(d):
    print "Processing all images in dataset... "
    dict = OrderedDict()
    dict2 = OrderedDict()
    for key in d:
        value = d[key]
        min_dist = dist_cal(key, value[0])
        min_y = str(value[0])
        for element in value:
            dist = dist_cal(key, element)
            if dist <= min_dist:
                query = str(key)
                min_dist = dist
                min_y = str(element).rstrip(".jpg")
        print "Processing query: " + (query) + " <=> Most similar image is: " + (min_y) + " <=> Distance is: " + str(min_dist)
        dict[query] = min_y
        dict2[query] = str(min_dist)
    # print dict
    print "Dataset processing finished... "
    savepair(dict)
    savedist(dict2)
    print "Dataset successfully created. "