Update TFLite Docs images (#8605)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
1146bb0582
commit
36408c974c
33 changed files with 112 additions and 107 deletions
|
|
@ -14,12 +14,12 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
## Recipe Walk Through
|
||||
|
||||
1. Begin with the necessary imports
|
||||
1. Begin with the necessary imports
|
||||
|
||||
```py
|
||||
```python
|
||||
from pathlib import Path
|
||||
|
||||
import cv2 as cv
|
||||
import cv2
|
||||
import numpy as np
|
||||
from ultralytics import YOLO
|
||||
```
|
||||
|
|
@ -30,19 +30,19 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
***
|
||||
|
||||
2. Load a model and run `predict()` method on a source.
|
||||
2. Load a model and run `predict()` method on a source.
|
||||
|
||||
```py
|
||||
```python
|
||||
from ultralytics import YOLO
|
||||
|
||||
# Load a model
|
||||
model = YOLO('yolov8n-seg.pt')
|
||||
|
||||
# Run inference
|
||||
result = model.predict()
|
||||
results = model.predict()
|
||||
```
|
||||
|
||||
??? question "No Prediction Arguments?"
|
||||
!!! question "No Prediction Arguments?"
|
||||
|
||||
Without specifying a source, the example images from the library will be used:
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
***
|
||||
|
||||
3. Now iterate over the results and the contours. For workflows that want to save an image to file, the source image `base-name` and the detection `class-label` are retrieved for later use (optional).
|
||||
3. Now iterate over the results and the contours. For workflows that want to save an image to file, the source image `base-name` and the detection `class-label` are retrieved for later use (optional).
|
||||
|
||||
```{ .py .annotate }
|
||||
# (2) Iterate detection results (helpful for multiple images)
|
||||
|
|
@ -81,7 +81,7 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
***
|
||||
|
||||
4. Start with generating a binary mask from the source image and then draw a filled contour onto the mask. This will allow the object to be isolated from the other parts of the image. An example from `bus.jpg` for one of the detected `person` class objects is shown on the right.
|
||||
4. Start with generating a binary mask from the source image and then draw a filled contour onto the mask. This will allow the object to be isolated from the other parts of the image. An example from `bus.jpg` for one of the detected `person` class objects is shown on the right.
|
||||
|
||||
{ width="240", align="right" }
|
||||
|
||||
|
|
@ -98,11 +98,11 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
|
||||
# Draw contour onto mask
|
||||
_ = cv.drawContours(b_mask,
|
||||
_ = cv2.drawContours(b_mask,
|
||||
[contour],
|
||||
-1,
|
||||
(255, 255, 255),
|
||||
cv.FILLED)
|
||||
cv2.FILLED)
|
||||
|
||||
```
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
- The `tuple` `(255, 255, 255)` represents the color white, which is the desired color for drawing the contour in this binary mask.
|
||||
|
||||
- The addition of `cv.FILLED` will color all pixels enclosed by the contour boundary the same, in this case, all enclosed pixels will be white.
|
||||
- The addition of `cv2.FILLED` will color all pixels enclosed by the contour boundary the same, in this case, all enclosed pixels will be white.
|
||||
|
||||
- See [OpenCV Documentation on `drawContours()`](https://docs.opencv.org/4.8.0/d6/d6e/group__imgproc__draw.html#ga746c0625f1781f1ffc9056259103edbc) for more information.
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
***
|
||||
|
||||
5. Next the there are 2 options for how to move forward with the image from this point and a subsequent option for each.
|
||||
5. Next the there are 2 options for how to move forward with the image from this point and a subsequent option for each.
|
||||
|
||||
### Object Isolation Options
|
||||
|
||||
|
|
@ -155,10 +155,10 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
```py
|
||||
# Create 3-channel mask
|
||||
mask3ch = cv.cvtColor(b_mask, cv.COLOR_GRAY2BGR)
|
||||
mask3ch = cv2.cvtColor(b_mask, cv2.COLOR_GRAY2BGR)
|
||||
|
||||
# Isolate object with binary mask
|
||||
isolated = cv.bitwise_and(mask3ch, img)
|
||||
isolated = cv2.bitwise_and(mask3ch, img)
|
||||
|
||||
```
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
***
|
||||
|
||||
6. <u>What to do next is entirely left to you as the developer.</u> A basic example of one possible next step (saving the image to file for future use) is shown.
|
||||
6. <u>What to do next is entirely left to you as the developer.</u> A basic example of one possible next step (saving the image to file for future use) is shown.
|
||||
|
||||
- **NOTE:** this step is optional and can be skipped if not required for your specific use case.
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
```py
|
||||
# Save isolated object to file
|
||||
_ = cv.imwrite(f'{img_name}_{label}-{ci}.png', iso_crop)
|
||||
_ = cv2.imwrite(f'{img_name}_{label}-{ci}.png', iso_crop)
|
||||
```
|
||||
|
||||
- In this example, the `img_name` is the base-name of the source image file, `label` is the detected class-name, and `ci` is the index of the object detection (in case of multiple instances with the same class name).
|
||||
|
|
@ -278,7 +278,7 @@ Here, all steps from the previous section are combined into a single block of co
|
|||
```{ .py .annotate }
|
||||
from pathlib import Path
|
||||
|
||||
import cv2 as cv
|
||||
import cv2
|
||||
import numpy as np
|
||||
from ultralytics import YOLO
|
||||
|
||||
|
|
@ -298,13 +298,13 @@ for r in res:
|
|||
|
||||
# Create contour mask (1)
|
||||
contour = c.masks.xy.pop().astype(np.int32).reshape(-1, 1, 2)
|
||||
_ = cv.drawContours(b_mask, [contour], -1, (255, 255, 255), cv.FILLED)
|
||||
_ = cv2.drawContours(b_mask, [contour], -1, (255, 255, 255), cv2.FILLED)
|
||||
|
||||
# Choose one:
|
||||
|
||||
# OPTION-1: Isolate object with black background
|
||||
mask3ch = cv.cvtColor(b_mask, cv.COLOR_GRAY2BGR)
|
||||
isolated = cv.bitwise_and(mask3ch, img)
|
||||
mask3ch = cv2.cvtColor(b_mask, cv2.COLOR_GRAY2BGR)
|
||||
isolated = cv2.bitwise_and(mask3ch, img)
|
||||
|
||||
# OPTION-2: Isolate object with transparent background (when saved as PNG)
|
||||
isolated = np.dstack([img, b_mask])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue