Skip to content

Commit

Permalink
Merge pull request #6 from wisesight/feature/support-inf1
Browse files Browse the repository at this point in the history
Feature/support inf1
  • Loading branch information
takipipo authored Dec 11, 2024
2 parents fb0708e + ca32004 commit ab37921
Show file tree
Hide file tree
Showing 74 changed files with 949 additions and 1,000 deletions.
1 change: 0 additions & 1 deletion docs/build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def prepare_docs_markdown(clone_repos=True):

def update_page_title(file_path: Path, new_title: str):
"""Update the title of an HTML file."""

# Read the content of the file
with open(file_path, encoding="utf-8") as file:
content = file.read()
Expand Down
48 changes: 38 additions & 10 deletions docs/overrides/javascript/extra.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Function that applies light/dark theme based on the user's preference
const applyAutoTheme = () => {
// Determine the user's preferred color scheme
const prefersLight = window.matchMedia("(prefers-color-scheme: light)").matches;
const prefersLight = window.matchMedia(
"(prefers-color-scheme: light)",
).matches;
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;

// Apply the appropriate attributes based on the user's preference
Expand All @@ -17,15 +19,31 @@ const applyAutoTheme = () => {
// Function that checks and applies light/dark theme based on the user's preference (if auto theme is enabled)
function checkAutoTheme() {
// Array of supported language codes -> each language has its own palette (stored in local storage)
const supportedLangCodes = ["en", "zh", "ko", "ja", "ru", "de", "fr", "es", "pt", "it", "tr", "vi", "nl"];
const supportedLangCodes = [
"en",
"zh",
"ko",
"ja",
"ru",
"de",
"fr",
"es",
"pt",
"it",
"tr",
"vi",
"nl",
];
// Get the URL path
const path = window.location.pathname;
// Extract the language code from the URL (assuming it's in the format /xx/...)
const langCode = path.split("/")[1];
// Check if the extracted language code is in the supported languages
const isValidLangCode = supportedLangCodes.includes(langCode);
// Construct the local storage key based on the language code if valid, otherwise default to the root key
const localStorageKey = isValidLangCode ? `/${langCode}/.__palette` : "/.__palette";
const localStorageKey = isValidLangCode
? `/${langCode}/.__palette`
: "/.__palette";
// Retrieve the palette from local storage using the constructed key
const palette = localStorage.getItem(localStorageKey);
if (palette) {
Expand All @@ -41,8 +59,12 @@ function checkAutoTheme() {
checkAutoTheme();

// Re-run the function when the user's preference changes (when the user changes their system theme)
window.matchMedia("(prefers-color-scheme: light)").addEventListener("change", checkAutoTheme);
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", checkAutoTheme);
window
.matchMedia("(prefers-color-scheme: light)")
.addEventListener("change", checkAutoTheme);
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", checkAutoTheme);

// Re-run the function when the palette changes (e.g. user switched from dark theme to auto theme)
// ! We can't use window.addEventListener("storage", checkAutoTheme) because it will NOT be triggered on the current tab
Expand All @@ -61,9 +83,15 @@ if (autoThemeInput) {
}

// Add iframe navigation
window.onhashchange = function() {
window.parent.postMessage({
type: 'navigation',
hash: window.location.pathname + window.location.search + window.location.hash
}, '*');
window.onhashchange = function () {
window.parent.postMessage(
{
type: "navigation",
hash:
window.location.pathname +
window.location.search +
window.location.hash,
},
"*",
);
};
4 changes: 1 addition & 3 deletions docs/overrides/main.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<!--Ultralytics YOLO 🚀, AGPL-3.0 license-->

{% extends "base.html" %}

{% block announce %}
{% extends "base.html" %} {% block announce %}
<a
href="https://github.com/ultralytics/ultralytics/releases/tag/v8.2.0"
target="_blank"
Expand Down
79 changes: 40 additions & 39 deletions docs/overrides/partials/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,51 @@
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2>

<!-- Insert Giscus code snippet from https://giscus.app/ here -->
<script async
crossorigin="anonymous"
data-category="Docs"
data-category-id="DIC_kwDOH-jzvc4CWLkL"
data-emit-metadata="0"
data-input-position="top"
data-lang="en"
data-loading="lazy"
data-mapping="pathname"
data-reactions-enabled="1"
data-repo="ultralytics/ultralytics"
data-repo-id="R_kgDOH-jzvQ"
data-strict="1"
data-theme="preferred_color_scheme"
src="https://giscus.app/client.js">
</script>
<script
async
crossorigin="anonymous"
data-category="Docs"
data-category-id="DIC_kwDOH-jzvc4CWLkL"
data-emit-metadata="0"
data-input-position="top"
data-lang="en"
data-loading="lazy"
data-mapping="pathname"
data-reactions-enabled="1"
data-repo="ultralytics/ultralytics"
data-repo-id="R_kgDOH-jzvQ"
data-strict="1"
data-theme="preferred_color_scheme"
src="https://giscus.app/client.js"
></script>

<!-- Synchronize Giscus theme with palette -->
<script>
var giscus = document.querySelector("script[src*=giscus]")
var giscus = document.querySelector("script[src*=giscus]");

/* Set palette on initial load */
var palette = __md_get("__palette")
if (palette && typeof palette.color === "object") {
var theme = palette.color.scheme === "slate" ? "dark" : "light"
giscus.setAttribute("data-theme", theme)
}
/* Set palette on initial load */
var palette = __md_get("__palette");
if (palette && typeof palette.color === "object") {
var theme = palette.color.scheme === "slate" ? "dark" : "light";
giscus.setAttribute("data-theme", theme);
}

/* Register event handlers after documented loaded */
document.addEventListener("DOMContentLoaded", function() {
var ref = document.querySelector("[data-md-component=palette]")
ref.addEventListener("change", function() {
var palette = __md_get("__palette")
if (palette && typeof palette.color === "object") {
var theme = palette.color.scheme === "slate" ? "dark" : "light"
/* Register event handlers after documented loaded */
document.addEventListener("DOMContentLoaded", function () {
var ref = document.querySelector("[data-md-component=palette]");
ref.addEventListener("change", function () {
var palette = __md_get("__palette");
if (palette && typeof palette.color === "object") {
var theme = palette.color.scheme === "slate" ? "dark" : "light";

/* Instruct Giscus to change theme */
var frame = document.querySelector(".giscus-frame")
frame.contentWindow.postMessage(
{ giscus: { setConfig: { theme } } },
"https://giscus.app"
)
}
})
})
/* Instruct Giscus to change theme */
var frame = document.querySelector(".giscus-frame");
frame.contentWindow.postMessage(
{ giscus: { setConfig: { theme } } },
"https://giscus.app",
);
}
});
});
</script>
{% endif %}
32 changes: 14 additions & 18 deletions docs/overrides/partials/source-file.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
<!-- taken from
https://github.com/squidfunk/mkdocs-material/blob/master/src/partials/source-file.html -->

<br>
<br />
<div class="md-source-file">
<small>
<small>
<!-- mkdocs-git-revision-date-localized-plugin -->
{% if page.meta.git_revision_date_localized %} 📅 {{
lang.t("source.file.date.updated") }}: {{
page.meta.git_revision_date_localized }} {% if
page.meta.git_creation_date_localized %}
<br />
🎂 {{ lang.t("source.file.date.created") }}: {{
page.meta.git_creation_date_localized }} {% endif %}

<!-- mkdocs-git-revision-date-localized-plugin -->
{% if page.meta.git_revision_date_localized %}
📅 {{ lang.t("source.file.date.updated") }}:
{{ page.meta.git_revision_date_localized }}
{% if page.meta.git_creation_date_localized %}
<br/>
🎂 {{ lang.t("source.file.date.created") }}:
{{ page.meta.git_creation_date_localized }}
{% endif %}

<!-- mkdocs-git-revision-date-plugin -->
{% elif page.meta.revision_date %}
📅 {{ lang.t("source.file.date.updated") }}:
{{ page.meta.revision_date }}
{% endif %}
</small>
<!-- mkdocs-git-revision-date-plugin -->
{% elif page.meta.revision_date %} 📅 {{ lang.t("source.file.date.updated")
}}: {{ page.meta.revision_date }} {% endif %}
</small>
</div>
1 change: 0 additions & 1 deletion examples/YOLOv8-Action-Recognition/action_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ def __call__(self, sequences: torch.Tensor) -> torch.Tensor:
Returns:
torch.Tensor: The model's output.
"""

input_ids = self.processor(text=self.labels, return_tensors="pt", padding=True)["input_ids"].to(self.device)

inputs = {"pixel_values": sequences, "input_ids": input_ids}
Expand Down
2 changes: 0 additions & 2 deletions examples/YOLOv8-ONNXRuntime/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def draw_detections(self, img, box, score, class_id):
Returns:
None
"""

# Extract the coordinates of the bounding box
x1, y1, w, h = box

Expand Down Expand Up @@ -118,7 +117,6 @@ def postprocess(self, input_image, output):
Returns:
numpy.ndarray: The input image with detections drawn on it.
"""

# Transpose and squeeze the output to match the expected shape
outputs = np.transpose(np.squeeze(output[0]))

Expand Down
7 changes: 0 additions & 7 deletions examples/YOLOv8-OpenCV-int8-tflite-Python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(

def __call__(self, labels=None, image=None):
"""Return updated labels and image with added border."""

if labels is None:
labels = {}
img = labels.get("img") if image is None else image
Expand Down Expand Up @@ -77,7 +76,6 @@ def __call__(self, labels=None, image=None):

def _update_labels(self, labels, ratio, padw, padh):
"""Update labels."""

labels["instances"].convert_bbox(format="xyxy")
labels["instances"].denormalize(*labels["img"].shape[:2][::-1])
labels["instances"].scale(*ratio)
Expand All @@ -96,7 +94,6 @@ def __init__(self, tflite_model, input_image, confidence_thres, iou_thres):
confidence_thres: Confidence threshold for filtering detections.
iou_thres: IoU (Intersection over Union) threshold for non-maximum suppression.
"""

self.tflite_model = tflite_model
self.input_image = input_image
self.confidence_thres = confidence_thres
Expand All @@ -121,7 +118,6 @@ def draw_detections(self, img, box, score, class_id):
Returns:
None
"""

# Extract the coordinates of the bounding box
x1, y1, w, h = box

Expand Down Expand Up @@ -160,7 +156,6 @@ def preprocess(self):
Returns:
image_data: Preprocessed image data ready for inference.
"""

# Read the input image using OpenCV
self.img = cv2.imread(self.input_image)

Expand Down Expand Up @@ -189,7 +184,6 @@ def postprocess(self, input_image, output):
Returns:
numpy.ndarray: The input image with detections drawn on it.
"""

boxes = []
scores = []
class_ids = []
Expand Down Expand Up @@ -234,7 +228,6 @@ def main(self):
Returns:
output_img: The output image with drawn detections.
"""

# Create an interpreter for the TFLite model
interpreter = tflite.Interpreter(model_path=self.tflite_model)
self.model = interpreter
Expand Down
1 change: 0 additions & 1 deletion examples/YOLOv8-SAHI-Inference-Video/yolov8_sahi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def run(weights="yolov8n.pt", source="test.mp4", view_img=False, save_img=False,
save_img (bool): Save results.
exist_ok (bool): Overwrite existing files.
"""

# Check source path
if not Path(source).exists():
raise FileNotFoundError(f"Source path '{source}' does not exist.")
Expand Down
12 changes: 4 additions & 8 deletions examples/YOLOv8-Segmentation-ONNXRuntime-Python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(self, onnx_model):
Args:
onnx_model (str): Path to the ONNX model.
"""

# Build Ort session
self.session = ort.InferenceSession(
onnx_model,
Expand Down Expand Up @@ -57,7 +56,6 @@ def __call__(self, im0, conf_threshold=0.4, iou_threshold=0.45, nm=32):
segments (List): list of segments.
masks (np.ndarray): [N, H, W], output masks.
"""

# Pre-process
im, ratio, (pad_w, pad_h) = self.preprocess(im0)

Expand Down Expand Up @@ -90,7 +88,6 @@ def preprocess(self, img):
pad_w (float): width padding in letterbox.
pad_h (float): height padding in letterbox.
"""

# Resize and pad input image using letterbox() (Borrowed from Ultralytics)
shape = img.shape[:2] # original image shape
new_shape = (self.model_height, self.model_width)
Expand Down Expand Up @@ -170,7 +167,7 @@ def postprocess(self, preds, im0, ratio, pad_w, pad_h, conf_threshold, iou_thres
def masks2segments(masks):
"""
It takes a list of masks(n,h,w) and returns a list of segments(n,xy) (Borrowed from
https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L750)
https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L750).
Args:
masks (numpy.ndarray): the output of the model, which is a tensor of shape (batch_size, 160, 160).
Expand All @@ -192,7 +189,7 @@ def masks2segments(masks):
def crop_mask(masks, boxes):
"""
It takes a mask and a bounding box, and returns a mask that is cropped to the bounding box. (Borrowed from
https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L599)
https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L599).
Args:
masks (Numpy.ndarray): [n, h, w] tensor of masks.
Expand All @@ -210,7 +207,7 @@ def crop_mask(masks, boxes):
def process_mask(self, protos, masks_in, bboxes, im0_shape):
"""
Takes the output of the mask head, and applies the mask to the bounding boxes. This produces masks of higher quality
but is slower. (Borrowed from https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L618)
but is slower. (Borrowed from https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L618).
Args:
protos (numpy.ndarray): [mask_dim, mask_h, mask_w].
Expand All @@ -233,7 +230,7 @@ def process_mask(self, protos, masks_in, bboxes, im0_shape):
def scale_mask(masks, im0_shape, ratio_pad=None):
"""
Takes a mask, and resizes it to the original image size. (Borrowed from
https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L305)
https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L305).
Args:
masks (np.ndarray): resized and padded masks/images, [h, w, num]/[h, w, 3].
Expand Down Expand Up @@ -277,7 +274,6 @@ def draw_and_visualize(self, im, bboxes, segments, vis=False, save=True):
Returns:
None
"""

# Draw rectangles and polygons
im_canvas = im.copy()
for (*box, conf, cls_), segment in zip(bboxes, segments):
Expand Down
Loading

0 comments on commit ab37921

Please sign in to comment.