示例#1
0
文件: git.py 项目: davisj/figit
 def remove(self, files):
     """Remove files from the repository."""
     self.checkout(self.INSTALLBRANCH)
     out = go("git rm -f %s" % files)
     out += go("git commit -m 'figit: deleted %s'" % files)
     self.checkout(self._init_branch)
     out += self.merge("figit: merging deletion of %s" % files,
                       self._init_branch, self.INSTALLBRANCH)
     return out
示例#2
0
def createRequiredDirs(filenameList,fromFilesDir):
    filesDirList=set(['/'.join(f.split('/')[:-1]) for f in filenameList])
    if fromFilesDir[0]=='+':
        for fd in filesDirList:
            addP=fromFilesDir[1:].split('/')
            addP[-1]=addP[-1]+fd.split('/')[-1]
            go('mkdir -p '+fd+'/'+'/'.join(addP))
    else:
        for fd in filesDirList:
            go('mkdir -p '+fd+'/'+fromFilesDir)
示例#3
0
文件: git.py 项目: davisj/figit
 def initdb(self):
     """Initialize a vcs working directory."""
     out = go('git init-db')  + '\n'
     vcsignorefile = open(self.ignorefile, 'w')
     for pattern in self.ignore_patterns:
         vcsignorefile.write("%s\n" % pattern)
     vcsignorefile.close()
     out += go('git add .')
     out += go("git commit -a -m 'figit: Initial commit.'")
     out += go('git branch %s' % self.INSTALLBRANCH)
     return out
示例#4
0
 def RestartService(self, restart, server = ''):
     '''
     Restarts the ntpd service if requested in ntp_adj.conf.
     Gets: restart (str)
     Returns: N/A
     '''
     if restart.startswith('y'):
         self.logger.debug('[%s] Restarting ntpd...' % Blu('i'))
         #output = go('/etc/init.d/ntpd stop')
         #self.logger.error('[%s] %s' % (Grn('i'), output))
         system('systemctl stop ntpd')
         
         if server != '':
             try:
                 server = eval(server)
             except NameError:
                 pass
             except SyntaxError:
                 pass
             except TypeError:
                 pass
             output = go('/usr/sbin/ntpdate %s' % server)
             self.logger.error('[%s] %s' % (Grn('i'), output))
         else:
             self.logger.debug('[%s] Skipping ntpdate for local syncs' % Blu('i'))
         #output = go('/etc/init.d/ntpd start')
         system('systemctl enable ntpd')
         system('systemctl start ntpd')
         system('timedatectl set-ntp yes')
         #self.logger.error('[%s] %s' % (Grn('i'), output))
     elif restart.startswith('n'):
         self.logger.debug('[%s] Skipping ntpd restart...' % Blu('i'))
示例#5
0
文件: git.py 项目: davisj/figit
 def merge(self, message, to_branch, from_branch):
     self.checkout(to_branch)
     out = go('git merge "%s" %s %s' 
               % (message, to_branch, from_branch))
     if self.branch() != self._init_branch:
         self.checkout(self._init_branch)
     return out
 def getData(self):
     data = go("curl -s -G https://api.spark.io/v1/devices/%s/lab2_data -d access_token=%s" % (self.particle,self.ac))
     data = json.loads(data)
     st = data['result']
     data['result'] =  json.loads(st)
     data['result']['time'] = time.time()
     return data['result']
示例#7
0
文件: git.py 项目: davisj/figit
 def add(self, files):
     """Add new files to the INSTALLBRANCH"""     
     try:
         br = self.branch()
         assert br == self.INSTALLBRANCH
     except AssertionError:
         self.checkout(self.INSTALLBRANCH)
     return go("git add %s" % files)
 def setOutput(self, bit, value):
     """set digital pin number bit to value, where value = 1 is HIGH and value = 0 is LOW"""
     return go(
         'curl -s https://api.particle.io/v1/devices/%s/setOutput \
      -d access_token=%s \
      -d "args=%i%i"'
         % (self.particle, self.ac, bit, value)
     )
