Exemplo n.º 1
0
 def uiStartStopServices(self, row):
     lf = tk.LabelFrame(self, text='Control CVAC Services:')
     lf.grid(row=row, columnspan=5, sticky="ew")
     self.serverStatus = tk.StringVar()
     self.dataDir = easy.getFSPath("", abspath=True)
     row = row + 1
     self.startButton = tk.Button(lf, text='start services', 
                              bg="light blue", width=12,
                              command=lambda: self.startStopServices(True))
     self.startButton.grid(row=0, sticky=tk.W, padx=5)
     self.stopButton = tk.Button(lf, text='stop services', 
                              bg="light blue", width=12,
                              command=lambda: self.startStopServices(False))
     self.stopButton.grid(row=0, column=1, padx=5)
     self.statusButton = tk.Button(lf, text='status', 
                              bg="light blue", width=12,
                              command=lambda: self.runServerStatus())
     self.statusButton.grid(row=0, column=2, padx=5, sticky=tk.E)
     tk.Label(lf, text="Service Status:").grid(row=2, sticky=tk.W)
     statusLabel = tk.Label(lf, textvariable=self.serverStatus)
     statusLabel.grid(row=2, column=1, pady=5, columnspan=4, sticky=tk.W)
     tk.Label(lf, text="Data Dir:").grid(row=3, sticky=tk.W)
     dirText = tk.Text(lf, width=38, height=1)
     dirText.insert(tk.END, self.dataDir)
     dirText.configure(state=tk.DISABLED, relief='groove', wrap='char',
                       borderwidth=2)
     dirText.grid(row=3, column=1, columnspan=4, sticky=tk.W)
     toolTip = ToolTip(dirText, text=self.dataDir, wraplength=600, 
                       delay=1000)
     if sys.platform!='win32':
         checkButton = tk.Checkbutton(lf, text= 'Show services output',
                                       variable=self.checkVar)
         checkButton.grid(row=5, columnspan=5, sticky=tk.W)
     return row
Exemplo n.º 2
0
 def getLabels(self):
     # todo: this is a very preliminary implementation that
     # doesn't do any error checking or create proper temp directories;
     # it mainly just works with a remote tar.gz type corpus file
     import urllib
     import tarfile
     urlfile = urllib.URLopener()
     urlfile.retrieve( self.main_location, "deleteme.tar.gz" )
     # extract the tar into a hardcoded dir path
     extractinto = easy.getFSPath( "deleteme_tmpdir" )
     if not os.path.exists(extractinto):
         os.makedirs(extractinto)
     tar = tarfile.open("deleteme.tar.gz")
     tar.extractall(path=extractinto)
     tar.close()
     # obtain labelables from extracted tar directory
     return easy.getLabelableList(extractinto)
Exemplo n.º 3
0
 def addCorpusFromConfig(self, cvacPath):
     propFile = easy.getFSPath( cvacPath )
     # since our config file does not have sections and we need one so we
     # create a string with the required header and file contents
     # and pass that to the parser
     with open(propFile, 'r') as f:     
         fileStr = '[main]\n' + f.read()
         str_fp = StringIO.StringIO(fileStr)
     config = ConfigParser.RawConfigParser()
     # Tell parser not to convert keys to lower case!
     config.optionxform = str
     config.readfp(str_fp)
     configProps = config._sections['main']
     corpus = self.parseCorpusProperties(configProps, propFile)
     if corpus == None:
         return None
     corp = self.corpToImp.get(corpus.name)
     if corp == None:
         self.corpToImp[corpus.name] = corpus
         return corpus
     else:
         return corpus
Exemplo n.º 4
0
easy.printRunSetInfo(trainset, printLabels=True)

#
# Connect to the trainer for a Bag of Words algorithm, then
# train with the given runset
#
print("starting training, this might take a few minutes...")
trainer = easy.getTrainer("BOW_Trainer")
trainedModel = easy.train(trainer, trainset)

#
# Display information about the file in which the model is stored;
# this is generally no concern to algorithm users and only of
# interest to algorithm developers since it is algorithm-specific
#
zipfname = easy.getFSPath(trainedModel)
print("{0}".format(zipfname))
zipf = zipfile.ZipFile(zipfname)
print("Training model stored in file {0}".format(zipfname))
# print("file contents:\n{0}".format(zipf.namelist()))

#
# test the trained model on a separate set of images
#
print("==== Test runset: ====")
testset = easy.createRunSet("testImg")
easy.printRunSetInfo(testset, printLabels=True)
detector = easy.getDetector("BOW_Detector")
results = easy.detect(detector, trainedModel, testset)
print("==== Results: ====")
easy.printResults(results)
Exemplo n.º 5
0
#
# detect remotely: note the host specification
#
detector = easy.getDetector("OpenCVCascadeDetector:default -p 10102 " + host)
results = easy.detect(detector, modelfile, rs1)
easy.printResults(results)

