ultralytics 8.3.117 Replace TFLite Support with JSON metadata (#16413)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com> Co-authored-by: Muhammad Rizwan Munawar <muhammadrizwanmunawar123@gmail.com> Co-authored-by: RizwanMunawar <chr043416@gmail.com> Co-authored-by: Francesco Mattioli <Francesco.mttl@gmail.com>
This commit is contained in:
parent
4c5bb8710a
commit
3efef8203e
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
@ -18,19 +18,19 @@ on:
|
||||
inputs:
|
||||
hub:
|
||||
description: "Run HUB"
|
||||
default: false
|
||||
default: true
|
||||
type: boolean
|
||||
benchmarks:
|
||||
description: "Run Benchmarks"
|
||||
default: false
|
||||
default: true
|
||||
type: boolean
|
||||
tests:
|
||||
description: "Run Tests"
|
||||
default: false
|
||||
default: true
|
||||
type: boolean
|
||||
gpu:
|
||||
description: "Run GPU"
|
||||
default: false
|
||||
default: true
|
||||
type: boolean
|
||||
raspberrypi:
|
||||
description: "Run Raspberry Pi"
|
||||
@ -202,7 +202,7 @@ jobs:
|
||||
fi
|
||||
pytest $slow --cov=ultralytics/ --cov-report xml tests/
|
||||
- name: Upload Coverage Reports to CodeCov
|
||||
if: github.repository == 'ultralytics/ultralytics' # && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
|
||||
if: github.repository == 'ultralytics/ultralytics' # && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
|
||||
uses: codecov/codecov-action@v5
|
||||
with:
|
||||
flags: Tests
|
||||
@ -240,7 +240,9 @@ jobs:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
||||
RaspberryPi:
|
||||
if: github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event.inputs.raspberrypi == 'true')
|
||||
# if: github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event.inputs.raspberrypi == 'true')
|
||||
# TODO: disabled to debug newer numpy compatibility issues
|
||||
if: false
|
||||
timeout-minutes: 120
|
||||
runs-on: raspberry-pi
|
||||
steps:
|
||||
@ -320,7 +322,7 @@ jobs:
|
||||
- name: Install pip packages
|
||||
run: |
|
||||
# CoreML must be installed before export due to protobuf error from AutoInstall
|
||||
pip install pytest "coremltools>=8.0; platform_system != 'Windows' and python_version <= '3.12'"
|
||||
pip install pytest "coremltools>=8.0; platform_system != 'Windows' and python_version <= '3.13'"
|
||||
- name: Check environment
|
||||
run: |
|
||||
conda list
|
||||
|
||||
16
.github/workflows/docker.yml
vendored
16
.github/workflows/docker.yml
vendored
@ -17,35 +17,35 @@ on:
|
||||
inputs:
|
||||
Dockerfile:
|
||||
type: boolean
|
||||
description: Use Dockerfile
|
||||
description: Dockerfile
|
||||
default: true
|
||||
Dockerfile-cpu:
|
||||
type: boolean
|
||||
description: Use Dockerfile-cpu
|
||||
description: Dockerfile-cpu
|
||||
default: true
|
||||
Dockerfile-arm64:
|
||||
type: boolean
|
||||
description: Use Dockerfile-arm64
|
||||
description: Dockerfile-arm64
|
||||
default: true
|
||||
Dockerfile-jetson-jetpack6:
|
||||
type: boolean
|
||||
description: Use Dockerfile-jetson-jetpack6
|
||||
description: Dockerfile-jetson-jetpack6
|
||||
default: true
|
||||
Dockerfile-jetson-jetpack5:
|
||||
type: boolean
|
||||
description: Use Dockerfile-jetson-jetpack5
|
||||
description: Dockerfile-jetson-jetpack5
|
||||
default: true
|
||||
Dockerfile-jetson-jetpack4:
|
||||
type: boolean
|
||||
description: Use Dockerfile-jetson-jetpack4
|
||||
description: Dockerfile-jetson-jetpack4
|
||||
default: true
|
||||
Dockerfile-python:
|
||||
type: boolean
|
||||
description: Use Dockerfile-python
|
||||
description: Dockerfile-python
|
||||
default: true
|
||||
Dockerfile-conda:
|
||||
type: boolean
|
||||
description: Use Dockerfile-conda
|
||||
description: Dockerfile-conda
|
||||
default: true
|
||||
push:
|
||||
type: boolean
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
# Builds ultralytics/ultralytics:latest-cpu image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics
|
||||
# Image is CPU-optimized for ONNX, OpenVINO and PyTorch YOLO11 deployments
|
||||
|
||||
# Use official Python base image for reproducibility (3.11.10 for export and 3.12.6 for inference)
|
||||
# Use official Python base image for reproducibility (3.11.10 for export and 3.12.10 for inference)
|
||||
FROM python:3.11.10-slim-bookworm
|
||||
|
||||
# Set environment variables
|
||||
|
||||
@ -33,8 +33,9 @@ COPY . .
|
||||
RUN sed -i '/^\[http "https:\/\/github\.com\/"\]/,+1d' .git/config
|
||||
ADD https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt .
|
||||
|
||||
# Pip install onnxruntime-gpu, torch, torchvision and ultralytics
|
||||
# Pip install numpy, onnxruntime-gpu, torch, torchvision and ultralytics
|
||||
RUN python3 -m pip install --upgrade pip uv
|
||||
RUN uv pip install --system numpy==1.26.4
|
||||
RUN uv pip install --system \
|
||||
https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.20.0-cp310-cp310-linux_aarch64.whl \
|
||||
https://github.com/ultralytics/assets/releases/download/v0.0.0/torch-2.5.0a0+872d972e41.nv24.08-cp310-cp310-linux_aarch64.whl \
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
# Builds ultralytics/ultralytics:latest-cpu image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics
|
||||
# Image is CPU-optimized for ONNX, OpenVINO and PyTorch YOLO11 deployments
|
||||
|
||||
# Use official Python base image for reproducibility (3.11.10 for export and 3.12.6 for inference)
|
||||
# Use official Python base image for reproducibility (3.11.10 for export and 3.12.10 for inference)
|
||||
FROM python:3.11.10-slim-bookworm
|
||||
|
||||
# Set environment variables
|
||||
|
||||
@ -18,8 +18,8 @@ ENV PYTHONUNBUFFERED=1 \
|
||||
WORKDIR /actions-runner
|
||||
|
||||
# Download and unpack the latest runner from https://github.com/actions/runner
|
||||
RUN FILENAME=actions-runner-linux-x64-2.320.0.tar.gz && \
|
||||
curl -o $FILENAME -L https://github.com/actions/runner/releases/download/v2.320.0/$FILENAME && \
|
||||
RUN FILENAME=actions-runner-linux-x64-2.323.0.tar.gz && \
|
||||
curl -o $FILENAME -L https://github.com/actions/runner/releases/download/v2.323.0/$FILENAME && \
|
||||
tar xzf $FILENAME && \
|
||||
rm $FILENAME
|
||||
|
||||
|
||||
@ -94,14 +94,13 @@ dev = [
|
||||
]
|
||||
export = [
|
||||
"onnx>=1.12.0", # ONNX export
|
||||
"coremltools>=8.0; platform_system != 'Windows' and python_version <= '3.12'", # CoreML supported on macOS and Linux
|
||||
"coremltools>=8.0; platform_system != 'Windows' and python_version <= '3.13'", # CoreML supported on macOS and Linux
|
||||
"scikit-learn>=1.3.2; platform_system != 'Windows' and python_version <= '3.12'", # CoreML k-means quantization
|
||||
"openvino>=2024.0.0", # OpenVINO export
|
||||
"tensorflow>=2.0.0", # TF bug https://github.com/ultralytics/ultralytics/issues/5161
|
||||
"tensorflowjs>=4.0.0", # TF.js export, automatically installs tensorflow
|
||||
"tensorflowjs>=2.0.0", # TF.js export, automatically installs tensorflow
|
||||
"tensorstore>=0.1.63; platform_machine == 'aarch64' and python_version >= '3.9'", # for TF Raspberry Pi exports
|
||||
"keras", # not installed automatically by tensorflow>=2.16
|
||||
"flatbuffers>=23.5.26,<100; platform_machine == 'aarch64'", # update old 'flatbuffers' included inside tensorflow package
|
||||
"h5py!=3.11.0; platform_machine == 'aarch64'", # fix h5py build issues due to missing aarch64 wheels in 3.11 release
|
||||
]
|
||||
solutions = [
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
__version__ = "8.3.116"
|
||||
__version__ = "8.3.117"
|
||||
|
||||
import os
|
||||
|
||||
|
||||
@ -82,7 +82,6 @@ from ultralytics.utils import (
|
||||
ARM64,
|
||||
DEFAULT_CFG,
|
||||
IS_COLAB,
|
||||
IS_JETSON,
|
||||
LINUX,
|
||||
LOGGER,
|
||||
MACOS,
|
||||
@ -96,6 +95,7 @@ from ultralytics.utils import (
|
||||
yaml_save,
|
||||
)
|
||||
from ultralytics.utils.checks import (
|
||||
IS_PYTHON_MINIMUM_3_12,
|
||||
check_imgsz,
|
||||
check_is_path_safe,
|
||||
check_requirements,
|
||||
@ -925,10 +925,8 @@ class Exporter:
|
||||
"onnx>=1.12.0",
|
||||
"onnx2tf>=1.26.3",
|
||||
"onnxslim>=0.1.31",
|
||||
"tflite_support<=0.4.3" if IS_JETSON else "tflite_support", # fix ImportError 'GLIBCXX_3.4.29'
|
||||
"flatbuffers>=23.5.26,<100", # update old 'flatbuffers' included inside tensorflow package
|
||||
"onnxruntime-gpu" if cuda else "onnxruntime",
|
||||
"protobuf>=5", # tflite_support pins <=4 but >=5 works
|
||||
"protobuf>=5",
|
||||
),
|
||||
cmds="--extra-index-url https://pypi.ngc.nvidia.com", # onnx_graphsurgeon only on NVIDIA
|
||||
)
|
||||
@ -1279,8 +1277,20 @@ class Exporter:
|
||||
|
||||
return f, None
|
||||
|
||||
def _add_tflite_metadata(self, file):
|
||||
def _add_tflite_metadata(self, file, use_flatbuffers=False):
|
||||
"""Add metadata to *.tflite models per https://ai.google.dev/edge/litert/models/metadata."""
|
||||
if not use_flatbuffers:
|
||||
import zipfile
|
||||
|
||||
with zipfile.ZipFile(file, "a", zipfile.ZIP_DEFLATED) as zf:
|
||||
zf.writestr("metadata.json", json.dumps(self.metadata, indent=2))
|
||||
return
|
||||
|
||||
if IS_PYTHON_MINIMUM_3_12:
|
||||
LOGGER.warning(f"TFLite Support package may not be compatible with Python>=3.12 environments for {file}")
|
||||
|
||||
# Update old 'flatbuffers' included inside tensorflow package
|
||||
check_requirements(("tflite_support", "flatbuffers>=23.5.26,<100; platform_machine == 'aarch64'"))
|
||||
import flatbuffers
|
||||
|
||||
try:
|
||||
|
||||
@ -432,10 +432,14 @@ class AutoBackend(nn.Module):
|
||||
output_details = interpreter.get_output_details() # outputs
|
||||
# Load metadata
|
||||
try:
|
||||
with zipfile.ZipFile(w, "r") as model:
|
||||
meta_file = model.namelist()[0]
|
||||
metadata = ast.literal_eval(model.read(meta_file).decode("utf-8"))
|
||||
except zipfile.BadZipFile:
|
||||
with zipfile.ZipFile(w, "r") as zf:
|
||||
name = zf.namelist()[0]
|
||||
contents = zf.read(name).decode("utf-8")
|
||||
if name == "metadata.json": # Custom Ultralytics metadata dict for Python>=3.12
|
||||
metadata = json.loads(contents)
|
||||
else:
|
||||
metadata = ast.literal_eval(contents) # Default tflite-support metadata for Python<=3.11
|
||||
except (zipfile.BadZipFile, SyntaxError, ValueError, json.JSONDecodeError):
|
||||
pass
|
||||
|
||||
# TF.js
|
||||
|
||||
@ -120,10 +120,9 @@ def benchmark(
|
||||
)
|
||||
if i in {5}: # CoreML
|
||||
assert not IS_PYTHON_3_13, "CoreML not supported on Python 3.13"
|
||||
if i in {6, 7, 8}: # TF SavedModel, TF GraphDef, and TFLite
|
||||
assert not isinstance(model, YOLOWorld), "YOLOWorldv2 TensorFlow exports not supported by onnx2tf yet"
|
||||
if i in {9, 10}: # TF EdgeTPU and TF.js
|
||||
if i in {6, 7, 8, 9, 10}: # TF SavedModel, TF GraphDef, and TFLite, TF EdgeTPU and TF.js
|
||||
assert not isinstance(model, YOLOWorld), "YOLOWorldv2 TensorFlow exports not supported by onnx2tf yet"
|
||||
# assert not IS_PYTHON_MINIMUM_3_12, "TFLite exports not supported on Python>=3.12 yet"
|
||||
if i == 11: # Paddle
|
||||
assert not isinstance(model, YOLOWorld), "YOLOWorldv2 Paddle exports not supported yet"
|
||||
assert model.task != "obb", "Paddle OBB bug https://github.com/PaddlePaddle/Paddle/issues/72024"
|
||||
@ -178,7 +177,7 @@ def benchmark(
|
||||
except Exception as e:
|
||||
if verbose:
|
||||
assert type(e) is AssertionError, f"Benchmark failure for {name}: {e}"
|
||||
LOGGER.warning(f"ERROR ❌️ Benchmark failure for {name}: {e}")
|
||||
LOGGER.error(f"Benchmark failure for {name}: {e}")
|
||||
y.append([name, emoji, round(file_size(filename), 1), None, None, None]) # mAP, t_inference
|
||||
|
||||
# Print results
|
||||
|
||||
@ -883,7 +883,9 @@ check_torchvision() # check torch-torchvision compatibility
|
||||
|
||||
# Define constants
|
||||
IS_PYTHON_3_8 = PYTHON_VERSION.startswith("3.8")
|
||||
IS_PYTHON_MINIMUM_3_10 = check_python("3.10", hard=False)
|
||||
IS_PYTHON_3_11 = PYTHON_VERSION.startswith("3.11")
|
||||
IS_PYTHON_3_12 = PYTHON_VERSION.startswith("3.12")
|
||||
IS_PYTHON_3_13 = PYTHON_VERSION.startswith("3.13")
|
||||
|
||||
IS_PYTHON_MINIMUM_3_10 = check_python("3.10", hard=False)
|
||||
IS_PYTHON_MINIMUM_3_12 = check_python("3.12", hard=False)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user