def testImage(self): print "Testing!" self.queue.put("Working...") nImage = image.resize((200, 150), Image.NEAREST) imgArr = numpy.asarray(nImage) t = time.time() j = numpy.array(ExtractCharacters.LabelPixels(imgArr), dtype=numpy.uint8) print time.time() - t imagesWithCenters = ExtractCharacters.PasteCharacters(imgArr, j) numbers = [] if alreadyWorking.locked(): alreadyWorking.release() for imageWCenter in imagesWithCenters: testVec = map(norm, convert.getFeatureVecFromImg(imageWCenter[0])) if alreadyWorking.locked(): return #another thread has come into play! with lock: net.ClearNodes() net.SetInputs(testVec) rawOutputs = net.ComputeOutput() outputString = str(rawOutputs.index(max(rawOutputs))) numbers.append((imageWCenter[1], outputString)) numbers.sort() numbers = "".join(map(lambda elem: elem[1], numbers)) print numbers self.queue.put("Neural network read: " + numbers) print "done testing"
def testImage(self): print "Testing!" self.queue.put("Working...") nImage = image.resize((200,150),Image.NEAREST) imgArr = numpy.asarray(nImage) t = time.time() j = numpy.array(ExtractCharacters.LabelPixels(imgArr),dtype=numpy.uint8) print time.time()-t imagesWithCenters = ExtractCharacters.PasteCharacters(imgArr,j) numbers = [] if alreadyWorking.locked(): alreadyWorking.release() for imageWCenter in imagesWithCenters: testVec = map(norm,convert.getFeatureVecFromImg(imageWCenter[0])) if alreadyWorking.locked(): return #another thread has come into play! with lock: net.ClearNodes() net.SetInputs(testVec) rawOutputs = net.ComputeOutput() outputString = str(rawOutputs.index(max(rawOutputs))) numbers.append((imageWCenter[1],outputString)) numbers.sort() numbers = "".join(map(lambda elem: elem[1], numbers)) print numbers self.queue.put("Neural network read: " + numbers) print "done testing"
def TestNumber(testVec): testVec = map(norm,convert.getFeatureVecFromImg(testVec)) net.ClearNodes() net.SetInputs(testVec) rawOutputs = net.ComputeOutput() outputs = map (Indicator,net.ComputeOutput()) print "Confidence Values:" print ("\n" + fspace).join(textwrap.wrap(fspace+str(rawOutputs).ljust(10))) print "Greatest Confidence:" print fspace + str(rawOutputs.index(max(rawOutputs))) + " with " + str(100*max(rawOutputs)) + "% confidence" print return rawOutputs.index(max(rawOutputs))
def testDigit(self): print "Testing!" try: featureVec = map(norm, convert.getFeatureVecFromImg(image)) except: return with lock: net.ClearNodes() net.SetInputs(featureVec) rawOutputs = net.ComputeOutput() outputs = map(Indicator, rawOutputs) roundedOutputs = map(lambda x: "%.3f" % round(x, 3), rawOutputs) outputString = "Confidence Values:\n" + \ tabspace+str(roundedOutputs).ljust(10) + "\n" + \ "Greatest Confidence:\n" + \ tabspace + str(rawOutputs.index(max(rawOutputs))) + " with %3.3f" % (100*max(rawOutputs)) + "% confidence" self.queue.put(outputString) print "done testing"
def testDigit(self): print "Testing!" try: featureVec = map(norm,convert.getFeatureVecFromImg(image)) except: return with lock: net.ClearNodes() net.SetInputs(featureVec) rawOutputs = net.ComputeOutput() outputs = map (Indicator,rawOutputs) roundedOutputs = map (lambda x: "%.3f" % round (x,3),rawOutputs) outputString = "Confidence Values:\n" + \ tabspace+str(roundedOutputs).ljust(10) + "\n" + \ "Greatest Confidence:\n" + \ tabspace + str(rawOutputs.index(max(rawOutputs))) + " with %3.3f" % (100*max(rawOutputs)) + "% confidence" self.queue.put(outputString) print "done testing"