Exemplo n.º 1
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()
    #Instantiation classification detection, incoming om model path, model input width and height parameters
    classify = Classify(acl_resource, MODEL_PATH, MODEL_WIDTH, MODEL_HEIGHT)

    #Get the picture storage directory from the parameters, and infer picture by 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 IMG_EXT
    ]

    #Create a directory and save the infer results
    if not os.path.isdir(os.path.join(SRC_PATH, "../outputs")):
        os.mkdir(os.path.join(SRC_PATH, "../outputs"))

    for image_file in images_list:
        #read the picture
        image = AclImage(image_file)
        image_dvpp = image.copy_to_dvpp()
        #preprocess image
        resized_image = classify.pre_process(image_dvpp)
        print("pre process end")
        #inference
        result = classify.inference(resized_image)
        #post process
        classify.post_process(result, image_file)
Exemplo n.º 2
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()
    #Instance classification detection, pass into the OM model storage path, model input width and height parameters
    classify = Classify(acl_resource, MODEL_PATH, MODEL_WIDTH, MODEL_HEIGHT)

    #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 IMG_EXT
    ]

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

    resized_image_list = []
    batch_image_files = []
    num = 0
    batch_amount = len(images_list) // BATCH
    left = len(images_list) % BATCH

    for image_file in images_list:
        num += 1
        #Read the pictures
        image = AclImage(image_file)
        image_dvpp = image.copy_to_dvpp()
        #preprocess image
        resized_image = classify.pre_process(image_dvpp)
        print("pre process end")

        batch_image_files.append(image_file)
        resized_image_list.append(resized_image)
        if batch_amount > 0:
            #Each set of BATCH pictures, reasoning and post-processing
            if num == BATCH:
                #Reasoning pictures
                result = classify.inference(resized_image_list, BATCH)
                #process inference results
                classify.post_process(result, batch_image_files, BATCH)
                batch_amount -= 1
                num = 0
                batch_image_files = []
                resized_image_list = []
        else:
            #remaining images are inferred and post-processed
            if num == left:
                #Reasoning pictures
                result = classify.inference(resized_image_list, BATCH)
                #The inference results are processed
                classify.post_process(result, batch_image_files, left)