Beispiel #1
0
def main():
    """main"""
    #acl init
    if (len(sys.argv) != 2):
        print("The App arg is invalid")
        exit(1)
    acl_resource = AclResource()
    acl_resource.init()
    model = Model(MODEL_PATH)
    dvpp = Dvpp(acl_resource)

    #From the parameters of the picture storage directory, reasoning by a picture
    image_dir = sys.argv[1]
    images_list = [
        os.path.join(image_dir, img) for img in os.listdir(image_dir)
        if os.path.splitext(img)[1] in const.IMG_EXT
    ]

    if not os.path.isdir(os.path.join(SRC_PATH, "../outputs")):
        os.mkdir(os.path.join(SRC_PATH, "../outputs"))

    #infer picture
    for pic in images_list:
        #get pic data
        orig_shape, l_data = preprocess(pic)

        #inference
        result_list = model.execute([l_data])

        #postprocess
        postprocess(result_list, pic, orig_shape, pic)
    print("Execute end")
Beispiel #2
0
def main():
    if (len(sys.argv) != 2):
        print("The App arg is invalid")
        exit(1)

    acl_resource = AclResource()
    acl_resource.init()
    model = Model(MODEL_PATH)
    dvpp = Dvpp(acl_resource)

    image_dir = sys.argv[1]
    images_list = [
        os.path.join(image_dir, img) for img in os.listdir(image_dir)
        if os.path.splitext(img)[1] in const.IMG_EXT
    ]

    #Create a directory to store the inference results
    if not os.path.isdir(os.path.join(SRC_PATH, "../outputs")):
        os.mkdir(os.path.join(SRC_PATH, "../outputs"))

    image_info = construct_image_info()
    for image_file in images_list:
        image = AclImage(image_file)
        resized_image = pre_process(image, dvpp)
        print("pre process end")

        result = model.execute([
            resized_image,
        ])
        post_process(result, image_file)

        print("process " + image_file + " end")
Beispiel #3
0
def main():
    """
    Program execution with picture directory parameters
    """
    
    if (len(sys.argv) != 2):
        print("The App arg is invalid")
        exit(1)
    
    acl_resource = AclResource()
    acl_resource.init()
    model = Model(MODEL_PATH)
    dvpp = Dvpp(acl_resource)
    
    #From the parameters of the picture storage directory, reasoning by a picture
    image_dir = sys.argv[1]
    images_list = [os.path.join(image_dir, img)
                   for img in os.listdir(image_dir)
                   if os.path.splitext(img)[1] in const.IMG_EXT]
    #Create a directory to store the inference results
    if not os.path.isdir('../outputs'):
        os.mkdir('../outputs')

    image_info = construct_image_info()

    for image_file in images_list:
        #read picture
        image = AclImage(image_file)
        #preprocess image
        resized_image = pre_process(image, dvpp)
        print("pre process end")
        #reason pictures
        result = model.execute([resized_image, image_info])    
        #process resresults
        post_process(result, image, image_file)
Beispiel #4
0
 def __init__(self, acl_resource, model_width, model_height):
     self._acl_resource = acl_resource
     self._model_width = model_width
     self._model_height = model_height
     #Use dvpp to process images, when using opencv or PIL,
     # you don't need to create a dvpp instance
     self._dvpp = Dvpp(acl_resource)
Beispiel #5
0
 def init(self):    
     """
     init
     """ 
     self._dvpp = Dvpp() 
     self._model = Model(self._model_path)
 
     return constants.SUCCESS
Beispiel #6
0
    def init(self):
        """
        Initialize
        """
        self._dvpp = Dvpp()
        # Load model
        self._model = Model(self._model_path)

        return const.SUCCESS
Beispiel #7
0
    def _thread_entry(self, args_list):     
        self._context, ret = acl.rt.create_context(0)
        utils.check_ret("acl.rt.create_context", ret)
        self._cap = video.AclVideo(self._stream_name)
        self._dvpp = Dvpp() 
        self._status = STATUS_PREPROC_RUNNING
        frame_cnt = 0
        while self._status == STATUS_PREPROC_RUNNING: 
            ret, image = self._cap.read()
            if ret or (image is None):
                if ret == const.VIDEO_DECODE_FINISH:
                    log_info("Video %s decode finish"%(self._stream_name))
                    self._status = STATUS_PREPROC_EXIT
                else:
                    log_info("Video %s decode failed"%(self._stream_name))
                    self._status = STATUS_PREPROC_ERROR
                break
            if (int(frame_cnt) % 5 == 0):
                self._process_frame(image)  
            time.sleep(0.0)

        self._thread_exit()        
Beispiel #8
0
def main():
    """main"""
    if (len(sys.argv) != 2):
        print("The App arg is invalid")
        exit(1)

    acl_resource = AclResource()
    acl_resource.init()
    model = Model(MODEL_PATH)
    dvpp = Dvpp(acl_resource)

    image_dir = sys.argv[1]
    images_list = [
        os.path.join(image_dir, img) for img in os.listdir(image_dir)
        if os.path.splitext(img)[1] in const.IMG_EXT
    ]

    # Create a directory to save inference results
    if not os.path.isdir('./outputs'):
        os.mkdir('./outputs')

    # Create a directory to save the intermediate results of the large image detection
    if not os.path.isdir('./bigpic'):
        os.mkdir('./bigpic')

    # Create a directory to save the results of the big picture cropping inference
    outCrop = os.path.join('./bigpic', 'output')
    if not os.path.isdir(outCrop):
        os.mkdir(outCrop)

    # Create a directory, save the large and cropped pictures
    cropImg = os.path.join('./bigpic', 'cropimg')
    if not os.path.isdir(cropImg):
        os.mkdir(cropImg)

    image_info = construct_image_info()

    for image_file in images_list:
        imagename = get_file_name(image_file)
        tempfile = os.path.splitext(imagename)[0]

        imgdic = {}
        imgdic['name'] = imagename
        obj_res = []

        img = cv2.imread(image_file, -1)
        (width, height, depth) = img.shape
        if width > 1000 and height > 1000:
            # Create a directory to save the divided pictures of each big picture
            crop_target = os.path.join(cropImg, tempfile)
            if not os.path.isdir(crop_target):
                os.mkdir(crop_target)

            # Create a directory to save the inference results of each large image
            out_target = os.path.join(outCrop, tempfile)
            if not os.path.isdir(out_target):
                os.mkdir(out_target)

            # Large image clipping function
            crop_picture(image_file, crop_target)
            cropimg_list = [
                os.path.join(crop_target, imgs)
                for imgs in os.listdir(crop_target)
                if os.path.splitext(imgs)[1] in const.IMG_EXT
            ]

            # After the execution of the crop function is over,
            # the small picture after the big picture crop should be saved in a folder crop_target
            for cropimg_file in cropimg_list:
                print("the crop filename is :\t", cropimg_file)
                image = AclImage(cropimg_file)
                resized_image = pre_process(image, dvpp)
                result = model.execute([resized_image, image_info])
                resdic = post_process_big(result, image, cropimg_file,
                                          out_target)
                obj_res.extend(resdic)

            imgdic['object_result'] = obj_res

            merge_picture(out_target, tempfile)

        # Read in the picture, if the picture size is less than 1000x1000,
        # it will be read in and processed normally
        else:
            print("detect the small picture")
            image = AclImage(image_file)
            resized_image = pre_process(image, dvpp)
            print("pre process end")
            result = model.execute([resized_image, image_info])
            resdic = post_process(result, image, image_file)
            obj_res.extend(resdic)
            imgdic['object_result'] = obj_res