### CLI usage examples for download and cache Source: https://github.com/alberto-rota/unreflectanything/wiki/Download Shows example CLI commands for downloading assets, printing the cache directory, and clearing the cache. ```bash unreflect download --weights unreflect download --images unreflect download --notebooks unreflect download --configs unreflect download --all unreflect download --weights -o ./my_weights/ -f # Print cache directory (base or a subdir) unreflect cache --dir unreflect cache --dir --weights # Clear cache (entire or a subdir) unreflect cache --clear unreflect cache --clear --weights ``` -------------------------------- ### Clone and install UnReflectAnything for development Source: https://github.com/alberto-rota/unreflectanything/blob/main/README.md Steps to clone the repository and install dependencies for contributing or developing UnReflectAnything. A virtual environment with Python 3.12 is recommended. ```bash git clone https://github.com/alberto-rota/UnReflectAnything.git cd UnReflectAnything ``` ```bash pip install -r requirements.txt ``` -------------------------------- ### CLI example for verify Source: https://github.com/alberto-rota/unreflectanything/wiki/Verify Example CLI commands for dataset and weights verification, including use in shell scripts with exit code checks. ```bash # Dataset verification unreflect verify --dataset --path /data/my_dataset unreflect verify --dataset -p /data/SCRREAM -t SCRREAM unreflect verify --dataset --path /data/ds -c config.yaml # Weights verification unreflect verify --weights unreflect verify --weights -w /path/to/weights.pt unreflect verify --weights --model-config config/train.yaml # In scripts if unreflect verify --dataset --path /data/dataset; then echo "Dataset valid"; fi if unreflect verify --weights; then echo "Weights OK"; fi ``` -------------------------------- ### Install unreflectanything from PyPI Source: https://github.com/alberto-rota/unreflectanything/wiki/Installation Installs the package from PyPI. Requires Python 3.12. For GPU support, install PyTorch with the appropriate CUDA version for your system. ```bash pip install unreflectanything ``` -------------------------------- ### Python API example for cache and cache_clear Source: https://github.com/alberto-rota/unreflectanything/wiki/Cache Example usage of the cache and cache_clear functions. Shows how to get the base cache directory, a subdirectory, and how to clear a subdirectory or the entire cache. ```python from unreflectanything import cache, cache_clear base = cache() # ~/.cache/unreflectanything weights_dir = cache("weights") # base / "weights" cache_clear("weights") # delete only weights subdir cache_clear() # delete entire cache ``` -------------------------------- ### Manually install shell completion Source: https://github.com/alberto-rota/unreflectanything/wiki/Completion Manually installs shell completion by sourcing the output of the completion command. The bash example is shown for both bash and zsh, with a comment noting that zsh can also use 'unreflect completion zsh'. After installation, restart the shell or source the rc file. ```bash # Bash: run and execute the printed command, or add to ~/.bashrc: source <(unreflect completion bash) # Zsh: run and execute the printed command, or add to ~/.zshrc: source <(unreflect completion bash) # or unreflect completion zsh ``` -------------------------------- ### Python API usage examples for download Source: https://github.com/alberto-rota/unreflectanything/wiki/Download Shows example calls to the Python `download` function, including positional and keyword `asset` arguments, output directory, and force flag. ```python from unreflectanything import download download("weights") download(asset="weights") download(asset="images") download(asset="notebooks") download(asset="configs") download("all") download("weights", output_dir="./my_weights/", force=True) ``` -------------------------------- ### CLI examples for unreflect cache Source: https://github.com/alberto-rota/unreflectanything/wiki/Cache Example CLI commands for printing the cache directory, printing a subdirectory, clearing a subdirectory, and clearing the entire cache. ```bash unreflect cache --dir unreflect cache --dir --weights unreflect cache --clear --weights unreflect cache --clear ``` -------------------------------- ### Python example: UnReflectModel forward with options Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Example of using `UnReflectModel` with custom threshold and dilation, and retrieving the full output dict to access the highlight mask. ```python uramodel = ura.model(pretrained=True) uramodel.eval() diffuse = uramodel(images, threshold=0.4, dilation=20) # Full outputs outputs = uramodel(images, return_dict=True) highlight_mask = outputs["highlight"] ``` -------------------------------- ### Get cache directory and subdirectories Source: https://github.com/alberto-rota/unreflectanything/wiki/Download Example of using `unreflectanything.cache` to obtain the base cache directory (e.g. `~/.cache/unreflectanything`) and a specific subdirectory like 'weights'. ```python from unreflectanything import cache base = cache() # e.g. ~/.cache/unreflectanything weights_dir = cache("weights") # base / "weights" # Assets are under base/weights, base/images, base/notebooks, base/configs ``` -------------------------------- ### CLI examples: unreflect inference Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Example CLI invocations. The first processes a single image, the second processes a directory with batch size 8, and the third uses custom weights, CPU device, and verbose output. ```bash unreflect inference input.png -o output.png unreflect inference ./images/ -o ./outputs/ -b 8 unreflect inference input.png -o output.png -w /path/to/weights.pt -d cpu -v ``` -------------------------------- ### Python API example for verify() Source: https://github.com/alberto-rota/unreflectanything/wiki/Verify Example usage of the Python API. Shows dataset verification with optional dataset_type, and weights verification with optional weights_path and model_config_path. The backward-compatible verify_dataset() function is also mentioned. ```python from unreflectanything import verify # Verify dataset structure verify("dataset", path="/data/my_dataset") verify("dataset", path="/data/SCRREAM", dataset_type="SCRREAM") # Verify weights (default cache location) verify("weights") # Verify weights at a custom path verify("weights", weights_path="/path/to/weights.pt") verify("weights", weights_path="/path/to/weights.pt", model_config_path="config/train.yaml") ``` -------------------------------- ### Python example: ura.model() and inference Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Example of creating a pretrained model and running inference on a random batch. Requires `ura download --weights` first. The model expects `[B, 3, H, W]` RGB tensors and returns a diffuse tensor of the same shape. ```python import unreflectanything as ura # Get a pretrained instance (run 'ura download --weights' first) uramodel = ura.model(pretrained=True) images = torch.rand(2, 3, 448, 448, device="cuda") # [B, 3, H, W] diffuse = uramodel(images) # [B, 3, H, W] ``` -------------------------------- ### Python API: inference usage example Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Shows how to call `inference` with a file, directory, and tensor input. The tensor input returns a tensor; file/directory inputs write results to the specified output paths. ```python from unreflectanything import inference import torch inference("input.png", output="output.png") inference("input_dir/", output="output_dir/", batch_size=8, threshold=0.5) img = torch.rand(1, 3, 448, 448) result = inference(img) # returns tensor ``` -------------------------------- ### CLI: unreflect cite usage examples Source: https://github.com/alberto-rota/unreflectanything/wiki/Cite Illustrates several CLI invocations. The first uses the default BibTeX format. The last pipes the output to `pbcopy` on macOS to copy the citation to the clipboard. ```bash unreflect cite unreflect cite --apa unreflect cite --ieee unreflect cite --bibtex | pbcopy ``` -------------------------------- ### Get BibTeX citation with unreflectanything cite --bibtex Source: https://github.com/alberto-rota/unreflectanything/blob/main/README.md Command to get the BibTeX citation entry for UnReflectAnything. ```bash unreflectanything cite --bibtex ``` -------------------------------- ### Enable shell completion for bash Source: https://github.com/alberto-rota/unreflectanything/blob/main/README.md Enable shell completion for bash or zsh. Run this command and then execute the echo command that gets printed. ```bash unreflectanything completion bash ``` -------------------------------- ### Python API usage for UnReflectAnything Source: https://github.com/alberto-rota/unreflectanything/blob/main/README.md Shows the Python API for UnReflectAnything: loading the model class, getting a pretrained model, running inference on batched RGB tensors, and accessing the cache directory. Requires cached weights (run 'unreflect download --weights' first). ```python import unreflectanything as unreflect import torch # Get the model class (e.g. for custom setup or training) ModelClass = unreflect.model() # Get a pretrained model (torch.nn.Module) and run on batched RGB unreflectmodel = unreflect.model(pretrained=True) # uses cached weights; run 'unreflect download --weights' first images = torch.rand(2, 3, 448, 448, device="cuda") # [B, 3, H, W], values in [0, 1] model_out = unreflectmodel(images) # [B, 3, H, W] diffuse tensor # File-based or tensor-based inference (one-shot, no model handle) unreflect.inference("input.png", output="output.png") unreflect.inference(images, output="output.png") result = unreflect.inference(images) # Cache directory (where weights, images, etc. are stored) weights_dir = unreflect.cache("weights") ``` -------------------------------- ### Python API: cite() usage example Source: https://github.com/alberto-rota/unreflectanything/wiki/Cite Shows how to call `cite()` with different format arguments from Python. The first call uses the default BibTeX, then APA and IEEE. ```python from unreflectanything import cite cite() cite("apa") cite("ieee") ``` -------------------------------- ### Check CLI availability with --help Source: https://github.com/alberto-rota/unreflectanything/wiki/Installation Checks that the CLI works. The CLI is available under three names: unreflect, unreflectanything, and ura. Run any of these commands to display help. ```bash unreflectanything --help ``` ```bash unreflect --help ``` ```bash ura --help ``` -------------------------------- ### Download weights and sample images Source: https://github.com/alberto-rota/unreflectanything/blob/main/README.md Download model weights and sample images using the CLI. Weights are stored by default in ~/.cache/unreflectanything/weights (or $XDG_CACHE_HOME/unreflectanything/weights, %LOCALAPPDATA%\unreflectanything on Windows). Use --output-dir to change the location. ```bash unreflectanything download --weights ``` ```bash unreflectanything download --images ``` -------------------------------- ### Download pretrained weights with unreflectanything download Source: https://github.com/alberto-rota/unreflectanything/wiki/Home Downloads the pretrained model weights. Weights are stored by default in ~/.cache/unreflectanything/weights (or $XDG_CACHE_HOME/unreflectanything/weights if set; %LOCALAPPDATA%\unreflectanything\weights for Windows). Use --output-dir to choose another location. ```bash unreflectanything download --weights ``` -------------------------------- ### Show CLI help Source: https://github.com/alberto-rota/unreflectanything/blob/main/README.md Display an overview of available CLI endpoints. The command is aliased to 'unreflect' and 'ura'. ```bash unreflectanything --help # alias 'unreflect --help' alias 'ura --help' ``` -------------------------------- ### train(config, resume_run=None, boot=False, **overrides) Source: https://github.com/alberto-rota/unreflectanything/wiki/API Runs the training pipeline using the given config path and overrides. ```APIDOC ## train(config, resume_run=None, boot=False, **overrides) ### Description Run the training pipeline. Uses `main.run_pipeline(mode="train")` with the given config path and overrides. ### Method Function call ### Endpoint `train(config, resume_run=None, boot=False, **overrides)` ### Parameters - **config** (str) - Required - Path to config file. - **resume_run** (optional) - Resume run identifier. - **boot** (bool, optional) - Whether to boot. - **overrides** (kwargs) - Additional overrides (e.g., EPOCHS=50). ### Request Example ```python train("config.yaml", EPOCHS=50) ``` ### Response #### Success Response - Runs the training pipeline. ``` -------------------------------- ### Verify weights with unreflectanything verify Source: https://github.com/alberto-rota/unreflectanything/wiki/Home Checks that weights have been downloaded correctly and that the model can load a state dict with no key misalignment error. ```bash unreflectanything verify --weights ``` -------------------------------- ### Python API signature for unreflectanything.download Source: https://github.com/alberto-rota/unreflectanything/wiki/Download Signature of the `download` function, showing accepted parameters: `what`, `asset`, `output_dir`, `variant`, and `force`. Defaults to weights when neither `what` nor `asset` is provided. ```python def download( what: Optional[Literal["weights", "images", "notebooks", "configs", "all"]] = None, *, asset: Optional[Literal["weights", "images", "notebooks", "configs", "all"]] = None, output_dir: Optional[Union[str, Path]] = None, variant: str = "default", force: bool = False, ) -> Path ``` -------------------------------- ### unreflect download [OPTIONS] Source: https://github.com/alberto-rota/unreflectanything/wiki/Download Command-line interface to download assets from the Hugging Face repository. Supports flags for weights, images, notebooks, configs, or all assets, with options for output directory, variant, and force re-download. ```APIDOC ## unreflect download [OPTIONS] ### Description Downloads assets from the Hugging Face repository via the command line. Specify at least one of `--weights`, `--images`, `--notebooks`, `--configs`, or `--all`. If none is given, the CLI typically defaults to weights. ### Method CLI command ### Endpoint `unreflect download [OPTIONS]` ### Options - **--weights** - No short option - Download pretrained weights. - **--images** - No short option - Download sample images. - **--notebooks** - No short option - Download example notebooks. - **--configs** - No short option - Download YAML configs (training, inference, etc.). - **--all** - No short option - Download everything. - **--output-dir** / **-o** - Default: cache dir - Output directory. - **--variant** - No short option - Default: `default` - Weights variant. - **--force** / **-f** - No default - Force re-download. ### Example ```bash unreflect download --weights unreflect download --images unreflect download --notebooks unreflect download --configs unreflect download --all unreflect download --weights -o ./my_weights/ -f ``` ``` -------------------------------- ### CLI syntax: unreflect download Source: https://github.com/alberto-rota/unreflectanything/wiki/Download Shows the basic command-line syntax for `unreflect download`. ```bash unreflect download [OPTIONS] ``` -------------------------------- ### download() Source: https://github.com/alberto-rota/unreflectanything/wiki/Download Python function to download assets from the Hugging Face repository. Supports downloading weights, images, notebooks, configs, or all assets. Returns the directory where files were saved. ```APIDOC ## download() ### Description Downloads assets from the Hugging Face repository: pretrained weights, sample images, example notebooks, or YAML configs. Returns the directory where files were saved. ### Method Python function ### Signature ```python def download( what: Optional[Literal["weights", "images", "notebooks", "configs", "all"]] = None, *, asset: Optional[Literal["weights", "images", "notebooks", "configs", "all"]] = None, output_dir: Optional[Union[str, Path]] = None, variant: str = "default", force: bool = False, ) -> Path ``` ### Parameters - **what** (Literal["weights", "images", "notebooks", "configs", "all"]) - Optional - Asset type to download (positional). Defaults to None. - **asset** (Literal["weights", "images", "notebooks", "configs", "all"]) - Optional - Alias for `what` (e.g. `download(asset="weights")`). Defaults to None. - **output_dir** (str, Path, or None) - Optional - Output directory (default: cache). Defaults to None. - **variant** (str) - Optional - Weights variant when downloading weights. Defaults to "default". - **force** (bool) - Optional - Re-download even if files exist. Defaults to False. If neither `what` nor `asset` is given, defaults to `"weights"`. ### Returns - **Path** - Directory where files were saved. ### Example ```python from unreflectanything import download download("weights") download(asset="weights") download(asset="images") download(asset="notebooks") download(asset="configs") download("all") download("weights", output_dir="./my_weights/", force=True) ``` ``` -------------------------------- ### Import unreflectanything API functions Source: https://github.com/alberto-rota/unreflectanything/wiki/Home Import the main API functions from the unreflectanything package. This is the standard import statement to access all documented commands programmatically. ```python from unreflectanything import inference, model, train, test, download, cache, cache_clear, evaluate, verify, cite ``` -------------------------------- ### Show unreflect CLI help Source: https://github.com/alberto-rota/unreflectanything/wiki/Home Display the help message for the unreflect CLI, which is also available as 'unreflect' or 'ura'. This command lists all available subcommands and options. ```bash unreflect --help ``` -------------------------------- ### verify_dataset(path, dataset_type=None, config=None) Source: https://github.com/alberto-rota/unreflectanything/wiki/API Convenience wrapper for verify(what="dataset", path=path, ...). ```APIDOC ## verify_dataset(path, dataset_type=None, config=None) ### Description Convenience wrapper for `verify(what="dataset", path=path, ...)`. ### Method Function call ### Endpoint `verify_dataset(path, dataset_type=None, config=None)` ### Parameters - **path** (str) - Required - Path to dataset directory. - **dataset_type** (str, optional) - Dataset type. - **config** (optional) - Config path or dict. ### Request Example ```python verify_dataset("data/") ``` ### Response #### Success Response - No return value; raises errors if verification fails. ``` -------------------------------- ### CLI usage pattern Source: https://github.com/alberto-rota/unreflectanything/wiki/Verify CLI usage pattern. Must specify exactly one of --dataset or --weights. Exit codes: 0 = passed, 1 = failed or invalid arguments. ```bash unreflect verify [OPTIONS] ``` -------------------------------- ### inference(input, output=None, ...) Source: https://github.com/alberto-rota/unreflectanything/wiki/API Runs inference on an image file, directory, or tensor. Saves to disk if output is set; otherwise returns a tensor. ```APIDOC ## inference(input, output=None, ...) ### Description Run inference on an image file, directory, or tensor. Saves to disk if output is set; otherwise returns a tensor. ### Method Function call ### Endpoint `inference(input, output=None, ...)` ### Parameters - **input** (str or tensor) - Required - Path to image/directory or tensor [B, 3, H, W]. - **output** (str, optional) - Output file/directory. If None, returns tensor. - **weights_path** (str, optional) - Path to weights. - **config** (optional) - Config path or dict. - **device** (str, optional) - Device to use. - **batch_size** (int, optional) - Batch size. - **threshold** (float, optional) - Threshold value. - **dilation** (int, optional) - Dilation value. - **resize_output** (bool, optional) - Whether to resize output. - **verbose** (bool, optional) - Whether to print verbose output. ### Request Example ```python result = inference("input.jpg", output="output.jpg") ``` ### Response #### Success Response - If output is set: saves to disk. - If output is None: returns a tensor. ``` -------------------------------- ### CLI usage: unreflect inference [OPTIONS] INPUT Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Shows the general CLI syntax for the `unreflect inference` command. The `INPUT` argument is required and can be an image file or directory. ```bash unreflect inference [OPTIONS] INPUT ``` -------------------------------- ### Load raw module with load_pretrained from inference module Source: https://github.com/alberto-rota/unreflectanything/wiki/API Provides direct access to the raw loaded module without the UnReflectModel wrapper. Config resolution order: checkpoint, run directory (if run/runs_dir set), config argument, then default_config_path. Use strict=False to avoid key errors. ```python from inference import load_pretrained model = load_pretrained( weights_path="path/to/full_model_weights.pt", config=None, # or path/dict; resolved from checkpoint if None device="cuda", strict=False, verbose=False, default_config_path=None, # optional fallback config path ) ``` -------------------------------- ### cite(format="bibtex") Source: https://github.com/alberto-rota/unreflectanything/wiki/API Returns the project citation in the specified format. ```APIDOC ## cite(format="bibtex") ### Description Return the project citation. ### Method Function call ### Endpoint `cite(format="bibtex")` ### Parameters - **format** (str, optional) - Citation format: "bibtex", "apa", "mla", "ieee", or "plain". ### Request Example ```python citation = cite(format="bibtex") ``` ### Response #### Success Response - **citation** (str) - The citation string. ``` -------------------------------- ### Load pretrained model with ura.model(pretrained=True) Source: https://github.com/alberto-rota/unreflectanything/wiki/API Recommended way to load a pretrained model for inference. Uses cached weights and default config. Optional arguments include weights_path, config_path, and device. The model expects a tensor of shape [B, 3, H, W] and returns a diffuse tensor of the same shape. ```python import unreflectanything as ura model = ura.model(pretrained=True) # uses cache weights and default config # Optional: ura.model(pretrained=True, weights_path="...", config_path="...", device="cuda") images = torch.rand(2, 3, 448, 448, device="cuda") # [B, 3, H, W] diffuse = model(images) # [B, 3, H, W] ``` -------------------------------- ### test(config, **overrides) Source: https://github.com/alberto-rota/unreflectanything/wiki/API Runs the test/evaluation pipeline using the given config. ```APIDOC ## test(config, **overrides) ### Description Run the test/evaluation pipeline. Uses `main.run_pipeline(mode="test")` with the given config. ### Method Function call ### Endpoint `test(config, **overrides)` ### Parameters - **config** (str) - Required - Path to config file. - **overrides** (kwargs) - Additional overrides. ### Request Example ```python test("config.yaml") ``` ### Response #### Success Response - Runs the test pipeline. ``` -------------------------------- ### model() Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Factory function that returns an UnReflectModel instance. Loads pretrained weights or builds architecture only, with options for device, config, and weights. ```APIDOC ## Python: model() ### Description Creates an UnReflectModel instance for repeated inference on batched tensors. ### Method Python function ### Endpoint `model(pretrained=True, weights_path=None, device="cuda", config_path=None, verbose=False, config=None, weights=None, strict=True)` ### Parameters - **pretrained** (bool) - Optional - If `True`, load checkpoint weights; if `False`, build architecture only (default: `True`) - **weights_path** (str, Path, or None) - Optional - Path to checkpoint (default: cache dir) - **device** (str) - Optional - Device to load the model on (default: `"cuda"`) - **config_path** (str, Path, or None) - Optional - Path to YAML config - **verbose** (bool) - Optional - Print progress messages (default: `False`) - **config** (dict or None) - Optional - In-memory config object (overrides `config_path`) - **weights** (dict or None) - Optional - In-memory state dict (overrides `weights_path`) - **strict** (bool) - Optional - Strict state dict loading (default: `True`) ### Returns - **UnReflectModel** - An instance of the model wrapper. ### Request Example ```python import unreflectanything as ura uramodel = ura.model(pretrained=True) images = torch.rand(2, 3, 448, 448, device="cuda") diffuse = uramodel(images) ``` ### Response No structured response; returns an UnReflectModel instance. ``` -------------------------------- ### evaluate(output, reference, metrics=None, mask=None) Source: https://github.com/alberto-rota/unreflectanything/wiki/API Computes image quality metrics between output and reference. Returns a dict of metric names to values. ```APIDOC ## evaluate(output, reference, metrics=None, mask=None) ### Description Compute image quality metrics between output and reference (paths or tensors). Returns a dict of metric names to values. ### Method Function call ### Endpoint `evaluate(output, reference, metrics=None, mask=None)` ### Parameters - **output** (str or tensor) - Required - Output image path or tensor. - **reference** (str or tensor) - Required - Reference image path or tensor. - **metrics** (list, optional) - List of metric names (e.g., ["psnr", "ssim"]). If None, all metrics are computed. - **mask** (optional) - Mask to apply. ### Request Example ```python metrics = evaluate("output.png", "reference.png", metrics=["psnr", "ssim"]) ``` ### Response #### Success Response - **metrics** (dict) - Dictionary of metric names to values. ``` -------------------------------- ### inference Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Runs the UnReflectAnything model on input image(s) to remove specular reflections. Accepts a file path, directory, or tensor, and returns a tensor or writes results to disk. ```APIDOC ## inference ### Description Runs the UnReflectAnything model on input image(s) to remove specular reflections. Accepts a file path, directory, or tensor, and returns a tensor or writes results to disk. ### Method Function ### Endpoint `inference(input, output=None, weights_path=None, config=None, device="cuda", batch_size=4, threshold=0.3, dilation=40, resize_output=True, verbose=False, model=None)` ### Parameters #### Path Parameters - **input** (str, Path, or Tensor) - Required - Image file, directory, or tensor `[B, 3, H, W]` in [0, 1] #### Query Parameters - **output** (str, Path, or None) - Optional - If set, results are saved here; if `None`, returns a tensor - **weights_path** (str, Path, or None) - Optional - Model weights path (default: cache dir). Ignored if `model` is provided. - **config** (str, Path, dict, or None) - Optional - Config file path or dict for overrides. Ignored if `model` is provided. - **device** (str) - Optional - `"cuda"` or `"cpu"`. Ignored if `model` is provided. - **batch_size** (int) - Optional - Images per forward pass (for directory/file inputs) - **threshold** (float) - Optional - Highlight detection threshold (0.0–1.0) - **dilation** (int) - Optional - Highlight mask dilation in pixels - **resize_output** (bool) - Optional - Resize output to original input size - **verbose** (bool) - Optional - Print progress - **model** (UnReflectModel or None) - Optional - Pre-loaded model instance. If provided, skips model loading. ### Request Example ```python from unreflectanything import inference import torch inference("input.png", output="output.png") inference("input_dir/", output="output_dir/", batch_size=8, threshold=0.5) img = torch.rand(1, 3, 448, 448) result = inference(img) # returns tensor ``` ### Response #### Success Response (200) - **result** (Tensor or None) - If `output` is `None`, a tensor of shape `[B, 3, H, W]`; otherwise `None` (results written to disk). #### Response Example ```python # When output is None, returns a tensor tensor([[[...]]]) # When output is set, returns None None ``` ``` -------------------------------- ### CLI: unreflect cite command syntax Source: https://github.com/alberto-rota/unreflectanything/wiki/Cite Shows the command structure for the CLI version. Options include --bibtex (default), --apa, --mla, --ieee, --plain. ```bash unreflect cite [OPTIONS] ``` -------------------------------- ### CLI syntax for unreflect cache Source: https://github.com/alberto-rota/unreflectanything/wiki/Cache CLI usage syntax for the unreflect cache command. At least one of --dir or --clear is required. ```bash unreflect cache (--dir | --clear) [--weights | --images | --notebooks | --configs] ``` -------------------------------- ### verify() function signature Source: https://github.com/alberto-rota/unreflectanything/wiki/Verify Signature of the verify() function. Use what="dataset" or what="weights" to select the verification mode. Returns True if verification passed, False otherwise. ```python def verify( what: Literal["dataset", "weights"], path: Optional[Union[str, Path]] = None, weights_path: Optional[Union[str, Path]] = None, dataset_type: Optional[str] = None, config: Optional[Union[str, Path]] = None, model_config_path: Optional[Union[str, Path]] = None, ) -> bool ``` -------------------------------- ### unreflect inference [OPTIONS] INPUT Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Runs inference on an input image or directory. Supports options for output, weights, config, device, batch size, threshold, dilation, and more. ```APIDOC ## CLI: unreflect inference ### Description Runs inference on an input image or directory using the UnReflectAnything model. ### Method CLI ### Endpoint `unreflect inference [OPTIONS] INPUT` ### Parameters #### Arguments - **INPUT** (string) - Required - Input image file or directory #### Options - **--output, -o** (string) - Optional - Output file or directory (default: `./output/`) - **--weights, -w** (string) - Optional - Path to model weights (default: cache dir) - **--config, -c** (string) - Optional - Inference config YAML - **--device, -d** (string) - Optional - `cuda` or `cpu` (default: `cuda`) - **--batch-size, -b** (integer) - Optional - Batch size (default: `4`) - **--threshold** (number) - Optional - Highlight detection threshold (default: `0.3`) - **--dilation** (integer) - Optional - Highlight mask dilation (default: `40`) - **--no-resize** (flag) - Optional - Do not resize output to original size - **--verbose, -v** (flag) - Optional - Verbose output ### Request Example ```bash unreflect inference input.png -o output.png unreflect inference ./images/ -o ./outputs/ -b 8 unreflect inference input.png -o output.png -w /path/to/weights.pt -d cpu -v ``` ### Response No structured response; outputs are written to the specified output path. ``` -------------------------------- ### unreflect verify CLI Source: https://github.com/alberto-rota/unreflectanything/wiki/Verify The `unreflect verify` command checks dataset structure or weights integrity. It requires exactly one of `--dataset` or `--weights`. Exit code 0 indicates success, 1 indicates failure or invalid arguments. ```APIDOC ## unreflect verify ### Description Checks either dataset structure or weights integrity. Specify which to run with the `--dataset` or `--weights` flags. ### Method CLI command ### Endpoint `unreflect verify [OPTIONS]` ### Parameters - **--dataset** (flag) - Optional - Verify dataset structure; requires `--path`. - **--weights** (flag) - Optional - Verify weights file exists and loads into model with no key alignment errors. - **--path** / **-p** (str) - Optional - Dataset root directory (required when `--dataset`). - **--weights-path** / **-w** (str) - Optional - Path to weights file (optional when `--weights`; default: cache). - **--type** / **-t** (str) - Optional - Dataset type: `SCRREAM`, `HOUSECAT6D`, `POLARGB`, etc. (only with `--dataset`). - **--config** / **-c** (str) - Optional - Config file for dataset verification (only with `--dataset`). - **--model-config** / **-m** (str) - Optional - Model config YAML for weights verification (only with `--weights`). ### Exit Codes - **0** - Verification passed. - **1** - Verification failed or invalid arguments. ### Example ```bash # Dataset verification unreflect verify --dataset --path /data/my_dataset unreflect verify --dataset -p /data/SCRREAM -t SCRREAM unreflect verify --dataset --path /data/ds -c config.yaml # Weights verification unreflect verify --weights unreflect verify --weights -w /path/to/weights.pt unreflect verify --weights --model-config config/train.yaml # In scripts if unreflect verify --dataset --path /data/dataset; then echo "Dataset valid"; fi if unreflect verify --weights; then echo "Weights OK"; fi ``` ``` -------------------------------- ### DEFAULT_IMAGE_EXTENSIONS Source: https://github.com/alberto-rota/unreflectanything/wiki/API Tuple of default image file extensions (e.g., .png, .jpg). ```APIDOC ## DEFAULT_IMAGE_EXTENSIONS ### Description Tuple of default image file extensions (e.g., .png, .jpg). ### Method Constant ### Endpoint `DEFAULT_IMAGE_EXTENSIONS` ### Parameters None ### Request Example ```python print(DEFAULT_IMAGE_EXTENSIONS) ``` ### Response #### Success Response - **extensions** (tuple) - Tuple of file extensions. ``` -------------------------------- ### unreflect cache Source: https://github.com/alberto-rota/unreflectanything/wiki/Cache Command-line interface to print or clear the cache directory, optionally limited to a specific subdirectory. ```APIDOC ## unreflect cache (--dir | --clear) [--weights | --images | --notebooks | --configs] ### Description Manage the local asset cache: print the cache directory or clear cached assets. At least one of `--dir` or `--clear` is required. ### Method CLI ### Endpoint `unreflect cache (--dir | --clear) [--weights | --images | --notebooks | --configs]` ### Parameters #### Options - **--dir** - Print the cache directory (base or the selected subdir). - **--clear** - Delete cached assets (entire cache or the selected subdir). - **--weights** - Limit to weights cache subdir (with `--dir` or `--clear`). - **--images** - Limit to sample images cache subdir. - **--notebooks** - Limit to notebooks cache subdir. - **--configs** - Limit to configs cache subdir. ### Example ```bash unreflect cache --dir unreflect cache --dir --weights unreflect cache --clear --weights unreflect cache --clear ``` ``` -------------------------------- ### Python API: ura.model() signature Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Signature of the `ura.model()` factory function. It returns an `UnReflectModel` instance. Parameters allow loading pretrained weights, specifying device, config, and in-memory overrides. ```python def model( pretrained: bool = True, weights_path: Optional[Union[str, Path]] = None, device: str = "cuda", config_path: Optional[Union[str, Path]] = None, verbose: bool = False, config: Optional[Union[dict, Any]] = None, weights: Optional[Union[str, Path, dict, Any]] = None, strict: bool = True, ) -> UnReflectModel ``` -------------------------------- ### model(pretrained=True) Source: https://github.com/alberto-rota/unreflectanything/wiki/API Loads a pretrained model for inference. Returns a model that takes a tensor of shape [B, 3, H, W] and returns a diffuse tensor of the same shape. ```APIDOC ## model(pretrained=True) ### Description Load a pretrained model for inference (tensor-in, tensor-out). ### Method Function call ### Endpoint `ura.model(pretrained=True)` ### Parameters - **pretrained** (bool) - Required - Whether to load pretrained weights. - **weights_path** (str, optional) - Path to custom weights. - **config_path** (str, optional) - Path to config file. - **device** (str, optional) - Device to use (e.g., "cuda"). ### Request Example ```python import unreflectanything as ura model = ura.model(pretrained=True) images = torch.rand(2, 3, 448, 448, device="cuda") diffuse = model(images) ``` ### Response #### Success Response - **diffuse** (tensor) - Output tensor of shape [B, 3, H, W]. ``` -------------------------------- ### UnReflectModel.forward() Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Runs inference on batched RGB tensors. Returns either the diffuse tensor or a dict with diffuse and highlight outputs. ```APIDOC ## Python: UnReflectModel.forward() ### Description Performs inference on a batch of RGB images. Returns the diffuse reflection tensor or a dictionary with additional outputs. ### Method Python method (callable on the model instance) ### Endpoint `forward(images, threshold=0.3, dilation=40, inpaint_mask_override=None, return_dict=False)` ### Parameters - **images** (Tensor) - Required - Batched RGB tensor `[B, 3, H, W]` in [0, 1]; moved to model device automatically - **threshold** (float) - Optional - Highlight detection threshold (default: `0.3`) - **dilation** (int) - Optional - Highlight mask dilation in pixels (default: `40`) - **inpaint_mask_override** (Tensor or None) - Optional - Optional mask to force inpainting regions (1 = inpaint); if `None`, model uses its highlight head - **return_dict** (bool) - Optional - If `True`, return full output dict (`diffuse`, `highlight`, etc.); if `False`, return only the diffuse tensor (default: `False`) ### Returns - **Tensor** - If `return_dict=False`, a tensor of shape `[B, 3, H, W]`. - **Dict[str, Tensor]** - If `return_dict=True`, a dict with at least `diffuse`, `highlight` keys. ### Request Example ```python uramodel = ura.model(pretrained=True) uramodel.eval() diffuse = uramodel(images, threshold=0.4, dilation=20) outputs = uramodel(images, return_dict=True) highlight_mask = outputs["highlight"] ``` ### Response No structured response; returns tensor or dict as described. ``` -------------------------------- ### verify() Python API Source: https://github.com/alberto-rota/unreflectanything/wiki/Verify The `verify` function checks dataset structure or weights integrity. It returns True if verification passes, False otherwise. Parameters include `what`, `path`, `weights_path`, `dataset_type`, `config`, and `model_config_path`. ```APIDOC ## verify() ### Description Checks either dataset structure or weights integrity. Specify which to run with the `what` argument. ### Method Python function call ### Endpoint `verify(what, path=None, weights_path=None, dataset_type=None, config=None, model_config_path=None) -> bool` ### Parameters - **what** (Literal["dataset", "weights"]) - Required - Which verification to run. - **path** (str, Path, or None) - Optional - Dataset root directory (required when `what="dataset"`). - **weights_path** (str, Path, or None) - Optional - Weights file path (optional when `what="weights"`; default: cache). - **dataset_type** (str or None) - Optional - Dataset type: `SCRREAM`, `HOUSECAT6D`, `POLARGB`, `RGBP`; `None` = auto-detect (dataset only). - **config** (str, Path, or None) - Optional - Config file for dataset verification (dataset only). - **model_config_path** (str, Path, or None) - Optional - Model config YAML for weights verification if the checkpoint has no embedded config (weights only). ### Returns - **bool** - True if verification passed, False otherwise. ### Example ```python from unreflectanything import verify # Verify dataset structure verify("dataset", path="/data/my_dataset") verify("dataset", path="/data/SCRREAM", dataset_type="SCRREAM") # Verify weights (default cache location) verify("weights") # Verify weights at a custom path verify("weights", weights_path="/path/to/weights.pt") verify("weights", weights_path="/path/to/weights.pt", model_config_path="config/train.yaml") ``` ``` -------------------------------- ### Python API: UnReflectModel.forward() signature Source: https://github.com/alberto-rota/unreflectanything/wiki/Inference Signature of `UnReflectModel.forward()`. Accepts batched RGB tensors in [0,1], with optional threshold, dilation, mask override, and return_dict flag. Returns either a diffuse tensor or a dict with at least `diffuse` and `highlight` keys. ```python def forward( self, images: Tensor, # [B, 3, H, W], values in [0, 1] threshold: float = 0.3, dilation: int = 40, inpaint_mask_override: Optional[Tensor] = None, # [B, 1, H, W] optional mask return_dict: bool = False, ) -> Union[Tensor, Dict[str, Tensor]] ``` -------------------------------- ### load_pretrained Source: https://github.com/alberto-rota/unreflectanything/wiki/API Loads a raw pretrained model module directly, bypassing the UnReflectModel wrapper. Useful for advanced use cases. ```APIDOC ## load_pretrained ### Description Load a pretrained model module directly from the root inference module. ### Method Function call ### Endpoint `from inference import load_pretrained` ### Parameters - **weights_path** (str) - Required - Path to the weights file. - **config** (optional) - Config path or dict; resolved from checkpoint if None. - **device** (str, optional) - Device to use (e.g., "cuda"). - **strict** (bool, optional) - Whether to load weights strictly. - **verbose** (bool, optional) - Whether to print verbose output. - **default_config_path** (str, optional) - Fallback config path. ### Request Example ```python from inference import load_pretrained model = load_pretrained( weights_path="path/to/full_model_weights.pt", config=None, device="cuda", strict=False, verbose=False, default_config_path=None, ) ``` ### Response #### Success Response - **model** (module) - The loaded model module. ``` -------------------------------- ### cache(asset_name=None) Source: https://github.com/alberto-rota/unreflectanything/wiki/Cache Python function to retrieve the cache directory path, optionally for a specific subdirectory. ```APIDOC ## cache(asset_name=None) ### Description Return the cache directory. `None` or omitted = base dir; use `"weights"`, `"images"`, `"notebooks"`, or `"configs"` for a subdir. ### Method Function ### Endpoint `cache(asset_name: Optional[str] = None) -> Path` ### Parameters - **asset_name** (Optional[str]) - Optional - The subdirectory name. Valid values: `"weights"`, `"images"`, `"notebooks"`, `"configs"`. If `None` or omitted, returns the base cache directory. ### Returns - **Path** - The cache directory path. ### Example ```python from unreflectanything import cache base = cache() # ~/.cache/unreflectanything weights_dir = cache("weights") # base / "weights" ``` ``` -------------------------------- ### cite(format: Literal["bibtex", "apa", "mla", "ieee", "plain"] = "bibtex") -> str Source: https://github.com/alberto-rota/unreflectanything/wiki/Cite Returns the citation for UnReflectAnything in a chosen format (BibTeX, APA, MLA, IEEE, or plain text). Useful for papers and references. ```APIDOC ## cite(format: Literal["bibtex", "apa", "mla", "ieee", "plain"] = "bibtex") -> str ### Description Returns the citation for UnReflectAnything in the chosen format (BibTeX, APA, MLA, IEEE, or plain text). Useful for papers and references. ### Parameters - **format** (string) - Optional - Citation format: `"bibtex"`, `"apa"`, `"mla"`, `"ieee"`, `"plain"` (default `"bibtex"`) ### Return Value - String - The citation text ### Example ```python from unreflectanything import cite cite() cite("apa") cite("ieee") ``` ``` -------------------------------- ### Generate shell completion script Source: https://github.com/alberto-rota/unreflectanything/wiki/Completion Prints the shell completion script for bash or zsh. If the argument is omitted, the shell is inferred from $SHELL (e.g., /bin/bash → bash). Running this in a TTY offers to append the appropriate line to ~/.bashrc or ~/.zshrc. ```bash unreflect completion [bash | zsh] ``` -------------------------------- ### Python API: cite() function signature Source: https://github.com/alberto-rota/unreflectanything/wiki/Cite Defines the `cite` function with its accepted formats and default 'bibtex'. Returns the citation as a string. ```python def cite( format: Literal["bibtex", "apa", "mla", "ieee", "plain"] = "bibtex" ) -> str ``` -------------------------------- ### Python API signatures for cache and cache_clear Source: https://github.com/alberto-rota/unreflectanything/wiki/Cache Function signatures for the cache and cache_clear functions. cache returns the cache directory (base or subdir), cache_clear deletes the cache (or subdir) and prints a confirmation. ```python def cache(asset_name: Optional[str] = None) -> Path def cache_clear(asset_name: Optional[str] = None) -> Path ```