示例#9
0
 def GetNet(self, eth = 'bond0', ip = '', netmask = ''):
     '''
     Finds the subnet and netmask of an ethernet device or, if given, finds a subnet
         and netmask of an ip and netmask couple.
     Gets: eth (optional str), ip (optional str), netmask (optional netmask)
     Returns: subnet, netmask (str, str)
     '''
     try:
         if ip == '':
             output = go('ifconfig %s' % eth)
             ip = search('(inet .*)(netmask.*)(broadcast.*)', output).group(1).lstrip('inet').strip() 
             netmask = search('(inet .*)(netmask.*)(broadcast.*)', output).group(2).lstrip('netmask').strip()
             subnet = go('ipcalc -n %s %s' % (ip, netmask)).lstrip('NETWORK=')
         elif ip != '' and netmask != '':
             subnet = go('ipcalc -n %s %s' % (ip, netmask)).lstrip('NETWORK=')
     except AttributeError:
         raise Exception, '[%s] The interface "%s" is not configured...' % (Red('e'), eth)
     return subnet, netmask
示例#10
0
文件: test.py 项目: proger/inspect
def read_udpmem():
    #  ffffffff81cc07a0 D sysctl_udp_mem    long[3]

    data = struct.unpack('@lll',
            kmem_read(kallsyms['sysctl_udp_mem'], 8 * 3))

    # sysctl net.ipv4.udp_mem
    assert map(int, go('sysctl net.ipv4.udp_mem').split('=')[1].split()) == list(data)
    return data
示例#11
0
文件: git.py 项目: davisj/figit
 def branch(self, branchname=None):
     """Create a new branch or report the current branch name."""
     if branchname is None:  # Just report the current branch name.
         try:          
             return open(join(".git", "HEAD")).read().split(sep)[-1].strip()
         except IOError:
             return None
     else:  # Create the named branch.
         return go('git branch %s' % branchname)
 def getData(self):
     """Get current data from sparks"""
     data = go(
         "curl -s -G https://api.spark.io/v1/devices/%s/lab_data -d access_token=%s" % (self.particle, self.ac)
     )
     data = json.loads(data)
     st = data["result"]
     data["result"] = json.loads(st)
     data["result"]["time"] = time.time()
     return data["result"]
示例#13
0
def prelibs(options,toadd):
	lss = [
		'libnss*', 'libnsl*', 'ld-linux.so.2',
	]
	dirs = "/lib /usr/lib"
	for ls in lss:
		fds = go("find " + dirs + " -name \"" + ls + "\" 2> /dev/null")
		if fds != '':
			toadd += fds.split("\n")
	return toadd
示例#14
0
def mkldd(fd,toadd):
	cmd = "ldd " + fd
	ldds = go(cmd).split("\n")
	for ldd in ldds:
		libs = re.split("\s+",ldd)
		for lib in libs:
			if lib != '':
				if lib[0] == '/':
					toadd = testlink(lib,toadd)
	return toadd
示例#15
0
def build_pdir(build_dir):
	pconf = build_dir + "/default.sh"
	cmd = "find " + build_dir + "/* -maxdepth 0 -type d 2> /dev/null"
	print cmd
	sdirs = go(cmd).split("\n")
	if sdirs[-1] != '':
		pdir = sdirs[-1]
	else:
		print "You should unpack software inside of the build dir (" + build_dir + ")."
		usage()
		sys.exit()
	return pconf, pdir
 def setOutputs(self, arr):
     """set all digital pins at once, where 1 is high and 0 is low"""
     if len(arr) != 4:
         return "need exactly four bits"
     else:
         value = ""
         for a in arr:
             value += str(a)
         return go(
             'curl -s https://api.particle.io/v1/devices/%s/setOutputs \
      -d access_token=%s \
      -d "args=%s"'
             % (self.particle, self.ac, value)
         )
示例#17
0
 def setOutput(self, bit, value):
     '''set digital pin number bit to value, where value = 1 is HIGH and value = 0 is LOW'''
     return go('curl -s https://api.particle.io/v1/devices/%s/setOutput \
      -d access_token=%s \
      -d "args=%i%i"' % (self.particle, self.ac, bit, value))
