def __init__(self): # data structure self.data = [] self.features = [] self.width = 27 self.height = 27 self.featureExtractor = AutoEncoderFeatureExtractor( self.width, self.height) self.processor = PreProcessor() self.driver = ProbDriver()
def get_data_from_susig_file(fileName): preProcessor = PreProcessor() print "Getting data from %s" % fileName X = [] Y = [] P = [] with open(fileName) as fp: lines = fp.readlines() for line in lines[2:]: items = line.split() x = float(items[0]) y = float(items[1]) p = float(items[3]) X.append(x) Y.append(y) P.append(p) X, Y = preProcessor.size_normalization(X, Y, 400, 200) return X, Y, P
def inference(bmodel_path, input_path, loops, tpu_id, compare_path): """ Load a bmodel and do inference. Args: bmodel_path: Path to bmodel input_path: Path to input file loops: Number of loops to run tpu_id: ID of TPU to use compare_path: Path to correct result file Returns: True for success and False for failure """ # init Engine to load bmodel and allocate input and output tensors engine = sail.Engine(bmodel_path, tpu_id, sail.SYSIO) # init preprocessor and postprocessor preprocessor = PreProcessor([127.5, 127.5, 127.5], 0.0078125) postprocessor = PostProcessor([0.5, 0.3, 0.7]) reference = postprocessor.get_reference(compare_path) status = True # pipeline of inference for i in range(loops): # read image image = cv2.imread(input_path) image = cv2.transpose(image) # run PNet, the first stage of MTCNN boxes = run_pnet(engine, preprocessor, postprocessor, image) if boxes is not None and len(boxes) > 0: # run RNet, the second stage of MTCNN boxes = run_rnet(engine, preprocessor, postprocessor, boxes, image) if boxes is not None and len(boxes) > 0: # run ONet, the third stage of MTCNN boxes = run_onet(engine, preprocessor, postprocessor, boxes, image) # print detected result if postprocessor.compare(reference, boxes, i): print_result(boxes, tpu_id) else: status = False break return status
def __init__(self): self.svmProcessor = SVMProcessor() self.probFeatureExtractor = ProbFeatureExtractor() self.preProcessor = PreProcessor()
def test_pre_processor(): file = get_file("tests/test_sample/82251504.png") new_file = PreProcessor(100).run(file) assert type(new_file) == io.BytesIO
def test_ocr_processor(): file = get_file("tests/test_sample/82251504.png") fixed_text = ocr_precess(file, PreProcessor(100), OCRTesseractProcessor(), PostProcessor()) assert type(fixed_text) == str