#!/usr/bin/python # -*- coding: iso-8859-1 -*- # Program for checking your submission to the automatic annotation # task # # © Thomas Deselaers # if you have any questions write me an email # # this program is called with the confidences file as parameter and # gives the classification decision for each of the files # # the input files have to be of the following format: # you can have comment lines (starting with #) # # ... # ... # ... # # please put contact details (especially your email into a comment line) before submitting import sys,string def USAGE(): print """USAGE: readconfidencefile [options] Options: -c file with necessary numbers and optionally correct classes """ sys.exit(10) def readclassfile(filename): f=open(filename,"r") files={} for l in f: tokens=string.split(l) filename="" for i in tokens[0]: if i.isdigit(): filename+=i filename=int(filename) if len(tokens)>1: files[filename]=int(tokens[1]) else: files[filename]=0 return files def main(): ## command line processing: sys.argv.pop(0) classfile="notdefined" conffile="notdefined" while len(sys.argv)>0: arg=sys.argv.pop(0) if arg=="-c": if classfile=="notdefined": classfile=sys.argv.pop(0) else: print "only once classfile allowed" USAGE() else: if conffile=="notdefined": conffile=arg else: print "only one confidence file allowed" USAGE() print "conffile="+conffile,"classfile="+classfile ## read files if conffile=="notdefined": USAGE() classesmap={} if classfile!="notdefined": classesmap=readclassfile(classfile) f=open(conffile) # init confusionmatrix confusionmatrix=[] for i in range(116): vec=[] for j in range(116): vec+=[0] confusionmatrix+=[vec] # init classfrequencies={} for i in range(116): classfrequencies[i]=0 classified=0; wrong=0; correct=0; illegal=0; illegalfiles=[] for line in f: if line[0]!='#': tokens=string.split(line) if len(tokens)!=117: print "Not the right number of confidences. Expected 116, got",len(tokens)-1," for image '"+str(tokens[0])+"'." filename="" for i in tokens[0]: if i.isdigit(): filename+=i fileno=int(filename) tokens=map(lambda token: float(token),tokens[1:]) cls=tokens.index(max(tokens))+1 print fileno,"is classified as",cls, classified+=1 if len(classesmap)>0 and not classesmap.has_key(fileno): print fileno,"is not expected to be classified" illegalfiles+=[fileno] illegal+=1 else: clsright=classesmap[fileno] classesmap.pop(fileno) if clsright!=0: if clsright==cls: print "correct" correct+=1 else: print "wrong, should be",clsright wrong+=1 confusionmatrix[clsright-1][cls-1]+=1 classfrequencies[clsright-1]+=1 else: print print "classified:",classified,"wrong:",wrong,"correct:",correct,"illegal:",illegal,"missing:",len(classesmap) if len(illegalfiles)>0: print "illegal files:", illegalfiles if len(classesmap)>0: print "missing files:", classesmap.keys() main()