#
# Example 2:
# Train on a remote machine, obtain the model file, and test locally.
# Assume the files are on the remote machine, or transfer with putAllFiles.
# If no local services are installed, this will be skipped.
#
print("------- Remote training, local detection: -------")
try:
    detector = easy.getDetector(
        "BOW_Detector:default -p 10104")  # local service
    trainer = easy.getTrainer("BOW_Trainer:default -p 10103 " + host)  # remote
    trainset = easy.createRunSet("trainImg")
    trainedModel = easy.train(trainer, trainset)
    easy.getFile(fileserver, trainedModel)  # downloads the model from remote
    print("obtained trained detector, stored in file {0}".format(
        easy.getFSPath(trainedModel)))
    testset = easy.createRunSet("testImg", "UNPURPOSED")
    results = easy.detect(detector, trainedModel, testset)
    easy.printResults(results)
except:
    print("Cannot connect to local detector.  Have you started the services?\n"\
          "This part of the demo does not work with the client-only distribution.")
Exemplo n.º 6
0
print("------- Remote detection, local result display: -------")
fileserver = easy.getFileServer( "PythonFileService:default -p 10111 " + host )
putResult = easy.putAllFiles( fileserver, rs1 )
modelfile = "detectors/haarcascade_frontalface_alt.xml"
if not fileserver.exists( easy.getCvacPath(modelfile) ):
    easy.putFile( fileserver, easy.getCvacPath(modelfile) )

#
# detect remotely: note the host specification
#
detector = easy.getDetector( "OpenCVCascadeDetector:default -p 10102 "+host )
results = easy.detect( detector, modelfile, rs1 )
easy.printResults( results )

#
# Example 2:
# Train on a remote machine, obtain the model file, and test locally.
# Assume the files are on the remote machine, or transfer with putAllFiles.
#
print("------- Remote training, local detection: -------")
trainer = easy.getTrainer( "BOW_Trainer:default -p 10103 "+ host) # remote
trainset = easy.createRunSet( "trainImg" );
trainedModel = easy.train( trainer, trainset )
easy.getFile( fileserver, trainedModel )  # downloads the model from remote
print("obtained trained detector, stored in file {0}"
      .format(easy.getFSPath(trainedModel)))
detector = easy.getDetector( "BOW_Detector:default -p 10104" ) # local service
testset = easy.createRunSet("testImg","UNPURPOSED"  )
results = easy.detect( detector, trainedModel, testset )
easy.printResults( results )
Exemplo n.º 7
0
correct = easy.isProperRunSet(trainset, deleteInvalid=True)
if not correct:
    print("failed Integrity test!!!!")
    exit()
#trainset = easy.createRunSet( categories, purpose=posPurpose );
#easy.printRunSetInfo( trainset, printLabels=True )
easy.printRunSetInfo( trainset )

#
# Connect to the trainer for a Bag of Words algorithm, then
# train with the given runset
#
#trainer = easy.getTrainer( "BOW_Trainer")
trainer = easy.getTrainer( "BOW_Trainer:default -p 10103")
trainedModel = easy.train( trainer, trainset )
zipfname = easy.getFSPath( trainedModel )
print("Training model stored in file {0}".format( zipfname ))

#
# test the trained model on a separate set of images
#
print("==== Test runset: ====")
testset = easy.createRunSet( "testImg" )
easy.printRunSetInfo( testset, printLabels=True )
detector = easy.getDetector( "BOW_Detector" )
results = easy.detect( detector, trainedModel, testset )
print("==== Results: ====")
easy.printResults( results )


Exemplo n.º 8
0
#
# Make sure all files in the RunSet are available on the remote site;
# it is the client's responsibility to upload them if not.
#
host = "-h localhost"
#host = "-h vision.nps.edu"
fileserver = easy.getFileServer( "FileService:default -p 10110 " + host )
putResult = easy.putAllFiles( fileserver, runset )

#
# Connect to a trainer service, train on the RunSet
#
trainer = easy.getTrainer( "bowTrain:default -p 10103 " + host )
trainedModel = easy.train( trainer, runset )
print("Training model stored in file: " + easy.getFSPath( trainedModel.file ))

#
# Connect to a detector service,
# test on the training RunSet for validation purposes;
# The detect call takes the detector, the trained model, the
# runset, and a mapping from purpose to label name
#
detector = easy.getDetector( "bowTest:default -p 10104 " + host )
results = easy.detect( detector, trainedModel, runset )
easy.printResults( results, foundMap=classmap )

easy.deleteAllFiles( fileserver, putResult['uploaded'] )

quit()