This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Visualise detections on input image | |
| cols = st.columns(len(pipeline_ids)) | |
| captions = ["YOLOv4", "YOLOv7"] | |
| for col, (resp, boxes_ltwh, categories, scores), cap in zip(cols, pipeline_results, captions): | |
| if resp.status_code == 200: | |
| # Show image overlaid with detection results | |
| img_draw = draw_detection(img, boxes_ltwh, categories, scores) | |
| col.image(img_draw, use_column_width=True, caption=cap) | |
| else: | |
| col.error("{} inference error".format(cap)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Trigger VDP pipelines | |
| pipeline_ids = [opt.yolov4, opt.yolov7] | |
| pipeline_results = [] | |
| for pipeline_id in pipeline_ids: | |
| resp = trigger_detection_pipeline(pipeline_backend_base_url, pipeline_id, image_url) | |
| boxes_ltwh, categories, scores = parse_detection_response(resp) | |
| pipeline_results.append((resp, boxes_ltwh, categories, scores)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def parse_detection_response(resp: requests.Response): | |
| r""" Parse a detection response | |
| Args: | |
| resp (`requests.Response`): response for standardised object detection task | |
| Returns: parsed outputs, a tuple of | |
| List[Tuple[float]]: a list of detected bounding boxes in the format of (top, left, width, height) | |
| List[str]: a list of category labels, each of which corresponds to a detected bounding box. The length of this list must be the same as the detected bounding boxes. | |
| List[float]]: a list of scores, each of which corresponds to a detected bounding box. The length of this list must be the same as the detected bounding boxes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def trigger_detection_pipeline(pipeline_backend_base_url: str, pipeline_id: str, image_url: str) -> requests.Response: | |
| r""" Trigger a pipeline composed with a detection model instance using remote image URL | |
| Args: | |
| pipeline_backend_base_url (string): VDP pipeline backend base URL | |
| pipeline_id (string): pipeline ID | |
| image_url (string): remote image URL, e.g., `https://artifacts.instill.tech/dog.jpg` | |
| Returns: requests.Response | |
| pipeline trigger result | |
| """ | |
| body = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use image remote URL to fetch an image as input | |
| image_url = st.text_input( | |
| label="Feed me with an image URL and press ENTER", value="https://artifacts.instill.tech/dog.jpg") |