Example #1
0
    def post_process(self, infer_output, image_file):
        """
	    post_process
        """
        print("post process")
        data = infer_output[0]
        vals = data.flatten()
        top_k = vals.argsort()[-1:-6:-1]
        print("images:{}".format(image_file))
        print("======== top5 inference results: =============")
        for n in top_k:
            object_class = image_net_classes.get_image_net_class(n)
            print("label:%d  confidence: %f, class: %s" %
                  (n, vals[n], object_class))

        #using pillow, the category with the highest confidence is written on the image and saved locally
        if len(top_k):
            object_class = image_net_classes.get_image_net_class(top_k[0])
            output_path = os.path.join(os.path.join(SRC_PATH, "../outputs"),
                                       os.path.basename(image_file))
            origin_img = Image.open(image_file)
            draw = ImageDraw.Draw(origin_img)
            font = ImageFont.load_default()
            draw.text((10, 50), object_class, font=font, fill=255)
            origin_img.save(output_path)
Example #2
0
def postprocess(infer_output, image_file):
    """
    post_process
    """
    print("post process")
    data = infer_output[0]
    vals = data.flatten()
    max_val = np.max(vals)
    vals = np.exp(vals - max_val)
    sum_val = np.sum(vals)
    vals /= sum_val

    top_k = vals.argsort()[-1:-6:-1]
    print("images:{}".format(image_file))
    print("======== top5 inference results: =============")
    for n in top_k:
        object_class = image_net_classes.get_image_net_class(n)
        print("label:%d  confidence: %f, class: %s" %
              (n, vals[n], object_class))

    (filepath, tempfilename) = os.path.split(image_file)
    (filename, extension) = os.path.splitext(tempfilename)
    output_path = os.path.join(os.path.join(SRC_PATH, "../outputs"),
                               filename + ".txt")
    with open(output_path, "w", encoding="utf-8") as fp:
        fp.write(image_net_classes.get_image_net_class(top_k[0]))
Example #3
0
    def post_process(self, infer_output, image_file):
        """
        post_process
        """
        print("post process")
        data = infer_output[0]
        vals = data.flatten()
        top_k = vals.argsort()[-1:-7:-1]
        print("images:{}".format(image_file))
        print("======== top5 inference results: =============")
        for n in top_k:
            object_class = get_image_net_class(n)
            print("label:%d  confidence: %f, class: %s" %
                  (n, vals[n], object_class))

        #using pillow, the category with the highest confidence is written on the image and saved locally
        if len(top_k):
            object_class = get_image_net_class(top_k[0])
            object_value = vals[top_k[0]]
            output_path = os.path.join(os.path.join(SRC_PATH, "../outputs"),
                                       os.path.basename(image_file))
            origin_img = cv2.imread(image_file)
            font = cv2.FONT_HERSHEY_SIMPLEX
            origin_img = cv2.putText(origin_img, object_class, (10, 100), font,
                                     3, (255, 255, 255), 3)
            origin_img = cv2.putText(origin_img, str(object_value), (10, 200),
                                     font, 2, (255, 255, 255), 3)
            cv2.imwrite(output_path, origin_img)
Example #4
0
    def post_process(self, infer_output, batch_image_files, number_of_images):
        print("post process")
        datas = infer_output[0]

        for number in range(number_of_images):
            data = datas[number]
            vals = data.flatten()
            top_k = vals.argsort()[-1:-6:-1]
            print("images:{}".format(batch_image_files[number]))
            print("======== top5 inference results: =============")
            for n in top_k:
                object_class = get_image_net_class(n)
                print("label:%d  confidence: %f, class: %s" %
                      (n, vals[n], object_class))

            #Use Pillow to write the categories with the highest confidence on the image and save them locally
            if len(top_k):
                object_class = get_image_net_class(top_k[0])
                output_path = os.path.join(
                    "../outputs", os.path.basename(batch_image_files[number]))
                origin_img = Image.open(batch_image_files[number])
                draw = ImageDraw.Draw(origin_img)
                font = ImageFont.load_default()
                draw.text((10, 50), object_class, font=font, fill=255)
                origin_img.save(output_path)
    def post_process(self, infer_output):
        print("post process")
        data = infer_output[0]
        vals = data.flatten()
        top_k = vals.argsort()[-1:-6:-1]
        print("======== top5 inference results: =============")
        for n in top_k:
            object_class = get_image_net_class(n)
            print("label:%d  confidence: %f, class: %s" %
                  (n, vals[n], object_class))

        object_class = get_image_net_class(top_k[0])
        return object_class
Example #6
0
    def post(self):
        args = parser_put.parse_args()
        img_data_base64_encode = args['img_data']
        img_type = args['img_type']
        img_decode = base64_decode(img_data_base64_encode, img_type)
        #print(img_decode)

        result_img_encode = main_process()
        os.remove("./origin/origin.jpg")
        q = 400

        for n in range(1, 1000):
            if str(result_img_encode) == get_image_net_class(n):
                q = 200
                break
        result = {"result": str(result_img_encode), "code": q}
        return result