示例#18
0
文件: git.py 项目: davisj/figit
 def commitall(self, message):
     return go("git commit -a -m '%s'" % message)
示例#19
0
文件: git.py 项目: davisj/figit
 def commit(self, message, files):
     return go("git commit -m '%s' %s" % (message, files))
 def getNames(self):
     return go('curl -s https://api.particle.io/v1/devices?access_token=%s' % self.ac)
示例#21
0
                filterIdx).shape[0], ' SURVIVED:', (filterIdx.shape[0])
            LTWHConf = LTWHConf[filterIdx, :]
            transcriptions = transcriptions[filterIdx]
            for k in range(transcriptions.shape[0]):
                resLine = ','.join([str(int(c)) for c in LTWHConf[k, :4]
                                    ]) + ',' + transcriptions[k]
                #print 'MAX RESLINE:',resLine
                res.append(resLine)
            open(ofname, 'w').write('\n'.join(res))

        outDirL = lambda x: 'finalDN%dIou%dVoc%s_%s' % (
            (int(100 * eval(switches['dictnetThr']))),
            (int(100 * eval(switches['iouThr']))), switches['vocDir'].split(
                '_')[-1], x.split('/')[-2])
        [
            go('mkdir -p ' + d)
            for d in set('/'.join(f.split('/')[:-2] + [outDirL(f)])
                         for f in sys.argv[2:])
        ]
        if int(switches['threads']) <= 1:
            [worker(f) for f in sys.argv[2:]]
        else:
            pool = Pool(int(switches['threads']))
            pool.map(worker, sys.argv[2:])
        sys.exit(0)

    if sys.argv[1] == 'gt2SW':
        widths = np.empty([1000000])
        heights = np.empty([1000000])
        objCount = 0
        for fname in sys.argv[2:]:
 def setMotor(self,motor,mode,pwm):
     out = str(motor)+str(mode)+str(pwm).rjust(3,"0")
     return go('curl -s https://api.particle.io/v1/devices/%s/setMotor \
      -d access_token=%s \
      -d "args=%s"' % (self.particle,self.ac,out))
示例#23
0
 def checkout(self, branchname):
     """Switch working directory to branchname."""
     return go('hg checkout %s' % branchname)
示例#24
0
def download(url, fname):
    cmd = 'wget -c ' + url + ' -O ' + fname
    go(cmd)
示例#25
0
#!/usr/bin/python

from commands import getoutput as go
import time,math,sys,numpy
#from __future__ import print_function
import __future__
stat = []
prev_max = 0
counter=0
try:
    f = open("%scwnd" % (sys.argv[1]),'w')
except:
    f = open("cwnd",'w')
try:
    while True:
        x = go("ss -i | grep cwnd");
        a=[]
        for l in x.split("\n"):
            if "cwnd" in l:
                cwnd = int(l.split("cwnd:")[1].split()[0])
                a.append(cwnd)
        # TODO: shift logarithm by 50 points - we never have less than 10 pkt in cwnd
        print("%d %s" % (max(a), "*"*int(math.log(float(max(a)),1.035))))
        f.write("{\"cwnd\":%d,\"time\":%d}\n" % (max(a),counter))
        if max(a) < prev_max:
            stat.append(float(prev_max))
        prev_max = max(a)
        counter = counter + 1
        time.sleep(0.1)
except KeyboardInterrupt:
     f.close()
示例#26
0
文件: killer.py 项目: YakBarber/pithy
#! /usr/bin/python
import sys
from commands import getoutput as go
import re
import os
#get process list

try:
    tokill = sys.argv[1]
except:
    tokill = 'foof'

print tokill
pss = go("ps ax | grep %s" % (tokill))

pss = pss.split("\n")

for p in pss:
    ps = p.split()[0]  #get PID
    print ps
    #get process tree for this process
    tk = go("pstree %s -A -p" % ps.split("/")[-1]).split("\n")[0]
    match = r'\((?:\d*\.)?\d+\)'
    tk = re.findall(match, tk)
    print tk
    #for this process and each subprocess
    for t in tk:
        t = t.replace("(", "").replace(")", "")
        print go("kill -9 %s" % t)
