9 Commits
13 changed files with 1620 additions and 1029 deletions
+5 -1
View File
@@ -8,15 +8,19 @@ on:
paths:
- "pyproject.toml"
permissions:
issues: write
jobs:
publish-node:
name: Publish Custom Node to registry
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'leoleelxh' }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Publish Custom Node
uses: Comfy-Org/publish-node-action@main
uses: Comfy-Org/publish-node-action@v1
with:
## Add your own personal access token to your Github Repository secrets and reference it here.
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
+11 -1
View File
@@ -1 +1,11 @@
__pycache__
__pycache__
pyproject.toml
node.zip
node_modules
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
.env.development
.env.test
+26
View File
@@ -1,5 +1,31 @@
# Changelog
## [1.0.0] - 2025-04-19
### Added
- 全新的智能图像格式处理系统,支持多种 PyTorch 张量格式
- 新增 `find_output_file` 辅助函数,能智能查找 Topaz 处理后的输出文件
- 新增 `output_prefix` 可选参数,允许用户自定义输出文件名前缀
- 更全面的日志系统,提供详细的处理信息和错误诊断
### Fixed
- 修复了处理 PyTorch 张量时的格式兼容问题,现可正确处理 [B, H, W, C]、[C, H, W] 等多种格式
- 修复了输出文件检测逻辑,能够找到 Topaz 使用不同命名规则的输出文件
- 修复了临时文件清理机制中的异常处理问题
- 改进了图像加载过程,添加了 EXIF 方向处理和图像模式转换
### Changed
- 重构了 `process_topaz_image` 函数,添加了多重检测方法和重试机制
- 改进了 `save_images` 函数,现在能处理更多图像格式和异常情况
- 优化了输出图像的后处理逻辑,与 ComfyUI 更好地兼容
- 更新了错误处理机制,确保即使在处理失败时也能返回原始图像
### Improved
- 大幅提高了与 Topaz Photo AI 的通信可靠性
- 优化了图像处理流程,提供更详细的调试信息
- 增强了错误恢复能力,添加了自动重试机制
- 更清晰的日志输出,方便用户排查问题
## [Unreleased] - 2025-04-12
### Fixed
+214 -197
View File
@@ -1,10 +1,21 @@
# ComfyUI Node for Topaz Photo AI (`ComfyTopazPhoto`)
![Topaz Photo AI Sample](sample.jpg)
Integrate Topaz Photo AI's powerful image enhancement capabilities directly into your ComfyUI workflows.
This node allows you to call the `tpai.exe` command-line interface from within ComfyUI to upscale, sharpen, denoise, and apply other adjustments offered by Topaz Photo AI.
This node allows you to call the `tpai.exe` command-line interface from within ComfyUI to apply enhancements offered by Topaz Photo AI through its Autopilot settings.
**Note:** This node is based on the work of [choey/Comfy-Topaz](https://github.com/choey/Comfy-Topaz) and has been adapted and debugged for compatibility with newer versions of Topaz Photo AI.
## 重要更新: v1.0.0 版本发布
我们很高兴地宣布 ComfyTopazPhoto 节点 v1.0.0 版本正式发布!此版本解决了多个关键问题并大幅提升了稳定性:
- **全新图像格式处理系统**:现在支持多种 PyTorch 张量格式,能够正确处理 ComfyUI 中的各种图像格式
- **智能输出文件检测**:新增 `find_output_file` 功能,能够在 Topaz 使用不同命名规则时仍能找到输出文件
- **出错后自动恢复**:添加了重试机制和更好的异常处理,确保在遇到问题时能继续工作
- **更详细的日志输出**:便于排查问题和了解处理过程
该扩展现已完全简化,专注于通过 Topaz Photo AI CLI 使用 Autopilot 设置进行基本图像处理。所有增强参数现在应该通过 Topaz Photo AI GUI 中的 Autopilot 设置进行配置。
## Requirements
@@ -15,217 +26,223 @@ This node allows you to call the `tpai.exe` command-line interface from within C
1. Clone this repository into your `ComfyUI/custom_nodes/` directory:
```bash
git clone <your-repo-url> ComfyUI/custom_nodes/ComfyTopazPhoto
git clone https://github.com/leoleelxh/Comfy-Topaz-Photo
```
(Replace `<your-repo-url>` with the actual URL of this repository)
2. Alternatively, download the repository contents as a ZIP file and extract it into `ComfyUI/custom_nodes/ComfyTopazPhoto`.
2. Alternatively, download the repository contents as a ZIP file and extract it into `ComfyUI/custom_nodes/Comfy-Topaz-Photo`.
3. **Restart ComfyUI.**
## Usage
## 使用流程详解
**⚠️ CRITICAL UPSCALING REQUIREMENT ⚠️**
### 完整工作流程
The upscale factor (`scale`) for Topaz Photo AI **cannot be controlled** from within ComfyUI using this node. You **must** set your desired upscale factor directly in the Topaz Photo AI application settings:
使用 ComfyTopazPhoto 的完整流程包括以下几个步骤:
1. Open Topaz Photo AI application
2. Go to **Preferences -> Autopilot -> Upscale & Resize**
3. Set your desired fixed upscale factor (e.g., 2x, 4x)
4. Save preferences
1. **安装前准备**
- 确保 Topaz Photo AI 正确安装并激活
- 确认 AI 模型已正确下载(可以通过打开 Topaz Photo AI 并处理一张测试图像来验证)
- 确认 `tpai.exe` 的正确路径(通常在 `C:\Program Files\Topaz Labs LLC\Topaz Photo AI\tpai.exe`)
The corresponding input for `scale` **is not available** on the `ComfyTopazPhoto Upscale Settings` node because it would be **ignored** by the application.
2. **配置 Autopilot 设置**
- 打开 Topaz Photo AI 应用程序
- 进入 **Preferences -> Autopilot**
- 根据需要配置增强参数:
* **Upscale & Resize**: 选择放大比例(2x、4x等)
* **Face Recovery**: 调整面部恢复强度
* **Sharpen**: 调整锐化程度
* **Denoise**: 设置降噪级别
* **文字恢复**: 如需要,启用文字恢复功能
- 保存设置(这些设置将在 CLI 调用中使用)
**Important Note:** The `scale` value set in the ComfyUI interface will be completely ignored by `tpai.exe`. The upscale factor is **exclusively determined** by what you've set in the Topaz Photo AI GUI. This is a limitation of the `tpai.exe` command-line interface, not of this ComfyUI node.
3. **ComfyUI 工作流设置**
- 在 ComfyUI 中,添加以下节点:
* 图像源节点(例如 Load Image、VAE Decode 等)
* **Topaz Photo AI** 节点:主处理节点
- 连接图像源到 Topaz Photo AI 节点的 `images` 输入
- 配置 Topaz Photo AI 节点参数:
* `tpai_exe`: 设置 Topaz Photo AI 的可执行文件路径(例如 `C:\Program Files\Topaz Labs LLC\Topaz Photo AI\tpai.exe`)
* `output_format`: 选择输出格式(jpg、png、tif等)
* `quality`: 设置 JPEG 质量(对于jpg格式)
* `overwrite`: 是否覆盖已存在的文件
* `output_prefix`: (可选) 自定义输出文件前缀
After installation, you will find the following nodes under the `ComfyTopazPhoto` category:
4. **运行处理**
- 运行工作流
- ComfyUI 会自动调用 Topaz Photo AI 对图像进行处理
- 处理完成后,增强后的图像将在 ComfyUI 中显示
* **`ComfyTopazPhoto` (Main Node):** This is the core node that executes Topaz Photo AI.
* **`ComfyTopazPhoto Upscale Settings`:** Connect this node to the `upscale` input of the main node to enable and partially control upscaling.
* **`ComfyTopazPhoto Sharpen Settings`:** Connect this node to the `sharpen` input of the main node to enable and partially control sharpening.
5. **故障排除(如需)**
- 如果遇到问题,可以在 ComfyUI 中添加 **Test & Clean Topaz** 节点
- 设置 `tpai_exe` 为 Topaz Photo AI 的可执行文件路径
- 设置 `clean_cache` 为 True 清理缓存
- 设置 `verbose` 为 True 获取详细日志
- 运行此节点测试 Topaz Photo AI 安装情况并清理缓存
### Inputs (Main Node)
### 实际使用案例
* `images`: The input image(s) to process.
* `tpai_exe`: **Required.** The full path to your `tpai.exe` executable (e.g., `H:\\Program Files\\Topaz Labs LLC\\Topaz Photo AI\\tpai.exe`).
* `compression`: PNG compression level (0-10, default: 2).
* `upscale`: (Optional) Connect the output of the `ComfyTopazPhoto Upscale Settings` node here.
* `sharpen`: (Optional) Connect the output of the `ComfyTopazPhoto Sharpen Settings` node here.
### Inputs (Settings Nodes - Upscale & Sharpen)
* `enabled`: Set to `true` to enable this enhancement (Upscale or Sharpen).
* `model`: Select the specific AI model to use for the enhancement. **This parameter should be correctly passed to `tpai.exe`.**
* **Upscale Parameters:**
* **⚠️ IMPORTANT:** The `scale` parameter is **NOT available** on this node. The upscale factor is determined **exclusively** by the settings in the Topaz Photo AI GUI under **Preferences -> Autopilot -> Upscale & Resize**. You **must** configure this setting in the GUI before using this node for upscaling.
* `denoise` (param1), `deblur` (param2), `detail` (param3): These parameters **should** be correctly passed to `tpai.exe` and override the defaults when Upscale is enabled.
* **Sharpen Parameters:**
* `strength` (param1), `denoise` (param2), `compression`, `is_lens`, etc.: Similar to upscale, it's highly likely that only the `model` parameter is reliably passed via CLI due to `tpai.exe` limitations. Other parameters are likely ignored, and Topaz Photo AI's defaults will be used. (Further testing needed if specific sharpen parameters are critical).
### Outputs (Main Node)
* `IMAGE`: The processed image(s).
* `settings`: A string containing the final JSON settings used by `tpai.exe` to process the image (excluding Autopilot settings, reflecting the parameters `tpai.exe` actually used).
* `autopilot_settings`: A string containing the Autopilot settings detected by `tpai.exe`.
### Workflow Strategy
1. **Set Fixed Upscale Factor in Topaz GUI:** *(Required step)* Open Topaz Photo AI, go to Preferences -> Autopilot -> Upscale & Resize, and set your desired **default** upscale factor (e.g., 2x, 4x). Save preferences. **This step is mandatory** - without it, your images will be upscaled according to whatever default factor is currently set in the Topaz GUI, regardless of what you select in ComfyUI.
2. **Use ComfyUI Node:**
* Connect the `ComfyTopazPhoto Upscale Settings` node if you want Topaz to perform upscaling (using the factor set in the GUI).
* Set `enabled` to `true`.
* Select the desired `model`.
* Adjust `denoise`, `deblur`, `detail` sliders as needed (these should work).
* Remember that the actual upscale factor is controlled by the Topaz GUI settings.
* Connect the main `ComfyTopazPhoto` node and provide the `tpai_exe` path.
3. **For Variable Upscaling:** If you need different upscale factors within the *same* workflow, **do not** rely on the Topaz node for scaling. Instead:
* Use a standard ComfyUI upscale node (like `Image Upscale with Model` or `ImageScale`) *before* the `ComfyTopazPhoto` node to achieve the desired size.
* You can still use the `ComfyTopazPhoto` node afterward for other enhancements (like sharpening or applying denoise/deblur/detail via the Upscale node with `enabled=true` but knowing the scale factor comes from the GUI setting) or set `enabled=false` on the relevant Topaz setting node if you only want processing from other enabled Topaz modules.
![Simple Workflow Example](demo1.png) *(Screenshot might show older node names and functionality)*
## Current Limitations & Troubleshooting
* **Upscale Factor Control:** The upscale factor (`scale`) **cannot** be controlled from this node. It **must** be preset in the Topaz Photo AI GUI preferences (Autopilot settings). **There is no workaround for this limitation** as it is inherent to how the `tpai.exe` command-line interface functions. If you need different upscale factors for different images, you will need to either:
* Change the setting in the Topaz GUI between ComfyUI runs, or
* Use a standard ComfyUI upscale node before the Topaz node to achieve the desired size
* **Parameter Override Reliability:** Only the `model`, and potentially the `param1`/`param2`/`param3` for upscale, seem reliably passed via the CLI. Other specific parameters on the settings nodes are likely ignored due to `tpai.exe` limitations.
* **`Could not load model` Error:** Likely an issue with the Topaz Photo AI installation or model files. Check the main app and Topaz logs (`AppData\Local\Topaz Labs LLC\Topaz Photo AI\Logs`).
* **Initial Setup:** Ensure the `tpai_exe` path is correct.
## Future Development (TODO)
* Monitor future `tpai.exe` versions for potential fixes or documented changes to CLI parameter handling.
* Update documentation if Topaz Labs clarifies or fixes CLI parameter behavior.
* Consider adding separate nodes for other CLI-controllable features if they prove reliable (e.g., Denoise module if its `strength`, `minor_deblur` etc. parameters work via CLI).
## Proposed Improvement
Based on code analysis, the current implementation can be simplified to make it more user-friendly. Since many of the parameters passed to `tpai.exe` are ignored or unreliable, we can streamline the nodes to focus only on enabling/disabling features:
### Suggested Changes:
1. **Simplify Settings Nodes**:
* Replace all parameter inputs with just an `enabled` toggle
* Remove confusing parameters that have no effect on the final output
* The model selection can be kept as it seems to be reliably passed to `tpai.exe`
2. **Updated Code Example**:
```python
# Simplified Upscale Settings Node
class ComfyTopazPhotoUpscaleSettings:
@classmethod
def INPUT_TYPES(cls):
return {
'required': {
'enabled': ('BOOLEAN', {'default': False}),
'model': ([
'Standard',
'Standard V2',
'High Fidelity',
'High Fidelity V2',
'Low Resolution'
], {'default': 'Standard V2'}),
},
}
RETURN_TYPES = ('ComfyTopazPhotoUpscaleSettings',)
FUNCTION = 'init'
CATEGORY = 'ComfyTopazPhoto'
def init(self, enabled, model):
self.enabled = enabled
self.model = model
return (self,)
```
3. **Main Node Implementation**:
* Keep the current command line argument structure
* Remove parameter passing code except for the model selection
* Use the Topaz Photo AI defaults for all other parameters, which will be controlled via the GUI settings
4. **User Experience Benefits**:
* More intuitive interface
* Less confusion about which parameters actually work
* Clearer expectations about what settings need to be configured in the Topaz GUI
* Simplified workflow with fewer potential errors
This approach would make the node much more straightforward to use - simply toggle 'enabled' for the features you want to use (upscale/sharpen), select a model, and let Topaz Photo AI's built-in settings handle the rest.
### Inputs (Settings Nodes - Simplified)
* `enabled`: Boolean toggle to enable/disable this enhancement (Upscale or Sharpen).
* `model`: Select the specific AI model to use for the enhancement. **This parameter should be correctly passed to `tpai.exe`.**
### Workflow Strategy (Simplified)
1. **Set Fixed Upscale Factor in Topaz GUI:** *(Required step)* Open Topaz Photo AI, go to Preferences -> Autopilot -> Upscale & Resize, and set your desired **default** upscale factor (e.g., 2x, 4x). Set other parameters like denoise, deblur, etc. as desired directly in the Topaz GUI.
2. **Use ComfyUI Node:**
* Connect the `ComfyTopazPhoto Upscale Settings` node to the main node
* Simply toggle `enabled` to `true` to activate upscaling
* Select the desired `model`
* Connect the main `ComfyTopazPhoto` node and provide the `tpai_exe` path
This simplified approach better reflects the actual capabilities of the `tpai.exe` command-line interface and provides a cleaner user experience.
## Implementation Status
✅ **Simplification Completed!**
The code has been updated to implement the simplified approach described above. The main changes include:
1. Simplified `ComfyTopazPhotoUpscaleSettings` and `ComfyTopazPhotoSharpenSettings` classes:
* Removed all parameters except `enabled` and `model`
* Simplified initialization methods
2. Modified `topaz_upscale` method:
* Removed code that tried to pass parameters that were being ignored
* Only passes the model selection which seems to be reliably handled by `tpai.exe`
* Added better logging for clarity
### How to Use the Simplified Version
With this simplified implementation, your workflow becomes much more straightforward:
1. **Configure Topaz Photo AI GUI** - Set up all your preferred enhancement parameters (upscale factor, denoise strength, deblur, etc.) directly in the Topaz Photo AI application.
2. **In ComfyUI:**
* Add the `ComfyTopazPhoto` main node
* Add `ComfyTopazPhoto Upscale Settings` and/or `ComfyTopazPhoto Sharpen Settings` nodes
* For each settings node, simply:
* Set `enabled` to `true` for the features you want to use
* Select the appropriate `model`
* Connect these settings nodes to the main node
* Connect your image source to the main node
* Provide the path to `tpai.exe`
3. **Run Your Workflow** - The image will be processed according to:
* The models you selected in ComfyUI
* The parameters you configured in the Topaz Photo AI GUI
### Simplified Workflow Diagram
#### 基本图像增强工作流
```
+-------------------+
| Image Source |
+--------+----------+
[Load Image] --> [Topaz Photo AI] --> [Preview Image]
```
在这个简单工作流中:
1. 加载图像
2. 通过 Topaz Photo AI 节点处理(使用 Autopilot 预设的增强参数)
3. 预览结果
#### 与其他 ComfyUI 节点结合使用
```
[Load Image] --> [其他处理节点] --> [Topaz Photo AI] --> [后续处理节点] --> [Preview Image]
```
例如,你可以:
1. 使用 ComfyUI 的 SD 生成图像
2. 应用其他效果
3. 使用 Topaz Photo AI 进行最终的增强处理
4. 应用后期处理效果
5. 保存或预览结果
### 视觉流程示例
下面是一个简单的 ComfyUI 工作流程图示例:
```
+------------------+
| Load Image |
+--------+---------+
|
v
+--------+-------------------+ +----------------------------------+
| ComfyTopazPhoto |<----| ComfyTopazPhoto Upscale |
| +----------------------+ | | +---------------------------+ |
| | images | | | | enabled: true | |
| | tpai_exe: [path] |<--+-----+ | model: Standard V2 | |
| | upscale | | | +---------------------------+ |
| | sharpen |<--+ +----------------------------------+
| +----------------------+ |
| | +----------------------------------+
+--------+-------------------+ | ComfyTopazPhoto Sharpen |
| | +---------------------------+ |
v | | enabled: false | |
+--------+----------+ | | model: Standard | |
| Output Image | | +---------------------------+ |
+-------------------+ +----------------------------------+
+--------+---------+ +------------------+
| Topaz Photo AI | | Test & Clean |
| tpai_exe: C:\... | | tpai_exe: C:\... |
| output_format:jpg| | clean_cache: True|
| quality: 95 | +------------------+
+--------+---------+
|
v
+--------+---------+
| Preview Image |
+------------------+
```
This implementation acknowledges the limitations of the Topaz Photo AI command-line interface while providing a clean, intuitive way to leverage its powerful image enhancement capabilities within ComfyUI.
## 关键使用说明
- **必须正确设置 tpai_exe 路径**:这是 Topaz Photo AI 可执行文件的完整路径,例如 `C:\Program Files\Topaz Labs LLC\Topaz Photo AI\tpai.exe`
- **所有增强参数都通过 Topaz Photo AI 的 Autopilot 设置控制**,而不是通过 ComfyUI 节点参数
- Topaz Photo AI 应用程序和 ComfyUI 可以同时运行,但不要在 ComfyUI 处理图像时修改 Autopilot 设置
- 处理大图像可能需要较长时间,请耐心等待
- 所有临时文件会自动清理
## 节点详情
### Topaz Photo AI 节点
**输入:**
* `images`: 要处理的输入图像
* `tpai_exe`: Topaz Photo AI 可执行文件路径 (tpai.exe)
* `output_format`: 输出图像格式(jpg、png、tif、tiff、preserve)
* `quality`: JPEG 质量 (0-100, 默认: 95)
* `overwrite`: 是否覆盖现有文件
* `output_prefix`: (可选) 自定义输出文件前缀,默认为 "topaz_"
**输出:**
* `IMAGE`: 处理后的图像
### Test & Clean Topaz 节点
**输入:**
* `tpai_exe`: Topaz Photo AI 可执行文件路径 (tpai.exe)
* `clean_cache`: 是否清理 Topaz Photo AI 缓存
* `verbose`: 是否显示详细日志信息
**输出:**
* `status`: 测试状态(SUCCESS 或 ERROR)
* `message`: 测试结果消息
* `cleaned_files`: 已清理的缓存文件数量
* `cache_before_MB`: 清理前的缓存大小(MB)
* `cache_after_MB`: 清理后的缓存大小(MB)
## 查找 tpai.exe 路径
Topaz Photo AI 可执行文件 (tpai.exe) 通常位于以下位置:
* Windows:
* `C:\Program Files\Topaz Labs LLC\Topaz Photo AI\tpai.exe`
* `C:\Program Files (x86)\Topaz Labs LLC\Topaz Photo AI\tpai.exe`
* `%LOCALAPPDATA%\Topaz Labs LLC\Topaz Photo AI\tpai.exe`
* macOS:
* `/Applications/Topaz Photo AI.app/Contents/MacOS/tpai`
* `~/Applications/Topaz Photo AI.app/Contents/MacOS/tpai`
如果 Topaz Photo AI 安装在非标准位置,您需要手动找到并提供正确的路径。
## 高级使用技巧
### 批量处理
1. 使用 ComfyUI 的批处理功能加载多张图像
2. 连接到 Topaz Photo AI 节点
3. 所有图像将按顺序处理
### 不同增强设置切换
如果需要使用不同的增强设置处理不同批次的图像:
1. 处理第一批图像
2. 暂停 ComfyUI 工作流
3. 打开 Topaz Photo AI 修改 Autopilot 设置
4. 恢复 ComfyUI 工作流处理下一批图像
## 故障排除
### 常见问题
* **tpai.exe 路径错误**:确保提供正确的 Topaz Photo AI 可执行文件路径。你可以在 Windows 中右键点击 tpai.exe 文件,选择"属性",然后复制"位置"中的路径
* **请确保 Topaz Photo AI 安装正确**:验证可以在命令行中运行 `tpai.exe --test`
* **确保已设置 Autopilot 设置**:所有增强设置都通过 Topaz Photo AI 的 Autopilot 进行控制,不再通过节点参数传递
* **处理失败**:查看控制台输出,可能是命令行参数问题。可以尝试使用 `Test & Clean Topaz` 节点清理缓存
* **图像质量不满意**:调整 Topaz Photo AI 的 Autopilot 设置,而不是节点参数
* **执行时间过长**:大图像处理可能需要较长时间;你也可以尝试清理缓存提高性能
### 新版本特有问题解决
* **图像格式兼容性错误**:如果看到类似 `Cannot handle this data type` 的错误,说明图像格式无法被正确处理。新版本已支持多种格式,但如果仍有问题,可尝试使用 ComfyUI 的格式转换节点先将图像转换为标准 RGB 格式。
* **"未找到输出文件"错误**:新版本引入了智能文件查找功能,应能解决大多数文件路径问题。如果仍然报错,请检查以下几点:
* Topaz Photo AI 是否有足够权限写入临时目录
* 临时目录路径中是否含有非英文字符
* 检查 Topaz 应用程序本身是否可以正常处理图像
* **处理超时**:如果处理大图像时超时,可以尝试:
* 先将图像缩小后再处理
* 增加节点的超时时间(在代码中可配置,默认为5分钟)
* 确保计算机有足够的内存和 GPU 资源
* **临时文件未删除**:如果发现临时文件未被清理,可能是因为处理过程中发生了异常。新版本改进了临时文件清理机制,如果仍有问题,可手动删除临时目录中的文件。
## 为什么简化?
原因很简单:根据官方文档,Topaz Photo AI CLI 实际上依赖于 GUI 中的 Autopilot 设置,而无法通过命令行参数直接控制增强参数。我们的简化版本专注于使用基本的 CLI 参数(如输出格式和质量),并让 Autopilot 设置控制所有增强功能。
这种方法有几个优点:
1. 更直观的界面
2. 更少的混淆(不再有看起来可以控制但实际无效的参数)
3. 更清晰的期望(用户知道需要在 GUI 中配置什么)
4. 简化的工作流程,减少潜在错误
## 后续改进
* 如果 Topaz Labs 更新 CLI 以支持更多直接参数控制,我们将相应更新扩展
* 考虑添加更多选项,如批处理模式和其他 CLI 支持的参数
* 计划添加预设功能,让用户可以保存和快速切换不同的 Autopilot 配置
# 参考
参考这个项目的处理简化而成,适配新版本的Topaz :
https://github.com/choey/Comfy-Topaz
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 455 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 307 KiB

@@ -0,0 +1,60 @@
To use the Topaz Photo AI command line interface (CLI), follow the below instructions for your operating system.
Windows:
1. Open Command Prompt or Terminal
2. Type in:
cd "C:\\Program Files\\Topaz Labs LLC\\Topaz Photo AI"
3. Type in:
.\\tpai.exe --help
4. Type in:
.\\tpai.exe "folder/or/file/path/here"
![](https://cdn.sanity.io/images/r2plryeu/production/45fd256fb694c2ff306b5a16b987852a828d10cd-1787x919.png?q=90&fit=max&auto=format)
* * *
Processing Controls
-------------------
The CLI will use your Autopilot settings to process images. Open Topaz Photo AI and go to the Preferences > Autopilot menu.
Instructions on using the Preferences > Autopilot menu are [here](https://docs.topazlabs.com/photo-ai/enhancements/autopilot-and-configuration).
### Command Options
\--output, -o: Output folder to save images to. If it doesn't exist the program will attempt to create it.
\--overwrite: Allow overwriting of files. THIS IS DESTRUCTIVE.
\--recursive, -r: If given a folder path, it will recurse into subdirectories instead of just grabbing top level files.
Note: If output folder is specified, the input folder's structure will be recreated within the output as necessary.
### File Format Options:
\--format, -f: Set the output format. Accepts jpg, jpeg, png, tif, tiff, dng, or preserve. Default: preserve
Note: Preserve will attempt to preserve the exact input extension, but RAW files will still be converted to DNG.Format Specific Options:
\--quality, -q: JPEG quality for output. Must be between 0 and 100. Default: 95
\--compression, -c: PNG compression amount. Must be between 0 and 10. Default: 2
\--bit-depth, -d: TIFF bit depth. Must be either 8 or 16. Default: 16
\--tiff-compression: -tc: TIFF compression format. Must be "none", "lzw", or "zip".
Note: lzw is not allowed on 16-bit output and will be converted to zip.
### Debug Options:
\--showSettings: Shows the Autopilot settings for images before they are processed
\--skipProcessing: Skips processing the image (e.g., if you just want to know the settings)
\--verbose, -v: Print more log entries to console.
Return values:
0 - Success
1 - Partial Success (e.g., some files failed)
\-1 (255) - No valid files passed.
\-2 (254) - Invalid log token. Open the app normally to login.
\-3 (253) - An invalid argument was found.
+642
View File
@@ -0,0 +1,642 @@
直接回答
以下是关于通过命令行接口(CLI)调用 Topaz Photo AI(tpai.exe)的官方指定参数和开发文档的简要说明,以及如何在 ComfyUI 中进行集成的指导。由于 CLI 功能的复杂性和官方文档的局限性,我会尽量提供清晰的建议,但请注意,某些功能可能需要额外的配置或未来更新。
* 官方参数和文档:Topaz Photo AI 的 CLI 使用 Autopilot 设置(需在 GUI 中配置),支持基本的输出选项如格式、质量等,但目前无法直接通过 CLI 传递特定增强设置(如锐化、降噪)。
* ComfyUI 集成:需要创建自定义节点,通过 Python 调用 tpai.exe,处理图像并返回结果,但需先在 GUI 中设置 Autopilot。
官方 CLI 参数
Topaz Photo AI 的 CLI 位于 C:\\Program Files\\Topaz Labs LLC\\Topaz Photo AI\\tpai.exe,基本用法为:
* 运行命令:.\\tpai.exe "path/to/image/or/folder"。
* 关键选项包括:
* \--output, -o <folder>:指定输出文件夹。
* \--format, -f <format>:设置输出格式(如 jpg、png)。
* \--quality, -q <0-100>:设置 JPEG 质量,默认 95。
详细参数见下表:
|
选项
|
描述
|
值/备注
|
| --- | --- | --- |
|
\--output, -o <folder>
|
指定输出文件夹
|
如果文件夹不存在,将自动创建
|
|
\--overwrite
|
允许覆盖现有文件,注意此操作具有破坏性
|
\-
|
|
\--recursive, -r
|
如果提供文件夹路径,递归处理子目录中的所有图像
|
\-
|
|
\--format, -f <format>
|
设置输出格式
|
jpg
,
jpeg
,
png
,
tif
,
tiff
,
dng
,
preserve
(默认:
preserve
)
|
|
\--quality, -q <0-100>
|
设置 JPEG 质量
|
默认:95
|
|
\--compression, -c <0-10>
|
设置 PNG 压缩级别
|
默认:2
|
|
\`--bit-depth, -d <8
|
16>\`
|
设置 TIFF 位深度
|
|
\`--tiff-compression, -tc <none
|
lzw
|
zip>\`
|
* 注意:增强设置(如锐化、降噪)依赖于 GUI 中的 Autopilot 配置,无法通过 CLI 直接控制。
在 ComfyUI 中的集成
ComfyUI 是一个基于节点的 Stable Diffusion 接口,您需要创建自定义节点来调用 tpai.exe:
* 步骤:
1. 在 ComfyUI/custom\_nodes 下创建新目录(如 TopazPhotoAI)。
2. 编写 Python 脚本,接受图像输入,保存为临时文件,调用 CLI 处理后加载结果。
3. 示例代码见下文,需确保 Autopilot 设置已配置。
* 限制:由于 CLI 依赖 GUI 设置,灵活性有限,建议关注 Topaz Labs 的未来更新。
* * *
详细报告
以下是关于 Topaz Photo AI CLI 调用和 ComfyUI 集成的详细分析,基于官方文档和相关资源,旨在为开发提供全面指导。当前时间为 2025 年 4 月 13 日星期日 15:53 HKT,所有信息均基于此时间点可用的资料。
背景与概述
Topaz Photo AI 是一款由 Topaz Labs 开发的照片增强软件,适用于锐化、降噪和上采样等任务。它提供了一个命令行接口(CLI),通过 tpai.exe 允许用户在脚本或自动化流程中调用功能。官方文档位于 [Topaz Photo AI CLI 官方文档](https://docs.topazlabs.com/photo-ai/command-line-interface),提供了 CLI 的基本用法和参数。
用户希望了解 CLI 的指定参数和开发文档,并特别关注如何在 ComfyUI 中调用。ComfyUI 是一个基于节点的 Stable Diffusion 接口,广泛用于 AI 图像生成,允许通过自定义节点扩展功能。
官方 CLI 文档分析
根据官方文档,tpai.exe 位于 C:\\Program Files\\Topaz Labs LLC\\Topaz Photo AI,基本用法如下:
* 打开命令提示符或终端,导航至安装目录:
```bash
cd "C:\Program Files\Topaz Labs LLC\Topaz Photo AI"
```
* 查看帮助信息:
* 处理图像或文件夹:
```bash
.\tpai.exe "path/to/image/or/folder"
```
处理机制
CLI 的图像处理依赖于 Autopilot 设置,这些设置需在 Topaz Photo AI 的 GUI 中配置,具体路径为 Preferences > Autopilot。相关配置指南见 [Autopilot 配置](https://docs.topazlabs.com/photo-ai/enhancements/autopilot-and-configuration)。这意味着,CLI 无法直接通过命令传递特定的增强参数(如锐化强度、降噪级别),而是使用 GUI 中预设的设置。
可用 CLI 选项
以下是官方文档中列出的 CLI 选项,整理为表格形式:
|
选项
|
描述
|
值/备注
|
| --- | --- | --- |
|
\--output, -o <folder>
|
指定输出文件夹
|
如果文件夹不存在,将自动创建
|
|
\--overwrite
|
允许覆盖现有文件,注意此操作具有破坏性
|
\-
|
|
\--recursive, -r
|
如果提供文件夹路径,递归处理子目录中的所有图像
|
\-
|
|
\--format, -f <format>
|
设置输出格式
|
jpg
,
jpeg
,
png
,
tif
,
tiff
,
dng
,
preserve
(默认:
preserve
)
注意:RAW 文件即使选择
preserve
也会转换为 DNG
|
|
\--quality, -q <0-100>
|
设置 JPEG 质量
|
默认:95
|
|
\--compression, -c <0-10>
|
设置 PNG 压缩级别
|
默认:2
|
|
\`--bit-depth, -d <8
|
16>\`
|
设置 TIFF 位深度
|
|
\`--tiff-compression, -tc <none
|
lzw
|
zip>\`
|
调试选项
* \--showSettings:显示处理前的 Autopilot 设置。
* \--skipProcessing:跳过实际处理,仅用于检查设置。
* \--verbose, -v:增加控制台输出详细程度。
返回值
CLI 的返回代码如下:
* 0:成功
* 1:部分成功(部分文件处理失败)
* \-1 (255):未传递有效文件
* \-2 (254):无效日志令牌(可能需要通过 GUI 登录)
* \-3 (253):无效参数
局限性
从官方文档来看,CLI 当前不支持直接传递特定增强设置(如上采样比例、锐化强度),这可能限制其在自动化场景中的灵活性。社区论坛(如 [Topaz Community](https://community.topazlabs.com/t/cli-improvement-allow-input-arguments-for-enhancement-adjustments/43464))中,用户已提出相关功能请求,但截至 2025 年 4 月 13 日,官方文档未反映此类更新。
ComfyUI 集成指南
ComfyUI 是一个基于节点的 Stable Diffusion 接口,允许用户通过自定义节点扩展功能。集成 Topaz Photo AI CLI 需要创建一个自定义节点,通过 Python 调用 tpai.exe,处理图像并返回结果。
创建自定义节点
1. 目录结构:
* 在 ComfyUI/custom\_nodes 下创建新目录,例如 TopazPhotoAI。
* 在该目录下创建 Python 文件,例如 topaz\_photo\_ai.py。
2. 节点实现:
* 节点需继承 ComfyUI 的节点基类,定义输入输出和处理逻辑。
* 示例代码如下,示意如何调用 CLI:
```python
import os
import subprocess
from comfy.sd import SDNode
class TopazPhotoAINode(SDNode):
def __init__(self):
super().__init__()
self.input_image = None
self.output_folder = None
self.format = "preserve"
self.quality = 95
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE",),
"output_folder": ("STRING", {"default": "output"}),
"format": (["jpg", "jpeg", "png", "tif", "tiff", "dng", "preserve"],),
"quality": ("INT", {"default": 95, "min": 0, "max": 100}),
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("processed_image",)
def process(self, image, output_folder, format, quality):
# 保存输入图像到临时文件
temp_input_path = os.path.join(output_folder, "input.jpg")
image.save(temp_input_path)
# 构造 CLI 命令
tpai_path = r"C:\Program Files\Topaz Labs LLC\Topaz Photo AI\tpai.exe"
cmd = [
tpai_path,
temp_input_path,
"--output", output_folder,
"--format", format,
"--quality", str(quality),
]
# 执行 CLI 命令
subprocess.run(cmd, check=True)
# 加载处理后的图像
processed_image_path = os.path.join(output_folder, "output.jpg") # 根据实际输出调整
processed_image = Image.open(processed_image_path)
return (processed_image,)
NODE_CLASS_MAPPINGS = {
"TopazPhotoAI": TopazPhotoAINode,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"TopazPhotoAI": "Topaz Photo AI",
}
```
* 说明:
* 节点接受图像、输出文件夹、格式和质量作为输入。
* 保存输入图像到临时文件,调用 tpai.exe,加载处理后的图像并返回。
* 需确保输出文件夹存在或动态创建。
3. 安装与使用:
* 将 topaz\_photo\_ai.py 放入 custom\_nodes/TopazPhotoAI 目录。
* 重启 ComfyUI,节点“Topaz Photo AI”将出现在节点列表中。
* 连接图像输入,配置输出文件夹、格式和质量,运行工作流处理图像。
集成限制
由于 CLI 依赖 Autopilot 设置,用户需在 Topaz Photo AI GUI 中预先配置这些设置,这可能限制灵活性。例如,无法通过节点动态调整锐化或降噪强度。社区讨论(如 [Topaz Community](https://community.topazlabs.com/t/ptai-cli-photo-ai-cli-allow-arguments-to-influence-settings/43464))中,用户已表达希望 CLI 支持更多参数的愿望,但截至目前,官方文档未支持。
额外考虑
在开发过程中,注意以下几点:
* 文件路径管理:确保处理临时文件和输出文件时,路径正确且无权限问题。
* 性能优化:批量处理可能需要递归选项(\--recursive, -r),但需测试性能。
* 未来更新:如果 Topaz Labs 未来更新 CLI,支持更多参数(如增强设置),可相应调整节点逻辑。
相关资源与社区反馈
通过搜索发现,社区中存在一些 Python 脚本示例(如 [Topaz Photo AI CLI 示例](https://gist.github.com/mq1n/c46c0ae4de2fb72897ba13fa22826ab0)),但需注意,这些脚本可能涉及 Gigapixel AI 而非 Photo AI,需验证适用性。此外,Topaz Community 论坛(如 [CLI 改进建议](https://community.topazlabs.com/t/cli-improvement-allow-input-arguments-for-enhancement-adjustments/43464))提供了用户需求反馈,可作为未来发展的参考。
结论
Topaz Photo AI 的 CLI 提供基本的图像处理功能,但增强设置依赖 GUI 配置,限制了自动化灵活性。在 ComfyUI 中集成需创建自定义节点,通过 Python 调用 CLI 处理图像,但需预先配置 Autopilot 设置。建议关注官方更新,获取更多 CLI 参数支持。
* * *
关键引用
+14 -34
View File
@@ -5,32 +5,19 @@ import comfy.model_management as model_management
from .topaz import (
init_topaz,
process_topaz_image,
disable_topaz_image_cache,
enable_topaz_image_cache,
test_and_clean_topaz
test_and_clean_topaz,
ComfyTopazPhoto,
NODE_CLASS_MAPPINGS as TOPAZ_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as TOPAZ_NODE_DISPLAY_NAME_MAPPINGS
)
# ... existing code ...
class ComfyTopazPhotoModelLoader:
# ... existing code ...
class ComfyTopazPhotoImageProcessor:
# ... existing code ...
class ComfyTopazPhotoDisableCache:
# ... existing code ...
class ComfyTopazPhotoEnableCache:
# ... existing code ...
# 添加新的节点,用于测试和清理 Topaz Photo AI
# 添加测试和清理节点
class ComfyTopazPhotoTestAndClean:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"tpai_exe": ("STRING", {"default": "C:\\Program Files\\Topaz Labs LLC\\Topaz Photo AI\\tpai.exe"}),
"clean_cache": (["True", "False"], {"default": "False"}),
"verbose": (["True", "False"], {"default": "True"}),
},
@@ -41,16 +28,14 @@ class ComfyTopazPhotoTestAndClean:
FUNCTION = "test_and_clean"
CATEGORY = "ComfyTopazPhoto"
def test_and_clean(self, clean_cache, verbose):
def test_and_clean(self, tpai_exe, clean_cache, verbose):
# 将字符串转换为布尔值
clean_cache = (clean_cache == "True")
verbose = (verbose == "True")
# 获取 Topaz Photo AI 可执行文件路径
try:
tpai_exe = init_topaz()[0]
except Exception as e:
return ("ERROR", f"无法初始化 Topaz Photo AI: {str(e)}", 0, 0.0, 0.0)
# 验证 tpai_exe 路径是否存在
if not os.path.exists(tpai_exe):
return ("ERROR", f"Topaz Photo AI 可执行文件未找到: {tpai_exe}", 0, 0.0, 0.0)
# 调用测试和清理函数
results = test_and_clean_topaz(tpai_exe, clean_cache, verbose)
@@ -72,19 +57,14 @@ class ComfyTopazPhotoTestAndClean:
return (status, message, results["cleaned_files"], cache_before_MB, cache_after_MB)
# 节点列表
# 合并节点映射
NODE_CLASS_MAPPINGS = {
"ComfyTopazPhotoModelLoader": ComfyTopazPhotoModelLoader,
"ComfyTopazPhotoImageProcessor": ComfyTopazPhotoImageProcessor,
"ComfyTopazPhotoDisableCache": ComfyTopazPhotoDisableCache,
"ComfyTopazPhotoEnableCache": ComfyTopazPhotoEnableCache,
**TOPAZ_NODE_CLASS_MAPPINGS,
"ComfyTopazPhotoTestAndClean": ComfyTopazPhotoTestAndClean,
}
# 合并显示名称映射
NODE_DISPLAY_NAME_MAPPINGS = {
"ComfyTopazPhotoModelLoader": "Topaz Photo AI",
"ComfyTopazPhotoImageProcessor": "Topaz Photo AI Processor",
"ComfyTopazPhotoDisableCache": "Disable Topaz Cache",
"ComfyTopazPhotoEnableCache": "Enable Topaz Cache",
**TOPAZ_NODE_DISPLAY_NAME_MAPPINGS,
"ComfyTopazPhotoTestAndClean": "Test & Clean Topaz",
}
+8 -8
View File
@@ -1,14 +1,14 @@
[project]
name = "comfy-topaz"
description = "Comfy-Topaz is a custom node for ComfyUI, which integrates with Topaz Photo AI to enhance (upscale, sharpen, denoise, etc.) images, allowing this traditionally asynchronous step to become a part of ComfyUI workflows.\nNOTE: Requires licensed installation of Topaz Photo AI"
version = "1.0.1"
license = { file = "LICENSE" }
name = "Comfy-Topaz-Photo"
description = "A ComfyUI node for integrating Topaz Photo AI's powerful image enhancement capabilities"
version = "1.0.0"
license = {file = "LICENSE"}
[project.urls]
Repository = "https://github.com/choey/Comfy-Topaz"
Repository = "https://github.com/leoleelxh/Comfy-Topaz-Photo"
# Used by Comfy Registry https://comfyregistry.org
[tool.comfy]
PublisherId = "choey"
DisplayName = "Comfy-Topaz"
Icon = ""
PublisherId = "leoleexh"
DisplayName = "Comfy-Topaz-Photo"
Icon = "https://raw.githubusercontent.com/leoleelxh/Comfy-Topaz-Photo/main/sample.jpg"
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 818 KiB

+635 -783
View File
File diff suppressed because it is too large Load Diff
+5 -5
View File
@@ -14,7 +14,7 @@ const ext = {
});
},
async beforeRegisterNodeDef(nodeType, nodeData, _app) {
if (nodeData.name === 'TopazPhotoAI') {
if (nodeData.name === 'ComfyTopazPhoto') {
const ensureTpai = async (node) => {
const tpaiWidget = node.widgets.find(w => w.name === "tpai_exe");
if (tpaiWidget && tpaiWidget.value === "") {
@@ -23,15 +23,15 @@ const ext = {
}
const onConfigure = nodeType.prototype.onConfigure;
nodeType.prototype.onConfigure = function () {
const r = onConfigure ? onConfigure.apply(this, arguments) : undefined;
nodeType.prototype.onConfigure = function(...args) {
const r = onConfigure ? onConfigure.apply(this, args) : undefined;
ensureTpai(this);
return r;
};
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined;
nodeType.prototype.onNodeCreated = function(...args) {
const r = onNodeCreated ? onNodeCreated.apply(this, args) : undefined;
ensureTpai(this);
return r;
};