@@ -1,10 +1,10 @@
|
||||
## <img src="images/depth-estimation-logo-with-smaller-z.svg" width="32" height="32" alt="Depth Estimation Icon" style="vertical-align: middle"> ComfyUIDepthEstimation ComfyUIDepthEstimation
|
||||
## <img src="images/depth-estimation-logo-with-smaller-z.svg" width="32" height="32" alt="Depth Estimation Icon" style="vertical-align: middle"> ComfyUI Depth Estimation Node
|
||||
|
||||
<div align="center">
|
||||
<img src="images/depth-estimation-logo-with-smaller-z.svg" width="150" height="150" alt="Depth Estimation Logo">
|
||||
</div>
|
||||
|
||||
A custom depth estimation node for ComfyUI using Depth-Anything models to generate depth maps from images.
|
||||
A robust custom depth estimation node for ComfyUI using Depth-Anything models to generate depth maps from images.
|
||||
|
||||
## Features
|
||||
- Multiple model options:
|
||||
@@ -18,26 +18,39 @@ A custom depth estimation node for ComfyUI using Depth-Anything models to genera
|
||||
- Median filtering (configurable size)
|
||||
- Automatic contrast enhancement
|
||||
- Gamma correction
|
||||
- Advanced options:
|
||||
- Force CPU processing for compatibility
|
||||
- Force model reload for troubleshooting
|
||||
|
||||
## Installation
|
||||
1. Clone the repository:
|
||||
|
||||
### Method 1: Install via ComfyUI Manager (Recommended)
|
||||
1. Open ComfyUI and install the ComfyUI Manager if you haven't already
|
||||
2. Go to the Manager tab
|
||||
3. Search for "Depth Estimation" and install the node
|
||||
|
||||
### Method 2: Manual Installation
|
||||
1. Navigate to your ComfyUI custom nodes directory:
|
||||
```bash
|
||||
git clone https://github.com/yourusername/ComfyUIDepthEstimation.git
|
||||
cd ComfyUI/custom_nodes/
|
||||
```
|
||||
|
||||
2. Navigate to the repository directory:
|
||||
|
||||
2. Clone the repository:
|
||||
```bash
|
||||
cd ComfyUIDepthEstimation
|
||||
git clone https://github.com/Limbicnation/ComfyUIDepthEstimation.git
|
||||
```
|
||||
|
||||
3. Install the required dependencies:
|
||||
|
||||
```bash
|
||||
cd ComfyUIDepthEstimation
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
# Usage
|
||||
4. Restart ComfyUI to load the new custom node.
|
||||
|
||||
> **Note**: On first use, the node will download the selected model from Hugging Face. This may take some time depending on your internet connection.
|
||||
|
||||
## Usage
|
||||
|
||||
<div align="center">
|
||||
<img src="images/depth-estimation-node.png" width="600" alt="Depth Estimation Node Preview">
|
||||
@@ -46,39 +59,96 @@ A custom depth estimation node for ComfyUI using Depth-Anything models to genera
|
||||
<img src="images/depth_map_generator_showcase.jpg" width="600" alt="Depth Map Generator Showcase">
|
||||
</div>
|
||||
|
||||
## Node Parameters
|
||||
### Node Parameters
|
||||
|
||||
Node Parameters
|
||||
#### Required Parameters
|
||||
- **image**: Input image (IMAGE type)
|
||||
- **model_name**: Select from available Depth-Anything models
|
||||
- **blur_radius**: Gaussian blur radius (0.0 - 10.0, default: 2.0)
|
||||
- **median_size**: Median filter size (3, 5, 7, 9, 11)
|
||||
- **apply_auto_contrast**: Enable automatic contrast enhancement
|
||||
- **apply_gamma**: Enable gamma correction
|
||||
|
||||
- image: Input image (IMAGE type)
|
||||
- model_name: Select from available Depth-Anything models
|
||||
- blur_radius: Gaussian blur radius (0.0 - 10.0, default: 2.0)
|
||||
- median_size: Median filter size (3, 5, 7, 9, 11)
|
||||
- apply_auto_contrast: Enable automatic contrast enhancement
|
||||
- apply_gamma: Enable gamma correction
|
||||
|
||||
### Integrate with ComfyUI
|
||||
|
||||
1. Copy the `depth_estimation_node.py` file to your ComfyUI custom nodes directory.
|
||||
|
||||
2. Update ComfyUI configuration to include the custom node if necessary.
|
||||
|
||||
3. Restart ComfyUI to load the new custom node.
|
||||
#### Optional Parameters
|
||||
- **force_reload**: Force the model to reload (useful for troubleshooting)
|
||||
- **force_cpu**: Use CPU for processing instead of GPU (slower but more compatible)
|
||||
|
||||
### Example Usage
|
||||
1. Add the `Depth Estimation` node to your ComfyUI workflow
|
||||
2. Connect an image source to the node's image input
|
||||
3. Configure the parameters:
|
||||
- Select a model (e.g., "Depth-Anything-V2-Small")
|
||||
- Select a model (e.g., "Depth-Anything-V2-Small" is fastest)
|
||||
- Adjust blur_radius (0-10) for depth map smoothing
|
||||
- Choose median_size (3-11) for noise reduction
|
||||
- Toggle auto_contrast and gamma correction as needed
|
||||
4. Connect the output to a Preview Image node or other image processing nodes
|
||||
|
||||
The node will process the input image and output a depth map that can be used in your ComfyUI workflow.
|
||||
## Model Information
|
||||
|
||||
| Model Name | Quality | VRAM Usage | Speed |
|
||||
|------------|---------|------------|-------|
|
||||
| Depth-Anything-V2-Small | Good | ~1.5 GB | Fast |
|
||||
| Depth-Anything-Small | Good | ~1.5 GB | Fast |
|
||||
| Depth-Anything-V2-Base | Better | ~2.5 GB | Medium |
|
||||
| Depth-Anything-Base | Better | ~2.5 GB | Medium |
|
||||
| Depth-Anything-Large | Best | ~4.0 GB | Slow |
|
||||
|
||||
## Troubleshooting Guide
|
||||
|
||||
### Common Issues and Solutions
|
||||
|
||||
#### Model Download Issues
|
||||
- **Error**: "Failed to load model" or "Model not found"
|
||||
- **Solution**:
|
||||
1. Check your internet connection
|
||||
2. Try authenticating with Hugging Face:
|
||||
```bash
|
||||
pip install huggingface_hub
|
||||
huggingface-cli login
|
||||
```
|
||||
3. Try a different model (e.g., switch to Depth-Anything-V2-Small)
|
||||
4. Check the ComfyUI console for detailed error messages
|
||||
|
||||
#### CUDA Out of Memory Errors
|
||||
- **Error**: "CUDA out of memory" or node shows red error image
|
||||
- **Solution**:
|
||||
1. Try a smaller model (Depth-Anything-V2-Small uses the least memory)
|
||||
2. Enable the `force_cpu` option (slower but uses less VRAM)
|
||||
3. Reduce the size of your input image
|
||||
4. Close other VRAM-intensive applications
|
||||
|
||||
#### Node Not Appearing in ComfyUI
|
||||
- **Solution**:
|
||||
1. Check your ComfyUI console for error messages
|
||||
2. Verify that all dependencies are installed:
|
||||
```bash
|
||||
pip install transformers>=4.20.0 Pillow>=9.1.0 numpy>=1.23.0 timm>=0.6.12
|
||||
```
|
||||
3. Try restarting ComfyUI
|
||||
4. Check that the node files are in the correct directory
|
||||
|
||||
#### Node Returns Original Image or Black Image
|
||||
- **Solution**:
|
||||
1. Try enabling the `force_reload` option
|
||||
2. Check the ComfyUI console for error messages
|
||||
3. Try using a different model
|
||||
4. Make sure your input image is valid (not corrupted or empty)
|
||||
5. Try restarting ComfyUI
|
||||
|
||||
#### Slow Performance
|
||||
- **Solution**:
|
||||
1. Use a smaller model (Depth-Anything-V2-Small is fastest)
|
||||
2. Reduce input image size
|
||||
3. If using CPU mode, consider using GPU if available
|
||||
4. Close other applications that might be using GPU resources
|
||||
|
||||
### Where to Get Help
|
||||
- Create an issue on the [GitHub repository](https://github.com/Limbicnation/ComfyUIDepthEstimation/issues)
|
||||
- Check the ComfyUI console for detailed error messages
|
||||
- Visit the ComfyUI Discord for community support
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the Apache License.
|
||||
|
||||
---
|
||||
---
|
||||
+109
-12
@@ -1,26 +1,123 @@
|
||||
"""
|
||||
ComfyUI Depth Estimation Node
|
||||
A custom node for depth map estimation using Depth-Anything-V2-Small model.
|
||||
A custom node for depth map estimation using Depth-Anything models.
|
||||
"""
|
||||
|
||||
from .depth_estimation_node import DepthEstimationNode
|
||||
import os
|
||||
import logging
|
||||
import importlib.util
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger("DepthEstimation")
|
||||
|
||||
# Version info
|
||||
__version__ = "1.0.0"
|
||||
__version__ = "1.1.0"
|
||||
|
||||
# Node class mapping for ComfyUI registration
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"DepthEstimationNode": DepthEstimationNode
|
||||
}
|
||||
|
||||
# Display names for UI
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"DepthEstimationNode": "Depth Estimation"
|
||||
}
|
||||
# Node class mappings - will be populated based on dependency checks
|
||||
NODE_CLASS_MAPPINGS = {}
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {}
|
||||
|
||||
# Web extension info for ComfyUI
|
||||
WEB_DIRECTORY = "./js"
|
||||
|
||||
# Graceful dependency checking
|
||||
required_dependencies = {
|
||||
"torch": "2.0.0",
|
||||
"transformers": "4.20.0",
|
||||
"numpy": "1.23.0",
|
||||
"PIL": "9.2.0", # Pillow is imported as PIL
|
||||
"timm": "0.6.12",
|
||||
"huggingface_hub": "0.16.0"
|
||||
}
|
||||
|
||||
missing_dependencies = []
|
||||
|
||||
# Check each dependency
|
||||
for module_name, min_version in required_dependencies.items():
|
||||
try:
|
||||
if module_name == "PIL":
|
||||
# Special case for Pillow/PIL
|
||||
import PIL
|
||||
module_version = PIL.__version__
|
||||
else:
|
||||
module = __import__(module_name)
|
||||
module_version = getattr(module, "__version__", "unknown")
|
||||
|
||||
logger.info(f"Found {module_name} version {module_version}")
|
||||
except ImportError:
|
||||
missing_dependencies.append(f"{module_name}>={min_version}")
|
||||
logger.warning(f"Missing required dependency: {module_name}>={min_version}")
|
||||
|
||||
if missing_dependencies:
|
||||
# Create placeholder node with dependency error
|
||||
class DependencyErrorNode:
|
||||
"""Placeholder node that shows dependency installation instructions."""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {}}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "error_message"
|
||||
CATEGORY = "depth"
|
||||
|
||||
def error_message(self):
|
||||
missing = ", ".join(missing_dependencies)
|
||||
message = f"Dependencies missing: {missing}. Please install with: pip install {' '.join(missing_dependencies)}"
|
||||
print(f"DepthEstimation Node Error: {message}")
|
||||
return (message,)
|
||||
|
||||
# Register the error node instead of the real node
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"DepthEstimationNode": DependencyErrorNode
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"DepthEstimationNode": "Depth Estimation (Missing Dependencies)"
|
||||
}
|
||||
else:
|
||||
# All dependencies are available, try to import the actual node
|
||||
try:
|
||||
from .depth_estimation_node import DepthEstimationNode
|
||||
|
||||
# Register the actual depth estimation node
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"DepthEstimationNode": DepthEstimationNode
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"DepthEstimationNode": "Depth Estimation"
|
||||
}
|
||||
except Exception as e:
|
||||
# Capture any import errors that might occur with transformers
|
||||
logger.error(f"Error importing depth estimation node: {str(e)}")
|
||||
|
||||
# Create a more specific error node
|
||||
class TransformersErrorNode:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {}}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "error_message"
|
||||
CATEGORY = "depth"
|
||||
|
||||
def error_message(self):
|
||||
if "Descriptors cannot be created directly" in str(e):
|
||||
message = "Protobuf version conflict. Run: pip install protobuf==3.20.3"
|
||||
else:
|
||||
message = f"Error loading depth estimation: {str(e)}"
|
||||
return (message,)
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"DepthEstimationNode": TransformersErrorNode
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"DepthEstimationNode": "Depth Estimation (Error)"
|
||||
}
|
||||
|
||||
# Module exports
|
||||
__all__ = [
|
||||
"NODE_CLASS_MAPPINGS",
|
||||
|
||||
+2528
-165
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 281 KiB After Width: | Height: | Size: 90 KiB |
+12
-6
@@ -1,15 +1,21 @@
|
||||
[project]
|
||||
name = "comfyuidepthestimation"
|
||||
description = "A custom depth estimation node for ComfyUI using transformer models. It integrates depth estimation with automatic gamma correction, contrast adjustment, and edge detection, based on the [a/TransformDepth](https://github.com/Limbicnation/TransformDepth) repository."
|
||||
version = "1.0.0"
|
||||
description = "A robust custom depth estimation node for ComfyUI using Depth-Anything models. It integrates depth estimation with configurable post-processing options including blur, median filtering, contrast enhancement, and gamma correction."
|
||||
version = "1.1.0"
|
||||
license = { file = "LICENSE" }
|
||||
dependencies = ["transformers==4.12.3", "Pillow==8.4.0", "numpy==1.21.2", "# Add other necessary dependencies without specifying torch again"]
|
||||
dependencies = [
|
||||
"transformers>=4.20.0",
|
||||
"Pillow>=9.1.0",
|
||||
"numpy>=1.23.0",
|
||||
"timm>=0.6.12",
|
||||
"huggingface-hub>=0.16.0"
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
Repository = "https://github.com/Limbicnation/ComfyUIDepthEstimation"
|
||||
# Used by Comfy Registry https://comfyregistry.org
|
||||
|
||||
[tool.comfy]
|
||||
PublisherId = ""
|
||||
DisplayName = "ComfyUIDepthEstimation"
|
||||
Icon = ""
|
||||
PublisherId = "Limbicnation"
|
||||
DisplayName = "Depth Estimation Node"
|
||||
Icon = "images/depth-estimation-icon.png"
|
||||
+25
-7
@@ -1,9 +1,27 @@
|
||||
# Core dependencies matching ComfyUI
|
||||
torch>=2.0.0
|
||||
transformers>=4.28.1
|
||||
Pillow>=9.0.0
|
||||
numpy>=1.21.2
|
||||
# requirements.txt for ComfyUI-DepthEstimation Node
|
||||
# Note: These are minimum requirements. ComfyUI's environment may provide newer versions.
|
||||
|
||||
# Fix for protobuf errors with transformers
|
||||
protobuf==3.20.3
|
||||
|
||||
# Core dependencies
|
||||
tokenizers>=0.13.3 # Pre-built version compatible with most platforms
|
||||
transformers>=4.20.0 # Required for Depth Anything models, but ComfyUI may have a specific version
|
||||
|
||||
# Pillow (PIL Fork) - Compatibility with other ComfyUI nodes
|
||||
Pillow>=9.2.0 # Ensures compatibility with nodes requiring >=9.2.0
|
||||
|
||||
# NumPy - Using version that properly supports numpy.dtypes
|
||||
numpy>=1.23.0 # Resolves compatibility issues
|
||||
|
||||
# Additional dependencies specific to depth estimation node
|
||||
timm>=0.6.12 # Required for depth estimation models
|
||||
huggingface-hub>=0.16.0 # For model downloading
|
||||
timm>=0.6.12 # Required for Depth Anything models
|
||||
huggingface-hub>=0.16.0 # For model downloading
|
||||
wget>=3.2 # For reliable model downloading
|
||||
|
||||
# Torch version requirements
|
||||
# Note: PyTorch dependencies are handled by ComfyUI's core installation
|
||||
# If you're installing this node directly, ensure torch>=2.0.0 is available
|
||||
|
||||
# Network dependencies
|
||||
requests>=2.27.0 # For model downloading
|
||||
Reference in New Issue
Block a user