示例#27
0
 def commitall(self, message):
     return go("git commit -a -m '%s'" % message)
示例#28
0
 def commit(self, message, files):
     return go("git commit -m '%s' %s" % (message, files))
示例#29
0
 def diff(self):
     """Return one filename per line. Ignore Added files."""
     return go('git diff --name-only --diff-filter=MRC %s' 
               % self.INSTALLBRANCH).split()
##pithytimeout=0
from commands import getoutput as go
print go("pip install sseclient")
from sseclient import SSEClient
import json
import time
from pymongo import MongoClient as mc

mip = "172.17.0.2"  ##Your MongoDB Address

client = mc(mip, 27017)
#print client
cores = {}

ac = ""  #->Get you token for this from Particle Build
get_event = "MAE_519_LAB_1"

while True:
    try:
        messages = SSEClient(
            'https://api.particle.io/v1/events/%s?access_token=%s' %
            (get_event, ac))
        for msg in messages:
            try:
                foo = msg.data.replace("nan", "NaN")
                total = json.loads(foo)
                data = json.loads(total['data'])
                data['time'] = time.time()
                data['coreid'] = total['coreid']
                try:
                    data['tid'] = client[get_event][
示例#31
0
#!/usr/bin/python

import csv
from commands import getoutput as go

scenes = ['scene1']
thresholds = [2**x for x in range(1, 15)]
runs = 3

for s in scenes:

    ocsv = csv.writer(open(s + '.csv', 'wb'))
    ocsv.writerow(['#threshold'] + ['real'] * runs)

    for t in thresholds:
        cmd = 'time -p ./%s 7 %d +RTS -N7' % (s, t)
        print cmd
        row = [t]
        for run in range(runs):
            done = False
            while not done:
                l = go(cmd).split('\n')
                real = l[0].split()[1]
                try:
                    row.append(float(real))
                    done = True
                except ValueError:
                    print l
        ocsv.writerow(row)
示例#32
0

# PATHS
home = os.path.expanduser("~") + sep
mdir = determine_path()  # Executable path
mdir += sep

misuraServerExe = os.path.join(mdir, 'MisuraServer.pyc')
baseStorageDir = os.path.join(home, 'storage', '')  # Config+Data
baseTmpDir = os.path.join(rootdir, 'tmp', 'misura', '')
baseRunDir = os.path.join(rootdir, 'dev', 'shm', 'misura', '')
testdir = os.path.join(mdir, 'tests', '')  # Test automatizzati

# Detect hardware mac address of this machine
if not isWindows:
    HW = go("ifconfig | grep 'HW' | awk '{ print $5}'|head -n1")
    # Check if netbooted - setup default dir in /opt/machines
    NETBOOTED = go('df -h|grep "/$"|grep ":/var/deploy" >/dev/null; echo $?')
    if NETBOOTED == '0':
        NETBOOTED = True
        baseStorageDir = "/opt/machines/" + HW + '/'
else:
    #TODO: how to find iface info on windows?
    HW = ''
    NETBOOTED = False

# LOGGING
log_basename = 'misura.log'
log_format = '%(levelname)s:%(asctime)s %(message)s'
log_disk_space = 1000 * (10**6)  # Bytes (1GB)
log_file_dimension = 10 * (10**6)  # Bytes (10MB)
示例#33
0
 def worker(imageFname):
     t=time.time()
     open(getProposalFromImage(imageFname),'w').write(go(proposalCmdPath+' '+imageFname))
     print imageFname, ' to ', getProposalFromImage(imageFname), ' ', int((time.time()-t)*1000)/1000.0,' sec.'
示例#34
0
 def worker(imageFname):
     t=time.time()
     open(getProposalFromImage(imageFname),'w').write(go(proposalCmdPath+' '+imageFname))
     print imageFname, ' to ', getProposalFromImage(imageFname), ' ', int((time.time()-t)*1000)/1000.0,' sec.'
示例#35
0
#! /usr/bin/python
import psutil
import sys
from commands import getoutput as go
for p in psutil.get_pid_list():
    i = psutil.Process(p)
    try:
        if i.cmdline[0].find("python") > -1:
            print i.cmdline
            print sys.argv[1]
            if i.cmdline[2].find(sys.argv[1]+".py") > -1:
                print p
                print go("kill "+str(p))
    except Exception as err:
        a = "foo"
示例#36
0
def getIoU(root):
    return [r.split('/')[-1] for r in go('echo '+root+'/*').split(' ') if r.split('/')[-1].startswith('iou_')]
示例#37
0
文件: git.py 项目: davisj/figit
 def checkout(self, branchname):
     """Switch working directory to branchname."""
     return go('git checkout %s' % branchname)
    def runDualFoil(self,
                    debug=False,
                    filename=None,
                    force=False,
                    output=False):
        hh = """   Time     Util N  Util P  Cell Pot   Uocp      Curr      Temp   heatgen
   (min)       x       y      (V)       (V)      (A/m2)    (C)    (W/m2)"""

        try:
            fni = "df_" + self.user + "/dualfoil5.in"
            fno = "df_" + self.user + "/dualfoil5.out"
            ti = os.path.getmtime(fni)
            to = os.path.getmtime(fno)
        except:
            #if something farts above, just make it so we have to
            #run the simulation
            ti = 1
            to = 0

        runs = glob("df_%s/files/*/dualfoil5.in" % self.user)
        same = None
        for run in runs:
            if filecmp.cmp(fni, run) == True and force == False:
                same = run
                rd = run.replace("dualfoil5.in", "")
                go("cp %s/*.out df_%s/" % (rd, self.user))
                if debug: print "same as %s" % run
                if debug: print "not running, pulling previous run"
                return 0

        if debug:
            print "Time Difference Between last input and output:", ti - to, " s"

        if ti > to or force:
            if debug:
                print "input older than output: analysis is not current: running simulation"

            a = go("rm df_" + self.user + "/*.out")
            if debug: print a
            #b = go("cd df_"+self.user+";./dualfoil")
            comm = "cd df_" + self.user + ";./dualfoil"
            b = subprocess.Popen(comm, shell=True)
            if output: print hh
            while b.poll() != 0:
                time.sleep(1)
                if output: print go("tail -n 1 %s" % fno)
            print ""
            if debug: print b
            c = go("mkdir " + "df_" + self.user + "/files/")
            if debug: print c

            if filename == None: filename = "run_" + str(time.time())
            dd = {}
            dd['user'] = self.user
            dd['name'] = "df_" + self.user + "/files/" + filename
            d = go(
                "mkdir -p %(name)s; cp df_%(user)s/*.out %(name)s/; cp df_%(user)s/*.in %(name)s/"
                % dd)
            if debug: print d
        else:
            doo = "foo"
            if debug:
                print "input younger that output: analysis is current: no need to run simulation"
示例#39
0
def countDir(dName,ext='/*'):
    return len(go('echo '+dName+ext).split(' '))
示例#40
0
文件: git.py 项目: davisj/figit
 def merge(self, message, to_branch, from_branch):
     self.checkout(to_branch)
     out = go('git merge "%s" %s %s' % (message, to_branch, from_branch))
     if self.branch() != self._init_branch:
         self.checkout(self._init_branch)
     return out
示例#41
0
import sys

arg = sys.argv[1]
print arg
from commands import getoutput as go

a = arg.split("BREAKKKKK")
dird = ""
fil = a[-1]+".py"
for i in a[:-1]: dird+=i+"/" 
go("mkdir -p code/"+dird)
print dird+fil
print go("cp code/%s.py code/%s/%s" % (arg,dird,fil))
示例#42
0
文件: git.py 项目: davisj/figit
 def diff(self):
     """Return one filename per line. Ignore Added files."""
     return go('git diff --name-only --diff-filter=MRC %s' 
               % self.INSTALLBRANCH).split()
示例#43
0
                filterIdx).shape[0], ' SURVIVED:', (filterIdx.shape[0])
            LTWHConf = LTWHConf[filterIdx, :]
            transcriptions = transcriptions[filterIdx]
            for k in range(transcriptions.shape[0]):
                resLine = ','.join([str(int(c)) for c in LTWHConf[k, :4]
                                    ]) + ',' + transcriptions[k]
                #print 'MAX RESLINE:',resLine
                res.append(resLine)
            open(ofname, 'w').write('\n'.join(res))

        outDirL = lambda x: 'finalDN%dIou%dVoc%s_%s' % (
            (int(100 * eval(switches['dictnetThr']))),
            (int(100 * eval(switches['iouThr']))), switches['vocDir'].split(
                '_')[-1], x.split('/')[-2])
        [
            go('mkdir -p ' + d)
            for d in set('/'.join(f.split('/')[:-2] + [outDirL(f)])
                         for f in sys.argv[2:])
        ]
        if int(switches['threads']) <= 1:
            [worker(f) for f in sys.argv[2:]]
        else:
            pool = Pool(int(switches['threads']))
            pool.map(worker, sys.argv[2:])
        sys.exit(0)

    if sys.argv[1] == 'conf2dictnet':
        import caffe
        download(
            'http://nicolaou.homouniversalis.org/assets/vgg_text/dictnet_vgg_deploy.prototxt',
            switches['proto'])
