www.pudn.com > firev0.01.rar > firev01.cgi


#!/usr/bin/python
print "Content-Type: text/html\n\n"
print
print "
"
import socket
import cgi
import re
import sys
import traceback
import os
from types import *

TemplateFile = "fire-template.html"
fireServer="europium"
firePort=12960
sys.stderr=sys.stdout

PRGRAPHDATFILE="/u/deselaers/data/PRGRAPH.DAT"
PRGRAPHDEMFILE="/u/deselaers/ir/src/cgi/prgraph.dem"
PRGRAPHPNGFILE="/u/deselaers/data/PRGRAPH.png"

def Display(Content):
    TemplateHandle = open(TemplateFile, "r")  # open in read only mode
    # read the entire file as a string
    TemplateInput = TemplateHandle.read() 
    TemplateHandle.close()                    # close the file

    # this defines an exception string in case our
    # template file is messed up
    BadTemplateException = "There was a problem with the HTML template."

    SubResult = re.subn("INSERT CONTENT HERE",Content,TemplateInput)
    if SubResult[1] == 0:
        raise BadTemplateException
    print SubResult[0]

def processForm(form):
    #processing form input
    for i in form.keys():
        if i=="retriever":
            retriever=form[i].value
            s.sendcmd("set retriever "+retriever)
            s.getResult()
        elif i.find("dist")==0:
            no=i[4:]
            dist=form[i].value
            s.sendcmd("set dist "+no+" "+dist)
            s.getResult()
        elif i.find("weight")==0:
            no=i[6:]
            weight=form[i].value
            s.sendcmd("set weight "+no+" "+weight)
            s.getResult()
        elif i=="database":
            database=form[i].value
            s.sendcmd("loadlist "+database)
            s.getResult()
        elif i=="results":
            results=form[i].value
            s.sendcmd("set results "+results)
            s.getResult()

def processStatus(msg, form):
    #processing status report
    noList=[]
    distNameList=[]
    suffixList=[]
    weightList=[]
    output=""
    retriever=""
    dist=""
    database=""
    results=""
    filelist=""
    testfile=""
    perfevalparams="fire -perf "    
    for line in re.split("\n",msg):
        line=re.sub("[ ]*","",line)
        linelist=re.split(":",line)
        if linelist[0]=="results":
            results=linelist[1]
            perfevalparams=perfevalparams+" -results "+str(results)
        elif linelist[0]=="dist":
            no=int(linelist[1])
            name=linelist[2]
            suffix=linelist[3]
            weight=linelist[4]
            if name != "basedist":
                perfevalparams=perfevalparams+" -dist"+str(no)+" "+name+" -weight"+str(no)+" "+weight+" "
            noList=noList+[no]
            distNameList=distNameList+[name]
            suffixList=suffixList+[suffix]
            weightList=weightList+[weight]
        elif linelist[0]=="filelist":
            database=linelist[1]
            perfevalparams=perfevalparams+"-filelist "+database
        elif linelist[0]=="testfile":
            testfile=linelist[1]

    output=output+"

Settings for fire on "+fireServer+":"+str(firePort)+"

" output=output+"""
\n""" output=output+"\n" output=output+"\n" output=output+"\n" for distNo in noList: output=output+"\n" output=output+"\n" output=output+"\n" output=output+"\n" output=output+"" output=output+"" output=output+"""""" output=output+"" output=output+"" output=output+"\n\n" output=output+"""\n""" output=output+"" output=output+"\n" output=output+"\n" output=output+"""""" output=output+"""""" output=output+"
Distance "+str(distNo)+""+suffixList[distNo]+"""" output=output+"Weight: "+distNameList[distNo]+"
Results"+results+"
Database"+database+"
params for perfeval"+perfevalparams+"
 
" output=output+"
\n" output=output+"
" return output def processQuery(msg): output="" for key in form.keys(): # image by filename if key=="queryfile": queryimage=form[key].value s.sendcmd("retrieve "+queryimage) msg=s.getResult() queryresult=processRetrieved(msg) output=output+"

Query result

\n" output=output+" query was: "+queryimage+"\n" output=output+queryresult output=output+"\n
\n" # image from "random-list" selected if key=="queryimage": queryimage=form[key].value s.sendcmd("retrieve "+queryimage) msg=s.getResult() queryresult=processRetrieved(msg) output=output+"

Query result

\n" output=output+" query was: "+queryimage+"\n" output=output+queryresult output=output+"\n
\n" # images from old result selected and "requerried" if key=="queryimagespos": field=form[key] queryimagespos=[] if type(field) ==ListType: for subfield in field: queryimagespos.append(subfield.value) else: queryimagespos.append(field.value) cmdopt="" for i in queryimagespos: cmdopt=cmdopt+" +"+i if form.has_key("queryimagesneg"): field=form["queryimagesneg"] queryimagesneg=[] if type(field) == ListType: for subfield in field: queryimagesneg.append(subfield.value) else: queryimagesneg.append(field.value) for i in queryimagesneg: cmdopt=cmdopt+" -"+i s.sendcmd("retrievemulti"+cmdopt) msg=s.getResult() queryresult=processRetrieved(msg) output=output+"

Query result

\n" output=output+" query was: "+cmdopt+"\n" output=output+queryresult output=output+"\n
\n" #generate query randomlist output=output+"

