cjm-byte-track


Namecjm-byte-track JSON
Version 0.0.6 PyPI version JSON
download
home_pagehttps://github.com/cj-mills/cjm-byte-track
SummaryA standalone Python implementation of the ByteTrack multi-object tracker based on the official implementation.
upload_time2023-10-27 19:42:56
maintainer
docs_urlNone
authorChristian Mills
requires_python>=3.9
licenseApache Software License 2.0
keywords nbdev jupyter notebook python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cjm-byte-track

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

A standalone Python implementation of the
[ByteTrack](https://arxiv.org/abs/2110.06864) multi-object tracker based
on the [official
implementation](https://github.com/ifzhang/ByteTrack/tree/main/yolox/tracker).

## Install

``` sh
pip install cjm_byte_track
```

## Tutorial:

- [**Real-Time Object Tracking with YOLOX and
  ByteTrack:**](https://christianjmills.com/posts/pytorch-train-object-detector-yolox-tutorial/byte-track/)
  Learn how to track objects across video frames with YOLOX and
  ByteTrack.

## How to use

``` python
# Import ByteTrack package
from cjm_byte_track.core import BYTETracker
from cjm_byte_track.matching import match_detections_with_tracks
```

``` python
# Initialize a ByteTracker object
tracker = BYTETracker(track_thresh=0.25, track_buffer=30, match_thresh=0.8, frame_rate=frame_fps)

with tqdm(total=frames, desc="Processing frames") as pbar:
    while video_capture.isOpened():
        ret, frame = video_capture.read()
        if ret:
            
            # Prepare an input image for inference
            rgb_img, input_dims, offsets, min_img_scale, input_img = prepare_image_for_inference(frame, test_sz, max_stride)
                        
            # Convert the existing input image to NumPy format
            input_tensor_np = np.array(input_img, dtype=np.float32).transpose((2, 0, 1))[None]/255

            # Start performance counter`m
            start_time = time.perf_counter()
                        
            # Run inference
            outputs = session.run(None, {"input": input_tensor_np})[0]

            # Process the model output
            proposals = process_outputs(outputs, input_tensor_np.shape[input_dim_slice], bbox_conf_thresh)
            
            # Apply non-max suppression to the proposals with the specified threshold
            proposal_indices = nms_sorted_boxes(calc_iou(proposals[:, :-2]), iou_thresh)
            proposals = proposals[proposal_indices]
            
            bbox_list = (proposals[:,:4]+[*offsets, 0, 0])*min_img_scale
            label_list = [class_names[int(idx)] for idx in proposals[:,4]]
            probs_list = proposals[:,5]

            # Update tracker with detections.
            track_ids = [-1]*len(bbox_list)

            # Convert to tlbr format
            tlbr_boxes = bbox_list.copy()
            tlbr_boxes[:, 2:4] += tlbr_boxes[:, :2]

            # Update tracker with detections
            tracks = tracker.update(
                output_results=np.concatenate([tlbr_boxes, probs_list[:, np.newaxis]], axis=1),
                img_info=rgb_img.size,
                img_size=rgb_img.size)
            track_ids = match_detections_with_tracks(tlbr_boxes=tlbr_boxes, track_ids=track_ids, tracks=tracks)

            # End performance counter
            end_time = time.perf_counter()
            # Calculate the combined FPS for object detection and tracking
            fps = 1 / (end_time - start_time)
            # Display the frame rate in the progress bar
            pbar.set_postfix(fps=fps)

            # Filter object detections based on tracking results
            bbox_list, label_list, probs_list, track_ids = zip(*[(bbox, label, prob, track_id) 
                                                                 for bbox, label, prob, track_id 
                                                                 in zip(bbox_list, label_list, probs_list, track_ids) if track_id != -1])

            # Annotate the current frame with bounding boxes and tracking IDs
            annotated_img = draw_bboxes_pil(
                image=rgb_img, 
                boxes=bbox_list, 
                labels=[f"{track_id}-{label}" for track_id, label in zip(track_ids, label_list)],
                probs=probs_list,
                colors=[int_colors[class_names.index(i)] for i in label_list],  
                font=font_file,
            )
            annotated_frame = cv2.cvtColor(np.array(annotated_img), cv2.COLOR_RGB2BGR)
            
            video_writer.write(annotated_frame)
            pbar.update(1)
        else:
            break
video_capture.release()
video_writer.release()
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cj-mills/cjm-byte-track",
    "name": "cjm-byte-track",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "nbdev jupyter notebook python",
    "author": "Christian Mills",
    "author_email": "millscj@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5a/1e/8e3cab0086bbeb1f07e24ee965f5e0a84091c05b7b8f9d05f6327351d1b2/cjm-byte-track-0.0.6.tar.gz",
    "platform": null,
    "description": "# cjm-byte-track\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nA standalone Python implementation of the\n[ByteTrack](https://arxiv.org/abs/2110.06864) multi-object tracker based\non the [official\nimplementation](https://github.com/ifzhang/ByteTrack/tree/main/yolox/tracker).\n\n## Install\n\n``` sh\npip install cjm_byte_track\n```\n\n## Tutorial:\n\n- [**Real-Time Object Tracking with YOLOX and\n  ByteTrack:**](https://christianjmills.com/posts/pytorch-train-object-detector-yolox-tutorial/byte-track/)\n  Learn how to track objects across video frames with YOLOX and\n  ByteTrack.\n\n## How to use\n\n``` python\n# Import ByteTrack package\nfrom cjm_byte_track.core import BYTETracker\nfrom cjm_byte_track.matching import match_detections_with_tracks\n```\n\n``` python\n# Initialize a ByteTracker object\ntracker = BYTETracker(track_thresh=0.25, track_buffer=30, match_thresh=0.8, frame_rate=frame_fps)\n\nwith tqdm(total=frames, desc=\"Processing frames\") as pbar:\n    while video_capture.isOpened():\n        ret, frame = video_capture.read()\n        if ret:\n            \n            # Prepare an input image for inference\n            rgb_img, input_dims, offsets, min_img_scale, input_img = prepare_image_for_inference(frame, test_sz, max_stride)\n                        \n            # Convert the existing input image to NumPy format\n            input_tensor_np = np.array(input_img, dtype=np.float32).transpose((2, 0, 1))[None]/255\n\n            # Start performance counter`m\n            start_time = time.perf_counter()\n                        \n            # Run inference\n            outputs = session.run(None, {\"input\": input_tensor_np})[0]\n\n            # Process the model output\n            proposals = process_outputs(outputs, input_tensor_np.shape[input_dim_slice], bbox_conf_thresh)\n            \n            # Apply non-max suppression to the proposals with the specified threshold\n            proposal_indices = nms_sorted_boxes(calc_iou(proposals[:, :-2]), iou_thresh)\n            proposals = proposals[proposal_indices]\n            \n            bbox_list = (proposals[:,:4]+[*offsets, 0, 0])*min_img_scale\n            label_list = [class_names[int(idx)] for idx in proposals[:,4]]\n            probs_list = proposals[:,5]\n\n            # Update tracker with detections.\n            track_ids = [-1]*len(bbox_list)\n\n            # Convert to tlbr format\n            tlbr_boxes = bbox_list.copy()\n            tlbr_boxes[:, 2:4] += tlbr_boxes[:, :2]\n\n            # Update tracker with detections\n            tracks = tracker.update(\n                output_results=np.concatenate([tlbr_boxes, probs_list[:, np.newaxis]], axis=1),\n                img_info=rgb_img.size,\n                img_size=rgb_img.size)\n            track_ids = match_detections_with_tracks(tlbr_boxes=tlbr_boxes, track_ids=track_ids, tracks=tracks)\n\n            # End performance counter\n            end_time = time.perf_counter()\n            # Calculate the combined FPS for object detection and tracking\n            fps = 1 / (end_time - start_time)\n            # Display the frame rate in the progress bar\n            pbar.set_postfix(fps=fps)\n\n            # Filter object detections based on tracking results\n            bbox_list, label_list, probs_list, track_ids = zip(*[(bbox, label, prob, track_id) \n                                                                 for bbox, label, prob, track_id \n                                                                 in zip(bbox_list, label_list, probs_list, track_ids) if track_id != -1])\n\n            # Annotate the current frame with bounding boxes and tracking IDs\n            annotated_img = draw_bboxes_pil(\n                image=rgb_img, \n                boxes=bbox_list, \n                labels=[f\"{track_id}-{label}\" for track_id, label in zip(track_ids, label_list)],\n                probs=probs_list,\n                colors=[int_colors[class_names.index(i)] for i in label_list],  \n                font=font_file,\n            )\n            annotated_frame = cv2.cvtColor(np.array(annotated_img), cv2.COLOR_RGB2BGR)\n            \n            video_writer.write(annotated_frame)\n            pbar.update(1)\n        else:\n            break\nvideo_capture.release()\nvideo_writer.release()\n```\n",
    "bugtrack_url": null,
    "license": "Apache Software License 2.0",
    "summary": "A standalone Python implementation of the ByteTrack multi-object tracker based on the official implementation.",
    "version": "0.0.6",
    "project_urls": {
        "Homepage": "https://github.com/cj-mills/cjm-byte-track"
    },
    "split_keywords": [
        "nbdev",
        "jupyter",
        "notebook",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b3b96e251ea133163a517f6d32044fcbd99e4cb423e7c62b02b2118ac6fa4b23",
                "md5": "71d5c4b2f6a01a1fc66c20bffe86674c",
                "sha256": "045dcc0f91fe423a065cbd1d85eff1217868b09ac9a32ee01a0f89d56eb1e501"
            },
            "downloads": -1,
            "filename": "cjm_byte_track-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "71d5c4b2f6a01a1fc66c20bffe86674c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 20378,
            "upload_time": "2023-10-27T19:42:54",
            "upload_time_iso_8601": "2023-10-27T19:42:54.876651Z",
            "url": "https://files.pythonhosted.org/packages/b3/b9/6e251ea133163a517f6d32044fcbd99e4cb423e7c62b02b2118ac6fa4b23/cjm_byte_track-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5a1e8e3cab0086bbeb1f07e24ee965f5e0a84091c05b7b8f9d05f6327351d1b2",
                "md5": "d818573b112f20fe159a3b1222fda924",
                "sha256": "98f9f876014e3bd245966b71addde1abbec95f51e33e18f0fea6b380e13d0ddb"
            },
            "downloads": -1,
            "filename": "cjm-byte-track-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "d818573b112f20fe159a3b1222fda924",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 18077,
            "upload_time": "2023-10-27T19:42:56",
            "upload_time_iso_8601": "2023-10-27T19:42:56.436870Z",
            "url": "https://files.pythonhosted.org/packages/5a/1e/8e3cab0086bbeb1f07e24ee965f5e0a84091c05b7b8f9d05f6327351d1b2/cjm-byte-track-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-27 19:42:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cj-mills",
    "github_project": "cjm-byte-track",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cjm-byte-track"
}
        
Elapsed time: 0.24877s