示例#44
0
    def test_do_backup(self):
        p0 = '/tmp/misuratest/'
        p = p0 + 'source/'
        f = p + 'file'
        p1 = p0 + 'odir/'
        # Clean
        go('rm -rf {}'.format(p0))

        os.makedirs(p)

        open(f, 'w').write('test1')

        of, r = self.s.do_backup(p, p1)
        # Check output
        self.assertTrue(r)
        self.assertIn('./file', r)

        # Check if tar exists
        ls = os.listdir(p1)
        self.assertEqual(len(ls), 1)
        ls1 = ls[0]
        self.assertTrue(ls1.endswith('.tar.bz2'))

        # Change file and try a new backup
        open(f, 'w').write('test2')
        self.s.do_backup(p, p1)
        # Check output
        self.assertTrue(r)
        self.assertIn('./file', r)

        # Check if second tar exists
        ls = os.listdir(p1)
        self.assertEqual(len(ls), 2)
        # Choose the newer one
        ls2 = ls[0]
        if ls2 == ls1:
            ls2 = ls[1]
        self.assertTrue(ls2.endswith('.tar.bz2'))

        # Change again
        open(f, 'w').write('test3')
        # Go in the correct position
        os.chdir('/')
        # Now restore first version
        st, r = self.s.do_restore(p1 + ls1, p)
        print 'Restore 1\n', r
        # Check output
        self.assertTrue(st)
        self.assertIn('./file', r)

        # Check restored file contents
        r = open(f, 'r').read()
        self.assertEqual(r, 'test1')

        # Now restore second version
        st, r = self.s.do_restore(p1 + ls2, p)
        print 'Restore 2\n', r
        # Check output
        self.assertTrue(st)
        self.assertIn('./file', r)

        # Check restored file contents
        r = open(f, 'r').read()
        self.assertEqual(r, 'test2')
        # Clean
        go('rm -rf {}'.format(p0))
