Skip to content

Latest commit

 

History

History
173 lines (118 loc) · 5.16 KB

File metadata and controls

173 lines (118 loc) · 5.16 KB

yolov3_darknet53_vehicles

Module Name yolov3_darknet53_vehicles
Category object detection
Network YOLOv3
Dataset Baidu Vehicle Dataset
Fine-tuning supported or not No
Module Size 238MB
Latest update date 2021-03-15
Data indicators -

I.Basic Information

  • Application Effect Display

    • Sample results:


  • Module Introduction

    • YOLOv3 is a one-stage detector proposed by Joseph Redmon and Ali Farhadi, which can reach comparable accuracy but twice as fast as traditional methods. This module is based on YOLOv3, trained on Baidu Vehicle Dataset, and can be used for vehicle detection.

II.Installation

III.Module API Prediction

  • 1、Command line Prediction

    • $ hub run yolov3_darknet53_vehicles --input_path "/PATH/TO/IMAGE"
    • If you want to call the Hub module through the command line, please refer to: PaddleHub Command Line Instruction
  • 2、Prediction Code Example

    • import paddlehub as hub
      import cv2
      
      vehicles_detector = hub.Module(name="yolov3_darknet53_vehicles")
      result = vehicles_detector.object_detection(images=[cv2.imread('/PATH/TO/IMAGE')])
      # or
      # result = vehicles_detector.object_detection((paths=['/PATH/TO/IMAGE'])
  • 3、API

    • def object_detection(paths=None,
                           images=None,
                           batch_size=1,
                           use_gpu=False,
                           output_dir='yolov3_vehicles_detect_output',
                           score_thresh=0.2,
                           visualization=True)
      • Detection API, detect positions of all vehicles in image

      • Parameters

        • paths (list[str]): image path;
        • images (list[numpy.ndarray]): image data, ndarray.shape is in the format [H, W, C], BGR;
        • batch_size (int): the size of batch;
        • use_gpu (bool): use GPU or not; set the CUDA_VISIBLE_DEVICES environment variable first if you are using GPU
        • output_dir (str): save path of images;
        • score_thresh (float): confidence threshold;
        • visualization (bool): Whether to save the results as picture files;

        NOTE: choose one parameter to provide data from paths and images

      • Return

        • res (list[dict]): results
          • data (list): detection results, each element in the list is dict
            • confidence (float): the confidence of the result
            • label (str): label
            • left (int): the upper left corner x coordinate of the detection box
            • top (int): the upper left corner y coordinate of the detection box
            • right (int): the lower right corner x coordinate of the detection box
            • bottom (int): the lower right corner y coordinate of the detection box
          • save_path (str, optional): output path for saving results
    • def save_inference_model(dirname)
      • Save model to specific path

      • Parameters

        • dirname: model save path

IV.Server Deployment

  • PaddleHub Serving can deploy an online service of object detection.

  • Step 1: Start PaddleHub Serving

    • Run the startup command:

    • $ hub serving start -m yolov3_darknet53_vehicles
    • The servitization API is now deployed and the default port number is 8866.

    • NOTE: If GPU is used for prediction, set CUDA_VISIBLE_DEVICES environment variable before the service, otherwise it need not be set.

  • Step 2: Send a predictive request

    • With a configured server, use the following lines of code to send the prediction request and obtain the result

    • import requests
      import json
      import cv2
      import base64
      
      
      def cv2_to_base64(image):
        data = cv2.imencode('.jpg', image)[1]
        return base64.b64encode(data.tostring()).decode('utf8')
      
      # Send an HTTP request
      data = {'images':[cv2_to_base64(cv2.imread("/PATH/TO/IMAGE"))]}
      headers = {"Content-type": "application/json"}
      url = "http://127.0.0.1:8866/predict/yolov3_darknet53_vehicles"
      r = requests.post(url=url, headers=headers, data=json.dumps(data))
      
      # print prediction results
      print(r.json()["results"])

V.Release Note

  • 1.0.0

    First release

  • 1.0.2

    Fix the problem of reading numpy

  • 1.0.3

    Remove fluid api

  • 1.1.0

    Fix bug of save_inference_model

    • $ hub install yolov3_darknet53_vehicles==1.1.0