Refactor and clean up codebase by removing unused functions and reorganizing imports

- Removed unused model keys and functions from properties.py.
- Deleted projection.py as its functions were no longer needed.
- Cleaned up model_catalog.py by removing unused model directory function.
- Updated imports in various test files to reflect new module structure.
- Removed deprecated test cases related to image editing tools.
- Added new tests for ONNX runtime provider selection logic.
This commit is contained in:
2026-09-09 10:31:56 +08:00
parent 4c902ed7db
commit f5aff50b13
47 changed files with 460 additions and 413 deletions

View File

@@ -5,11 +5,9 @@ from .operators.clipboard_image import CLASSES as CLIPBOARD_CLASSES
from .menu import AnyImageImageMenu, draw_image_context_menu
from .operators import CLASSES as OPERATOR_CLASSES
from .operators.cutout_tool import CutoutTool
from .operators.image_edit_tool import (
FrameTool,
MaskTool,
RectifyTool,
)
from .operators.frame_tool import FrameTool
from .operators.mask_tool import MaskTool
from .operators.rectify_tool import RectifyTool
from .panel import ServerPanel
from .preferences import AnyImagePreferences
from .properties import AnyImageSettings

View File

@@ -12,8 +12,6 @@ from .image import (
from .node import load_node_group
DISPLACEMENT_STRENGTH = 1.0
DISPLACEMENT_MIDLEVEL = 0.0
IMAGE_MATERIAL_NODE_GROUP_NAME = "O Image Layer"
DEPTH_MATERIAL_NODE_GROUP_NAME = "O Image Depth Layer"
SHADELESS_NODE_GROUP_NAME = "O Shadeless"

View File

@@ -0,0 +1,152 @@
Files: *
Copyright: 2009-2022 the scikit-image team
License: BSD-3-Clause
Files: doc/source/themes/scikit-image/layout.html
Copyright: 2007-2010 the Sphinx team
License: BSD-3-Clause
Files: skimage/feature/_canny.py
skimage/filters/edges.py
skimage/filters/_rank_order.py
skimage/morphology/_skeletonize.py
skimage/morphology/tests/test_watershed.py
skimage/morphology/watershed.py
skimage/segmentation/heap_general.pxi
skimage/segmentation/heap_watershed.pxi
skimage/segmentation/_watershed.py
skimage/segmentation/_watershed_cy.pyx
Copyright: 2003-2009 Massachusetts Institute of Technology
2009-2011 Broad Institute
2003 Lee Kamentsky
2003-2005 Peter J. Verveer
License: BSD-3-Clause
Files: skimage/filters/thresholding.py
skimage/graph/_mcp.pyx
skimage/graph/heap.pyx
Copyright: 2009-2015 Board of Regents of the University of
Wisconsin-Madison, Broad Institute of MIT and Harvard,
and Max Planck Institute of Molecular Cell Biology and
Genetics
2009 Zachary Pincus
2009 Almar Klein
License: BSD-2-Clause
File: skimage/morphology/grayreconstruct.py
skimage/morphology/tests/test_reconstruction.py
Copyright: 2003-2009 Massachusetts Institute of Technology
2009-2011 Broad Institute
2003 Lee Kamentsky
License: BSD-3-Clause
File: skimage/morphology/_grayreconstruct.pyx
Copyright: 2003-2009 Massachusetts Institute of Technology
2009-2011 Broad Institute
2003 Lee Kamentsky
2022 Gregory Lee (added a 64-bit integer variant for large images)
License: BSD-3-Clause
File: skimage/segmentation/_expand_labels.py
Copyright: 2020 Broad Institute
2020 CellProfiler team
License: BSD-3-Clause
File: skimage/exposure/_adapthist.py
Copyright: 1994 Karel Zuiderveld
License: BSD-3-Clause
Function: skimage/morphology/_skeletonize_various_cy.pyx:_skeletonize_loop
Copyright: 2003-2009 Massachusetts Institute of Technology
2009-2011 Broad Institute
2003 Lee Kamentsky
License: BSD-3-Clause
Function: skimage/_shared/version_requirements.py:_check_version
Copyright: 2013 The IPython Development Team
License: BSD-3-Clause
Function: skimage/_shared/version_requirements.py:is_installed
Copyright: 2009-2011 Pierre Raybaut
License: MIT
File: skimage/feature/_fisher_vector.py
Copyright: 2014 2014 Dan Oneata
License: MIT
File: skimage/_vendored/numpy_lookfor.py
Copyright: 2005-2023, NumPy Developers
License: BSD-3-Clause
File: skimage/transform/_thin_plate_splines.py
Copyright: 2007 Zachary Pincus
License: BSD-3-Clause
License: BSD-2-Clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE HOLDERS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License: BSD-3-Clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE HOLDERS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -3,7 +3,9 @@ from .cutout_tool import (
CutoutSelectionToShape,
SelectCutoutSelection,
)
from .image_edit_tool import CLASSES as IMAGE_EDIT_TOOL_CLASSES
from .frame_tool import FrameImages
from .mask_tool import EditImageAlpha
from .rectify_tool import RectifyImagePerspective
from .convert_to_plane import (
ConvertToDepthPlane,
ConvertToPlane,
@@ -29,7 +31,9 @@ CLASSES = (
SelectCutoutSelection,
RunBackgroundRemoval,
ClearModels,
*IMAGE_EDIT_TOOL_CLASSES,
FrameImages,
EditImageAlpha,
RectifyImagePerspective,
RemoveImageBackground,
UpscaleImage,
ConvertToPlane,

View File

@@ -1,209 +1,15 @@
import sys
import bpy
from .actions import (
PasteTargetError,
acquire_packed_image,
paste_image,
paste_location,
target_for_context,
)
from .clipboard import (
ClipboardImageError,
ClipboardImageUnavailable,
clipboard_change_token,
clipboard_image_supported,
read_clipboard_image,
from .operators import (
CLASSES,
PasteClipboardImage,
TrackNativeCopy,
register_keymaps,
unregister_keymaps,
)
_keymap_items = []
_native_copy_token = None
class TrackNativeCopy(bpy.types.Operator):
bl_idname = "anyimage.track_native_copy"
bl_label = "Track Native Copy"
bl_description = "Preserve Blender's native copy and paste priority"
bl_options = {"INTERNAL"}
def execute(self, _context):
global _native_copy_token
_native_copy_token = clipboard_change_token()
return {"PASS_THROUGH"}
class PasteClipboardImage(bpy.types.Operator):
bl_idname = "anyimage.paste_clipboard_image"
bl_label = "Paste Clipboard Image"
bl_description = "Paste and pack the clipboard image for the current editor"
bl_options = {"REGISTER", "UNDO"}
import_as: bpy.props.EnumProperty(
name="Import As",
description="Choose the 3D View representation for the image",
items=(
(
"PLANE",
"Plane",
"Create a mesh plane with an image material",
),
(
"REFERENCE",
"Reference Image",
"Create an image Empty like dragging an image into Blender",
),
),
default="REFERENCE",
)
shadeless: bpy.props.BoolProperty(
name="Shadeless",
description=(
"Use an Emission shader so the image is unaffected by scene lighting"
),
default=False,
)
paste_target: bpy.props.StringProperty(
options={"HIDDEN", "SKIP_SAVE"},
)
location: bpy.props.FloatVectorProperty(
size=3,
options={"HIDDEN", "SKIP_SAVE"},
)
location_set: bpy.props.BoolProperty(
default=False,
options={"HIDDEN", "SKIP_SAVE"},
)
@classmethod
def poll(cls, context):
if not clipboard_image_supported():
return False
return target_for_context(context) is not None
def execute(self, context):
return self._paste(context)
def invoke(self, context, event):
self.paste_target = target_for_context(context) or ""
location = paste_location(context, event)
if location is not None:
values = tuple(location)
self.location = (*values, 0.0)[:3]
self.location_set = True
return self._paste(context, event)
def draw(self, _context):
if self.paste_target != "PLANE":
return
self.layout.prop(self, "import_as")
if self.import_as == "PLANE":
self.layout.prop(self, "shadeless")
def _paste(self, context, event=None):
if _should_defer_to_native_paste():
return {"PASS_THROUGH"}
if not self.paste_target:
self.paste_target = target_for_context(context) or ""
try:
image_data, suffix = read_clipboard_image()
except ClipboardImageUnavailable:
return {"PASS_THROUGH"}
except ClipboardImageError as error:
self.report({"ERROR"}, str(error))
return {"CANCELLED"}
image = None
image_reused = False
try:
image, image_reused = acquire_packed_image(image_data, suffix)
location = None
if self.location_set:
location = self.location
if self.paste_target == "NODE":
location = location[:2]
paste_image(
context,
image,
event,
location=location,
import_as=self.import_as,
shadeless=self.shadeless,
)
except (OSError, RuntimeError, PasteTargetError) as error:
if image is not None and not image_reused and image.users == 0:
bpy.data.images.remove(image)
self.report({"ERROR"}, f"Unable to paste clipboard image: {error}")
return {"CANCELLED"}
self.report({"INFO"}, f"Pasted and packed {image.name}")
return {"FINISHED"}
CLASSES = (TrackNativeCopy, PasteClipboardImage)
def register_keymaps():
_register_keymaps()
def unregister_keymaps():
global _native_copy_token
_unregister_keymaps()
_native_copy_token = None
def _should_defer_to_native_paste():
if _native_copy_token is None:
return False
return clipboard_change_token() == _native_copy_token
def _register_keymaps():
if not clipboard_image_supported():
return
window_manager = getattr(bpy.context, "window_manager", None)
keyconfigs = getattr(window_manager, "keyconfigs", None)
addon_keyconfig = getattr(keyconfigs, "addon", None)
if addon_keyconfig is None:
return
keymap_definitions = (
("3D View", "VIEW_3D"),
("Node Editor", "NODE_EDITOR"),
)
for keymap_name, space_type in keymap_definitions:
keymap = addon_keyconfig.keymaps.new(
name=keymap_name,
space_type=space_type,
)
modifiers = (
{"oskey": True}
if sys.platform == "darwin"
else {"ctrl": True}
)
keymap_item = keymap.keymap_items.new(
PasteClipboardImage.bl_idname,
"V",
"PRESS",
**modifiers,
)
_keymap_items.append((keymap, keymap_item))
copy_keymap_item = keymap.keymap_items.new(
TrackNativeCopy.bl_idname,
"C",
"PRESS",
**modifiers,
)
_keymap_items.append((keymap, copy_keymap_item))
def _unregister_keymaps():
for keymap, keymap_item in _keymap_items:
keymap.keymap_items.remove(keymap_item)
_keymap_items.clear()
__all__ = (
"CLASSES",
"PasteClipboardImage",
"TrackNativeCopy",
"register_keymaps",
"unregister_keymaps",
)

View File

@@ -0,0 +1,201 @@
import sys
import bpy
from .actions import (
PasteTargetError,
acquire_packed_image,
paste_image,
paste_location,
target_for_context,
)
from .clipboard import (
ClipboardImageError,
ClipboardImageUnavailable,
clipboard_change_token,
clipboard_image_supported,
read_clipboard_image,
)
_keymap_items = []
_native_copy_token = None
class TrackNativeCopy(bpy.types.Operator):
bl_idname = "anyimage.track_native_copy"
bl_label = "Track Native Copy"
bl_description = "Preserve Blender's native copy and paste priority"
bl_options = {"INTERNAL"}
def execute(self, _context):
global _native_copy_token
_native_copy_token = clipboard_change_token()
return {"PASS_THROUGH"}
class PasteClipboardImage(bpy.types.Operator):
bl_idname = "anyimage.paste_clipboard_image"
bl_label = "Paste Clipboard Image"
bl_description = "Paste and pack the clipboard image for the current editor"
bl_options = {"REGISTER", "UNDO"}
import_as: bpy.props.EnumProperty(
name="Import As",
description="Choose the 3D View representation for the image",
items=(
(
"PLANE",
"Plane",
"Create a mesh plane with an image material",
),
(
"REFERENCE",
"Reference Image",
"Create an image Empty like dragging an image into Blender",
),
),
default="REFERENCE",
)
shadeless: bpy.props.BoolProperty(
name="Shadeless",
description=(
"Use an Emission shader so the image is unaffected by scene lighting"
),
default=False,
)
paste_target: bpy.props.StringProperty(
options={"HIDDEN", "SKIP_SAVE"},
)
location: bpy.props.FloatVectorProperty(
size=3,
options={"HIDDEN", "SKIP_SAVE"},
)
location_set: bpy.props.BoolProperty(
default=False,
options={"HIDDEN", "SKIP_SAVE"},
)
@classmethod
def poll(cls, context):
if not clipboard_image_supported():
return False
return target_for_context(context) is not None
def execute(self, context):
return self._paste(context)
def invoke(self, context, event):
self.paste_target = target_for_context(context) or ""
location = paste_location(context, event)
if location is not None:
values = tuple(location)
self.location = (*values, 0.0)[:3]
self.location_set = True
return self._paste(context, event)
def draw(self, _context):
if self.paste_target != "PLANE":
return
self.layout.prop(self, "import_as")
if self.import_as == "PLANE":
self.layout.prop(self, "shadeless")
def _paste(self, context, event=None):
if _should_defer_to_native_paste():
return {"PASS_THROUGH"}
if not self.paste_target:
self.paste_target = target_for_context(context) or ""
try:
image_data, suffix = read_clipboard_image()
except ClipboardImageUnavailable:
return {"PASS_THROUGH"}
except ClipboardImageError as error:
self.report({"ERROR"}, str(error))
return {"CANCELLED"}
image = None
image_reused = False
try:
image, image_reused = acquire_packed_image(image_data, suffix)
location = None
if self.location_set:
location = self.location
if self.paste_target == "NODE":
location = location[:2]
paste_image(
context,
image,
event,
location=location,
import_as=self.import_as,
shadeless=self.shadeless,
)
except (OSError, RuntimeError, PasteTargetError) as error:
if image is not None and not image_reused and image.users == 0:
bpy.data.images.remove(image)
self.report({"ERROR"}, f"Unable to paste clipboard image: {error}")
return {"CANCELLED"}
self.report({"INFO"}, f"Pasted and packed {image.name}")
return {"FINISHED"}
CLASSES = (TrackNativeCopy, PasteClipboardImage)
def unregister_keymaps():
global _native_copy_token
for keymap, keymap_item in _keymap_items:
keymap.keymap_items.remove(keymap_item)
_keymap_items.clear()
_native_copy_token = None
def _should_defer_to_native_paste():
if _native_copy_token is None:
return False
return clipboard_change_token() == _native_copy_token
def register_keymaps():
if not clipboard_image_supported():
return
window_manager = getattr(bpy.context, "window_manager", None)
keyconfigs = getattr(window_manager, "keyconfigs", None)
addon_keyconfig = getattr(keyconfigs, "addon", None)
if addon_keyconfig is None:
return
keymap_definitions = (
("3D View", "VIEW_3D"),
("Node Editor", "NODE_EDITOR"),
)
for keymap_name, space_type in keymap_definitions:
keymap = addon_keyconfig.keymaps.new(
name=keymap_name,
space_type=space_type,
)
modifiers = (
{"oskey": True}
if sys.platform == "darwin"
else {"ctrl": True}
)
keymap_item = keymap.keymap_items.new(
PasteClipboardImage.bl_idname,
"V",
"PRESS",
**modifiers,
)
_keymap_items.append((keymap, keymap_item))
copy_keymap_item = keymap.keymap_items.new(
TrackNativeCopy.bl_idname,
"C",
"PRESS",
**modifiers,
)
_keymap_items.append((keymap, copy_keymap_item))

View File

@@ -1,6 +1,6 @@
"""Rectangular Plane and Depth Plane conversion operators."""
from .conversion import (
from .operators import (
ConvertToDepthPlane,
ConvertToPlane,
GenerateDepthPlane,

View File

@@ -1,4 +1,4 @@
from .main import CutoutSelectionToShape, CutoutTool, SelectCutoutSelection
from .operators import CutoutSelectionToShape, CutoutTool, SelectCutoutSelection
__all__ = (
"CutoutSelectionToShape",

View File

@@ -874,9 +874,6 @@ def teddy_balloon_heights(
)
DEFAULT_ALGORITHM = "POISSON"
def cotangent_poisson_field(
planar_points,
planar_faces,

View File

@@ -2,7 +2,7 @@ import math
import bpy
from ...common.image import (
from ..common.image import (
MAX_PROJECTIVE_OUTPUT_PIXELS,
PROJECTIVE_CHUNK_ROWS,
create_image_edit_result,
@@ -16,8 +16,8 @@ from ...common.image import (
transform_homography,
video_total_frames,
)
from ...preferences import configured_max_frame_resolution
from ...common.viewport import (
from ..preferences import configured_max_frame_resolution
from ..common.viewport import (
active_image_edit_source,
active_view3d_tool_id,
draw_dashed_line,
@@ -28,7 +28,7 @@ from ...common.viewport import (
rectangle_screen_path,
report_image_edit_exception,
)
from ...common.selection import ImageEditWarning, clip_polygon_halfplanes
from ..common.selection import ImageEditWarning, clip_polygon_halfplanes
FRAME_TOOL_ID = "anyimage.frame"
PROJECTIVE_RELATIVE_EPSILON = 1e-12
@@ -646,17 +646,3 @@ class FrameTool(bpy.types.WorkSpaceTool):
bl_icon = "ops.sculpt.border_mask"
bl_operator = FrameImages.bl_idname
bl_keymap = image_edit_drag_keymap(FrameImages.bl_idname)
class ActivateImageEditTool(bpy.types.Operator):
bl_idname = "anyimage.activate_image_edit_tool"
bl_label = "Image Edit"
bl_description = "Activate Frame in the 3D Viewport"
bl_options = {"INTERNAL"}
@classmethod
def poll(cls, context):
return image_edit_poll(context)
def execute(self, _context):
return bpy.ops.wm.tool_set_by_id(name=FRAME_TOOL_ID, space_type="VIEW_3D")

View File

@@ -1,18 +0,0 @@
from .frame import ActivateImageEditTool, FrameImages, FrameTool
from .mask import EditImageAlpha, MaskTool
from .rectify import RectifyImagePerspective, RectifyTool
CLASSES = (
FrameImages,
EditImageAlpha,
ActivateImageEditTool,
RectifyImagePerspective,
)
__all__ = (
"CLASSES",
"FrameTool",
"MaskTool",
"RectifyTool",
)

View File

@@ -1,25 +1,25 @@
import bpy
from ...common.image import (
from ..common.image import (
create_image_edit_result,
image_empty_bounds,
image_rgba,
replace_empty_image,
require_image_empty,
)
from ...common.selection import (
from ..common.selection import (
rasterize_selection_path,
rasterize_selection_union,
SelectionPath,
)
from ...common.viewport import (
from ..common.viewport import (
brush_footprint_polygons,
ImageGesture,
image_edit_point_keymap,
report_image_edit_exception,
screen_path_to_image_pixels,
)
from ...properties import (
from ..properties import (
mask_gesture_property,
mask_mode_property,
mask_radius_property,

View File

@@ -3,7 +3,7 @@ import math
import bpy
from ...common.viewport import (
from ..common.viewport import (
active_view3d_tool_id,
deserialize_matrix,
draw_dashed_line,
@@ -16,8 +16,8 @@ from ...common.viewport import (
screen_path_to_image_pixels,
serialize_matrix,
)
from ...common.selection import clip_polygon_halfplanes, trim_pixels_to_alpha
from ...common.image import (
from ..common.selection import clip_polygon_halfplanes, trim_pixels_to_alpha
from ..common.image import (
create_image_edit_result,
image_base_name,
image_pixels,

View File

@@ -9,8 +9,6 @@ from .server import model_catalog as shared_model_catalog
BEN2_MODEL_KEY = "BEN2_BASE"
REALESRGAN_GENERAL_WDN_MODEL_KEY = shared_model_catalog.DEFAULT_UPSCALE_MODEL_KEY
SAFMN_MODEL_KEY = shared_model_catalog.SAFMN_MODEL.key
REALESRGAN_X4PLUS_MODEL_KEY = shared_model_catalog.REALESRGAN_X4PLUS.key
DEFAULT_MOGE2_MODEL_KEY = "MOGE2_VITS_NORMAL"
REQUIRED_MODEL_KEYS = (
DEFAULT_MOGE2_MODEL_KEY,
@@ -85,10 +83,6 @@ def model_ready(model_key):
)
def required_models_ready():
return not ai_status()["missing_models"]
def ai_status():
environment_ready = runtime.environment_ready()
ready_models = {model["key"] for model in model_catalog() if model.get("ready")}

View File

@@ -1,7 +1 @@
from .projection import unproject_camera_depth, unproject_depth_frame
__all__ = (
"unproject_camera_depth",
"unproject_depth_frame",
)
"""Depth and normal artifact processing."""

View File

@@ -1,31 +0,0 @@
def unproject_depth_frame(depth, intrinsics, extrinsics):
import numpy as np
height, width = depth.shape
x, y = np.meshgrid(
np.arange(width, dtype=np.float32),
np.arange(height, dtype=np.float32),
)
pixels = np.stack((x, y, np.ones_like(x)), axis=-1).reshape(-1, 3)
rays = (np.linalg.inv(intrinsics) @ pixels.T).T
camera_points = rays * depth.reshape(-1, 1)
camera_points = np.column_stack(
(camera_points, np.ones(camera_points.shape[0], dtype=np.float32))
)
world_to_camera = np.eye(4, dtype=np.float32)
world_to_camera[: extrinsics.shape[0], :4] = extrinsics
world_points = (np.linalg.inv(world_to_camera) @ camera_points.T).T
return world_points[:, :3].reshape(height, width, 3)
def unproject_camera_depth(depth, intrinsics):
import numpy as np
height, width = depth.shape
x, y = np.meshgrid(
np.arange(width, dtype=np.float32),
np.arange(height, dtype=np.float32),
)
pixels = np.stack((x, y, np.ones_like(x)), axis=-1).reshape(-1, 3)
rays = (np.linalg.inv(intrinsics) @ pixels.T).T
return (rays * depth.reshape(-1, 1)).reshape(height, width, 3)

View File

@@ -178,7 +178,6 @@ MOGE2_MODELS = {
),),
),
}
MOGE2_MODEL = MOGE2_MODELS["MOGE2_VITS_NORMAL"]
DOWNLOADABLE_MODELS = {
BEN2_MODEL.key: BEN2_MODEL,
**UPSCALE_MODELS,
@@ -193,11 +192,6 @@ def get_downloadable_model(model_key):
raise ValueError(f"Unknown model: {model_key}") from error
def model_directory_name(model_key):
"""Return the model's folder name inside the shared models directory."""
return get_downloadable_model(model_key).directory_name
def model_record(model, ready=False):
"""Return public model metadata exposed by the Models Resource."""
return {

View File

@@ -4,7 +4,6 @@ from pathlib import Path
from .onnx_runtime import create_session as create_runtime_session
from .onnx_runtime import run_session
from .onnx_runtime import select_providers as select_providers
ONNX_FILENAME = "model.onnx"
@@ -15,10 +14,6 @@ COREML_PROVIDER_OPTIONS = {
}
def is_onnx_model(model_directory):
return (Path(model_directory) / ONNX_FILENAME).is_file()
def create_session(model_directory, requested_device="auto"):
path = Path(model_directory) / ONNX_FILENAME
return create_runtime_session(

View File

@@ -95,15 +95,3 @@ def run_session(
"gpu:0",
)
return session.run(output_names, input_feed, run_options=run_options)
def provider_label(session):
provider = session.get_providers()[0]
labels = {
"CUDAExecutionProvider": "CUDA",
"CoreMLExecutionProvider": "CoreML",
"DmlExecutionProvider": "DirectML",
"OpenVINOExecutionProvider": "OpenVINO",
"CPUExecutionProvider": "CPU",
}
return labels.get(provider, provider)