示例#45
0
def getConf(root):
    return [r.split('/')[-1] for r in go('echo '+root+'/*').split(' ') if r.split('/')[-1].startswith('conf_')]
def getReport(imgGtSubmFnames, **kwargs):
    #print imgGtSubmFnames
    """imgGtSubmFnames is a list of tuples with three strings:
       The first one is the path to the input image
       The second is the path to the 4point+transcription Gt
       The third is the path to the 4point+transcription Solution
    """
    p = {
        'IoUthreshold': .5,
        'dontCare': '###',
        'visualise': True,
        'outReportDir': '/tmp/report/'
    }
    p.update(kwargs)
    allIoU = []
    allEqual = []
    allCare = []
    accDict = {}
    go('mkdir -p ' + p['outReportDir'])
    startTime = time.time()
    for inImgFname, gtFname, submFname in imgGtSubmFnames:
        sampleFname = p['outReportDir'] + '/' + inImgFname.split(
            '/')[-1].split('.')[0]
        rectSubm, transcrSubm = loadBBoxTranscription(submFname)
        rectGt, transcrGt = loadBBoxTranscription(gtFname)
        rectGt = conv4pointToLTBR(rectGt)
        rectSubm = conv4pointToLTBR(rectSubm)
        print rectSubm
        #rectSubm,transcrSubm,rectGt,transcrGt
        IoU = get2PointIoU(rectGt, rectSubm)[0]
        exactIoU = IoU.copy()
        strEqual = np.zeros([len(transcrSubm), len(transcrGt)])
        strCare = np.zeros([len(transcrSubm), len(transcrGt)])
        for gt in range(transcrGt.shape[0]):
            strCare[:, gt] = (transcrGt[gt] != p['dontCare'])
            for subm in range(transcrSubm.shape[0]):
                strEqual[subm, gt] = (transcrGt[gt] == transcrSubm[subm])
        #IoU[IoU!=IoU.max(axis=0)[None,:]]=0
        IoU = (IoU > p['IoUthreshold']).astype('float')
        allIoU.append(IoU)
        allEqual.append(strEqual)
        allCare.append(strCare)
        img = cv2.imread(inImgFname)
        if p['visualise']:
            plt.imshow(img)
            plt.show()
            plotRectangles(rectGt, transcrGt, img, [0, 255, 0])
            plotRectangles(rectSubm, transcrSubm, img, [255, 0, 0])
            cv2.imwrite(sampleFname + '.png', img)
        else:
            cv2.imwrite(sampleFname + '.png', img)
        resTbl = '<table border=1>\n<tr><td></td><td>'
        resTbl += '</td> <td>'.join([s for s in transcrGt]) + '</tb></tr>\n'
        for k in range(IoU.shape[0]):
            resTbl += '<tr><td>' + transcrSubm[k] + '</td><td>'
            resTbl += '</td><td>'.join([
                str(int(k * 10000) / 100.0) for k in IoU[k, :] * strEqual[k, :]
            ]) + '</td></tr>\n'
        resTbl += '</table>\n'
        resHtml = '<html><body>\n<h3>' + inImgFname.split('/')[-1].split(
            '.')[0] + '</h3>\n'

        acc = ((IoU * strEqual).sum() / float(IoU.shape[1]))
        if p['dontCare'] != '':
            precision = (IoU * strEqual).max(
                axis=1)[(strCare * IoU).sum(axis=1) > 0].mean()
            if np.isnan(precision):
                precision = 0
            recall = (IoU *
                      strEqual).max(axis=0)[(strCare).sum(axis=0) > 0].mean()
            if np.isnan(recall):
                recall = 0
        else:
            precision = (IoU * strEqual).max(axis=1).mean()
            recall = (IoU * strEqual).max(axis=0).mean()
        fm = (2.0 * precision * recall) / (.0000001 + precision + recall)
        accDict[sampleFname + '.html'] = [acc, precision, recall, fm]
        resHtml += '<hr>\n<table><tr>'
        resHtml += '<td>Accuracy : ' + str(
            int(acc * 10000) / 100.0) + '% </td>'
        resHtml += '<td>Precision : ' + str(
            int(precision * 10000) / 100.0) + '% </td>'
        resHtml += '<td>Recall : ' + str(
            int(recall * 10000) / 100.0) + '% </td>'
        resHtml += '<td> FM : ' + str(int(fm * 10000) / 100.0) + '% </td>'
        resHtml += '</tr></table>\n<hr>\n'
        resHtml += '<img src="' + sampleFname + '.png"/>\n<hr>\n' + resTbl
        resHtml += '</body></html>'
        open(sampleFname + '.html', 'w').write(resHtml)
    gtSize = sum([iou.shape[1] for iou in allIoU])
    submSize = sum([iou.shape[0] for iou in allIoU])
    IoU = np.zeros([submSize, gtSize])
    strEqual = np.zeros([submSize, gtSize])
    strCare = np.zeros([submSize, gtSize])
    gtIdx = 0
    submIdx = 0
    for k in range(len(allIoU)):
        submSize, gtSize = allIoU[k].shape
        IoU[submIdx:submIdx + submSize, gtIdx:gtIdx + gtSize] = allIoU[k]
        strEqual[submIdx:submIdx + submSize,
                 gtIdx:gtIdx + gtSize] = allEqual[k]
        strCare[submIdx:submIdx + submSize, gtIdx:gtIdx + gtSize] = allCare[k]
        gtIdx += gtSize
        submIdx += submSize
    acc = ((IoU * strEqual).sum() / float(IoU.shape[1]))
    if p['dontCare'] != '':
        print 'CARE:', (IoU * strCare).sum(axis=1) > 0
        precision = (IoU * strEqual).max(
            axis=1)[(IoU * strCare).sum(axis=1) > 0].mean()
        recall = (IoU * strEqual).max(axis=0)[(strCare).sum(axis=0) > 0].mean()
    else:
        precision = (IoU * strEqual).max(axis=1).mean()
        recall = (IoU * strEqual).max(axis=0).mean()