Query

" output=output+"""
""" output=output+"\n" output=output+"\n" output=output+"""
""" output=output+"
\n" output=output+"\n" output=output+"\n" output=output+"\n" s.sendcmd("randomentries") msg=s.getResult() n=0 for i in re.split("\n",msg): if i!="": output=output+"\n" # output=output+"\n\n" # output=output+"
" return output #process the result of a query-task def processRetrieved(msg): prgraphHandle=open(PRGRAPHDATFILE,"w") statistics="" description="" output="

Results

\n" output=output+"
\n" output=output+"\n" output=output+"\n" output=output + "" n=0 for line in re.split("\n",msg): linelist=re.split("[ ]*",line) if(linelist[0]=="statistics"): statistics="

Statistics

" rank1=linelist[1] precision20=linelist[2] precision50=linelist[3] precisionNR=linelist[4] recall100=linelist[5] recallp05=linelist[6] ranktilde=linelist[7] equalerrorrate=linelist[8] prarea=linelist[9] time=linelist[10] statistics=statistics+"
\n" statistics=statistics+"\n" statistics=statistics+"\n" statistics=statistics+"\n" statistics=statistics+"\n" statistics=statistics+"\n" statistics=statistics+"\n" statistics=statistics+"\n" statistics=statistics+"\n" statistics=statistics+"\n" statistics=statistics+"\n" statistics=statistics+"
Rank1 "+rank1 +"
AvgRank "+ranktilde +"
Precision(20) "+precision20 +"
Precision(50) "+precision50 +"
Precision(NR) "+precisionNR +"
Recall(100) "+recall100 +"
Recall(P==0.5)"+recallp05 +"
EqualErrorRate"+equalerrorrate+"
PRArea "+prarea +"
Time[ms] "+time +"
\n" elif(linelist[0]=="prgraph"): prgraphHandle.write(linelist[2]+" "+linelist[1]+"\n") elif(len(linelist) >= 3): description="" if(n%5==0): output=output+"\n" number=linelist[1] distance=linelist[2] filename=linelist[3] cls="-1" if(len(linelist) >4): cls=linelist[4] if(len(linelist) >5): for i in linelist[5:]: description=description+" "+i imgname=re.sub(".greyfeat","",filename) imgname=re.sub("\.[xX].*-rgbfeat","",imgname) imgname=re.sub(".rgbfeat","",imgname) imgname=re.sub(".mdhisto","",imgname) imgname=re.sub("25x25/","25x25/",imgname) imgname=re.sub("-tnrgb.png","",imgname) imgname=re.sub("-tngrey.png","",imgname) imgname=re.sub("\.ar","",imgname) imgname=re.sub("-tn32x32","",imgname) imgname=re.sub(".gz","",imgname) output=output+"\n\n\n\n\n" output=output+"\n\n\n" output=output+"\n\n\n" output=output+"\n" output=output+"\n" output=output+"\n" output=output+"
" output=output+"
" output=output+"
\n"+imgname+"
Description: "+description+"
Number: "+number+"
\"Probabilty\": "+distance+"
\"Class\": "+cls+"
good " output=output+"
bad " output=output+"
\n\n" if(n%5==4): output=output+"\n" n=n+1 prgraphHandle.close() cmdline="gnuplot "+PRGRAPHDEMFILE os.popen(cmdline) output=output + "" output=output+"
"+statistics+"
" output=output+"" output=output+"
\n" return output class mysocket: '''Socket stolen somewhere from the net''' def __init__(self, sock=None): if sock is None: self.sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM) else: self.sock = sock def connect(self,host, port): self.sock.connect((host, port)) def send(self,msg): totalsent = 0 MSGLEN=len(msg) while totalsent < MSGLEN: sent = self.sock.send(msg[totalsent:]) if sent == 0: raise RuntimeError, "socket connection broken" totalsent = totalsent + sent def sendcmd(self,cmd): cmd = cmd + "\r\n" self.send(cmd) def getResult(self): result="" line="" while line[0:3] != "end": line=self.getline() if line[0:3] != "end": result=result+line return result def receive(self): msg = '' while len(msg) < MSGLEN: chunk = self.sock.recv(MSGLEN-len(msg)) if chunk == '': raise RuntimeError, "socket connection broken" msg = msg + chunk return msg def getline(self): msg='' chunk='a' while chunk != '\n': chunk=self.sock.recv(1) if chunk == '': raise RuntimeError, "socket connection broken" msg=msg+chunk return msg #----------------------------------------------------------- form=cgi.FieldStorage() status="" query="" output="" s = mysocket() if form.has_key("server"): fireServer=form["server"].value if form.has_key("port"): firePort=int(form["port"].value) try: s.connect(fireServer, firePort) except: message="""

FIRE Server down, try again later or complain: thomas@deselaers.de

Or try others:

  1. hassium:12960
  2. europium:12960
  3. hassium:12961
  4. europium:12961
  5. uran:12960
  6. """ print "
" Display(message) else: processForm(form) s.sendcmd("status") msg=s.getResult() status=processStatus(msg, form) query=processQuery(msg) print "
" simple="
simple interface
" Display(status+query+output+simple) s.sendcmd("bye\r\n")