mirror of
https://github.com/THU-MIG/yolov10.git
synced 2025-05-23 13:34:23 +08:00
Add retry
option to get_github_assets()
function (#4148)
This commit is contained in:
parent
11d0488bf1
commit
09a0378e81
@ -410,7 +410,7 @@ All Ultralytics `predict()` calls will return a list of `Results` objects:
|
||||
| `save_crop()` | `None` | Save cropped predictions to `save_dir/cls/file_name.jpg`. |
|
||||
| `tojson()` | `None` | Convert the object to JSON format. |
|
||||
|
||||
For more details see the `Results` class [documentation](../reference/engine/results.md#-results).
|
||||
For more details see the `Results` class [documentation](../reference/engine/results.md).
|
||||
|
||||
### Boxes
|
||||
|
||||
@ -448,7 +448,7 @@ Here is a table for the `Boxes` class methods and properties, including their na
|
||||
| `xyxyn` | Property (`torch.Tensor`) | Return the boxes in xyxy format normalized by original image size. |
|
||||
| `xywhn` | Property (`torch.Tensor`) | Return the boxes in xywh format normalized by original image size. |
|
||||
|
||||
For more details see the `Boxes` class [documentation](../reference/engine/results.md#boxes).
|
||||
For more details see the `Boxes` class [documentation](../reference/engine/results.md).
|
||||
|
||||
### Masks
|
||||
|
||||
@ -472,16 +472,16 @@ For more details see the `Boxes` class [documentation](../reference/engine/resul
|
||||
|
||||
Here is a table for the `Masks` class methods and properties, including their name, type, and description:
|
||||
|
||||
| Name | Type | Description |
|
||||
|------------|---------------------------|-----------------------------------------------------------------|
|
||||
| `cpu()` | Method | Returns the masks tensor on CPU memory. |
|
||||
| `numpy()` | Method | Returns the masks tensor as a numpy array. |
|
||||
| `cuda()` | Method | Returns the masks tensor on GPU memory. |
|
||||
| `to()` | Method | Returns the masks tensor with the specified device and dtype. |
|
||||
| `xyn` | Property (`torch.Tensor`) | A list of normalized segments represented as tensors. |
|
||||
| `xy` | Property (`torch.Tensor`) | A list of segments in pixel coordinates represented as tensors. |
|
||||
| Name | Type | Description |
|
||||
|-----------|---------------------------|-----------------------------------------------------------------|
|
||||
| `cpu()` | Method | Returns the masks tensor on CPU memory. |
|
||||
| `numpy()` | Method | Returns the masks tensor as a numpy array. |
|
||||
| `cuda()` | Method | Returns the masks tensor on GPU memory. |
|
||||
| `to()` | Method | Returns the masks tensor with the specified device and dtype. |
|
||||
| `xyn` | Property (`torch.Tensor`) | A list of normalized segments represented as tensors. |
|
||||
| `xy` | Property (`torch.Tensor`) | A list of segments in pixel coordinates represented as tensors. |
|
||||
|
||||
For more details see the `Masks` class [documentation](../reference/engine/results.md#masks).
|
||||
For more details see the `Masks` class [documentation](../reference/engine/results.md).
|
||||
|
||||
### Keypoints
|
||||
|
||||
@ -515,7 +515,7 @@ Here is a table for the `Keypoints` class methods and properties, including thei
|
||||
| `xy` | Property (`torch.Tensor`) | A list of keypoints in pixel coordinates represented as tensors. |
|
||||
| `conf` | Property (`torch.Tensor`) | Returns confidence values of keypoints if available, else None. |
|
||||
|
||||
For more details see the `Keypoints` class [documentation](../reference/engine/results.md#keypoints).
|
||||
For more details see the `Keypoints` class [documentation](../reference/engine/results.md).
|
||||
|
||||
### Probs
|
||||
|
||||
@ -539,22 +539,22 @@ For more details see the `Keypoints` class [documentation](../reference/engine/r
|
||||
|
||||
Here's a table summarizing the methods and properties for the `Probs` class:
|
||||
|
||||
| Name | Type | Description |
|
||||
|------------|-------------------------|-------------------------------------------------------------------------|
|
||||
| `cpu()` | Method | Returns a copy of the probs tensor on CPU memory. |
|
||||
| `numpy()` | Method | Returns a copy of the probs tensor as a numpy array. |
|
||||
| `cuda()` | Method | Returns a copy of the probs tensor on GPU memory. |
|
||||
| `to()` | Method | Returns a copy of the probs tensor with the specified device and dtype. |
|
||||
| `top1` | Property `int` | Index of the top 1 class. |
|
||||
| `top5` | Property `list[int]` | Indices of the top 5 classes. |
|
||||
| `top1conf` | Property `torch.Tensor` | Confidence of the top 1 class. |
|
||||
| `top5conf` | Property `torch.Tensor` | Confidences of the top 5 classes. |
|
||||
| Name | Type | Description |
|
||||
|------------|---------------------------|-------------------------------------------------------------------------|
|
||||
| `cpu()` | Method | Returns a copy of the probs tensor on CPU memory. |
|
||||
| `numpy()` | Method | Returns a copy of the probs tensor as a numpy array. |
|
||||
| `cuda()` | Method | Returns a copy of the probs tensor on GPU memory. |
|
||||
| `to()` | Method | Returns a copy of the probs tensor with the specified device and dtype. |
|
||||
| `top1` | Property (`int`) | Index of the top 1 class. |
|
||||
| `top5` | Property (`list[int]`) | Indices of the top 5 classes. |
|
||||
| `top1conf` | Property (`torch.Tensor`) | Confidence of the top 1 class. |
|
||||
| `top5conf` | Property (`torch.Tensor`) | Confidences of the top 5 classes. |
|
||||
|
||||
For more details see the `Probs` class [documentation](../reference/engine/results.md#probs).
|
||||
For more details see the `Probs` class [documentation](../reference/engine/results.md).
|
||||
|
||||
## Plotting Results
|
||||
|
||||
You can the `plot()` method of a `Result` objects to plot predictions. It plots all prediction types (boxes, masks, keypoints, probabilities, etc.) contained in the `Results` object.
|
||||
You can use the `plot()` method of a `Result` objects to visualize predictions. It plots all prediction types (boxes, masks, keypoints, probabilities, etc.) contained in the `Results` object onto a numpy array that can then be shown or saved.
|
||||
|
||||
!!! example "Plotting"
|
||||
|
||||
@ -570,8 +570,10 @@ You can the `plot()` method of a `Result` objects to plot predictions. It plots
|
||||
|
||||
# Show the results
|
||||
for r in results:
|
||||
im = r.plot() # plot a BGR numpy array of predictions
|
||||
Image.fromarray(im[..., ::-1]).show() # show RGB image
|
||||
im_array = r.plot() # plot a BGR numpy array of predictions
|
||||
im = Image.fromarray(im[..., ::-1]) # RGB PIL image
|
||||
im.show() # show image
|
||||
im.save('results.jpg') # save image
|
||||
```
|
||||
|
||||
The `plot()` method has the following arguments available:
|
||||
@ -636,4 +638,4 @@ Here's a Python script using OpenCV (`cv2`) and YOLOv8 to run inference on video
|
||||
cv2.destroyAllWindows()
|
||||
```
|
||||
|
||||
This script will run predictions on each frame of the video, visualize the results, and display them in a window. The loop can be exited by pressing 'q'.
|
||||
This script will run predictions on each frame of the video, visualize the results, and display them in a window. The loop can be exited by pressing 'q'.
|
||||
|
@ -422,7 +422,7 @@ class Exporter:
|
||||
f'{prefix} WARNING ⚠️ PNNX not found. Attempting to download binary file from '
|
||||
'https://github.com/pnnx/pnnx/.\nNote PNNX Binary file must be placed in current working directory '
|
||||
f'or in {ROOT}. See PNNX repo for full installation instructions.')
|
||||
_, assets = get_github_assets(repo='pnnx/pnnx')
|
||||
_, assets = get_github_assets(repo='pnnx/pnnx', retry=True)
|
||||
asset = [x for x in assets if ('macos' if MACOS else 'ubuntu' if LINUX else 'windows') in x][0]
|
||||
attempt_download_asset(asset, repo='pnnx/pnnx', release='latest')
|
||||
unzip_dir = Path(asset).with_suffix('')
|
||||
|
@ -208,8 +208,10 @@ class Results(SimpleClass):
|
||||
model = YOLO('yolov8n.pt')
|
||||
results = model('bus.jpg') # results list
|
||||
for r in results:
|
||||
im = r.plot() # BGR numpy array
|
||||
Image.fromarray(im[..., ::-1]).show() # show RGB image
|
||||
im_array = r.plot() # plot a BGR numpy array of predictions
|
||||
im = Image.fromarray(im[..., ::-1]) # RGB PIL image
|
||||
im.show() # show image
|
||||
im.save('results.jpg') # save image
|
||||
```
|
||||
"""
|
||||
if img is None and isinstance(self.orig_img, torch.Tensor):
|
||||
|
@ -202,12 +202,16 @@ def safe_download(url,
|
||||
return unzip_dir
|
||||
|
||||
|
||||
def get_github_assets(repo='ultralytics/assets', version='latest'):
|
||||
def get_github_assets(repo='ultralytics/assets', version='latest', retry=False):
|
||||
"""Return GitHub repo tag and assets (i.e. ['yolov8n.pt', 'yolov8s.pt', ...])."""
|
||||
if version != 'latest':
|
||||
version = f'tags/{version}' # i.e. tags/v6.2
|
||||
response = requests.get(f'https://api.github.com/repos/{repo}/releases/{version}').json() # github api
|
||||
return response['tag_name'], [x['name'] for x in response['assets']] # tag, assets
|
||||
url = f'https://api.github.com/repos/{repo}/releases/{version}'
|
||||
r = requests.get(url) # github api
|
||||
if r.status_code != 200 and retry:
|
||||
r = requests.get(url) # try again
|
||||
data = r.json()
|
||||
return data['tag_name'], [x['name'] for x in data['assets']] # tag, assets
|
||||
|
||||
|
||||
def attempt_download_asset(file, repo='ultralytics/assets', release='v0.0.0'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user