#    precision=(IoU*strEqual).max(axis=1).mean()
#    recall=(IoU*strEqual).max(axis=0).mean()
    fm = (2.0 * precision * recall) / (.0000001 + precision + recall)
    resHtml = '<body><html>\n<h3>Report on end 2 end</h3>\n'
    resHtml += '<hr>\n<table border=1>'
    resHtml += '<tr><td> Total Samples: </td><td>' + str(
        IoU.shape[1]) + '</td></tr>'
    resHtml += '<tr><td> Detected Samples : </td><td>' + str(
        IoU.shape[0]) + ' </td></tr>'
    resHtml += '<tr><td>Correct Samples : </td><td>' + str(
        int((IoU * strEqual).sum())) + ' </td></tr>'
    resHtml += '<tr><td>Computation Time : </td><td>' + str(
        int(1000 * (time.time() - startTime)) / 1000.0) + ' sec. </td></tr>'
    resHtml += '<tr><td></td><td></td></tr>\n'
    resHtml += '<tr><td>Accuracy : </td><td>' + str(
        int(acc * 10000) / 100.0) + '\% </td></tr>'
    resHtml += '<tr><td>Precision :</td><td> ' + str(
        int(precision * 10000) / 100.0) + '\% </td></tr>'
    resHtml += '<tr><td>Recall : </td><td>' + str(
        int(recall * 10000) / 100.0) + '\% </td></tr>'
    resHtml += '<tr><td> FM : </td><td>' + str(
        int(fm * 10000) / 100.0) + '\% </td></tr>'
    resHtml += '</table>\n<hr>\n'
    resHtml += '<table><tr><td>sample</td><td>Acc</td><td>Precision</td><td>Recall</td><td>FMeasure</td><tr>\n'
    for sampleFname in accDict.keys():
        fname = sampleFname.split('/')[-1]
        acc, pr, rec, fm = accDict[sampleFname]
        resHtml += '<tr><td><a href="' + fname + '">' + fname.split(
            '.')[0] + '</a></td><td>' + str(int(10000 *
                                                (acc)) / 100.0) + '%</td><td>'
        resHtml += str(int(10000 * (pr)) / 100.0) + '%</td><td>' + str(
            int(10000 * (rec)) / 100.0) + '%</td><td>' + str(
                int(10000 * (fm)) / 100.0) + '%</td></tr>\n'
    resHtml += '</table></body></html>'
    open(p['outReportDir'] + 'index.html', 'w').write(resHtml)
示例#47
0
def getHeatmaps(root):
    return [r.split('/')[-1] for r in go('echo '+root+'/*').split(' ') if r.split('/')[-1].startswith('hm')]
示例#48
0
 def get_eq_mac(self):
     all_mac = go("ifconfig | grep 'HW' | awk '{ print $5}'")
     return all_mac