AutoForge
AutoForge is a Python tool for generating 3D printed layered models from an input image. Using a learned optimization strategy with a Gumbel softmax formulation, AutoForge assigns materials per layer and produces both a discretized composite image and a 3D-printable STL file. It also generates swap instructions to guide the printer through material changes during a multi-material print.
TLDR: It uses a picture to generate a 3D layer image that you can print with a 3d printer. Similar to Hueforge, but without the manual work.

Example
All examples use only the 27 BambuLab Basic PLA filaments, currently available in Hueforge 0.9.0, the background color is set to black.
The pruning is set to a maximum of 8 color and 20 swaps, so each image uses at most 8 different colors and swaps the filament at most 20 times.
Features
- Image-to-Model Conversion: Converts an input image into a layered model suitable for 3D printing.
- Learned Optimization: Optimizes per-pixel height and per-layer material assignments using PyTorch.
- Learned Heightmap: Optimizes the height of the layered model to create more detailed prints.
- Gumbel Softmax Sampling: Leverages the Gumbel softmax method to decide material assignments for each layer.
- FlatForge Mode: Generate separate STL files for each color, enabling face-down printing for smooth, resin-like finishes.
- STL File Generation: Exports an ASCII STL file based on the optimized height map.
- Swap Instructions: Generates clear swap instructions for changing materials during printing.
- Live Visualization: (Optional) Displays live composite images during the optimization process.
- Hueforge export: Outputs a project file that can be opened with hueforge.
Web UI: One-Click Install & Run
The easiest way to use AutoForge is the web UI, a local app with drag-and-drop image upload, a filament library, live sliders for adjusting colors after optimization, and pruning. No command-line arguments needed.
Clone this repository (or download and extract the ZIP from the green "Code" button on GitHub).
Install, from the project folder:
- Linux/macOS:
./install.sh
- Windows: double-click
install.bat (or run it from a terminal)
This installs uv (a fast Python package manager) if you don't already have it, installs all Python dependencies, and builds the web UI. You'll need Node.js installed for that last step, the installer will tell you if it's missing.
Run:
- Linux/macOS:
./run_webui.sh
- Windows: double-click
run_webui.bat
This starts the server and opens the web UI in your browser automatically (usually at http://localhost:8000).
It only listens on this computer by default, since the web UI has no login. To open it from other devices on your network, start it with WEBUI_HOST=0.0.0.0 ./run_webui.sh (Windows: set WEBUI_HOST=0.0.0.0 before run_webui.bat). Open it by IP address or by this computer's name; any other name (for example one from a reverse proxy) has to be listed in AUTOFORGE_WEBUI_ALLOWED_HOSTS (comma separated).
To make some parts of the picture come out closer than the rest (a face, the eyes, lettering), click Focus in the image panel and paint over them; a slider sets how much more they count (2× to 100×, default 10×). After a run, the Differences view shows where the print strays furthest from the picture.
If HueForge is installed on the same computer, the web UI finds your HueForge personal filament library and offers to import it once, on its first start.
To find a filament you own without measuring it yourself, click Catalog in the filament library. It searches every filament on filamentcolors.xyz that has a measured TD (search by brand, color name, type or hex code; filter by type, brand or color family; or pick a color to see the closest matches first), and Add puts it straight into your library.
The web UI sends anonymous usage telemetry to the project via PostHog by default, to notify me of problems and any bugs. This includes crash reports (unhandled errors from both the browser frontend and the backend server, with the error type, message, and stack trace) so bugs can get fixed faster. No image data, filament data or other personal information is sent, except that error messages and stack traces can contain file paths (the backend replaces your home folder in them with ~, so your user name isn't sent from there; the browser's own stack traces only name the app's script files). To disable it, pass --no-telemetry (e.g. ./run_webui.sh --no-telemetry / run_webui.bat --no-telemetry), or set AUTOFORGE_WEBUI_TELEMETRY_ENABLED=false permanently in your environment.
Update to the latest release whenever you want, from the project folder:
- Linux/macOS:
./update.sh
- Windows: double-click
update.bat
This checks GitHub for a newer release and, if one exists, pulls it and reinstalls dependencies for you. Add --check to only check without applying it (e.g. ./update.sh --check).
GPU support
AutoForge runs on NVIDIA GPUs (CUDA), AMD GPUs (ROCm, Linux), Apple Silicon (MPS / Apple Metal) and, more slowly, on the CPU. The device is picked automatically in that order; override it with --device or the AUTOFORGE_DEVICE environment variable (e.g. AUTOFORGE_DEVICE=cpu).
install.sh installs the matching PyTorch build for you:
- NVIDIA: the default CUDA build; older (pre-Turing, e.g. GTX 10xx) cards automatically get the CUDA 12.6 build, the last one with kernels for them.
- AMD (Linux): detected through
/dev/kfd and given the ROCm build. Consumer Radeon cards that ROCm doesn't officially list may need e.g. HSA_OVERRIDE_GFX_VERSION=10.3.0 (RX 6000) or 11.0.0 (RX 7000) set when running.
- Apple Silicon: the default macOS build already includes MPS.
- Anything else: run
AUTOFORGE_TORCH_INDEX=<PyTorch wheel index> ./install.sh, e.g. https://download.pytorch.org/whl/cpu. ./update.sh keeps whichever build was installed.
If the fused GPU kernels (Triton) cause trouble on your GPU, AUTOFORGE_TRITON=off switches to the plain PyTorch code path. For other GPU problems, see the PyTorch homepage.
Manual Installation (CLI only)
If you just want the command-line tool (no web UI), install the current version from PyPI:
pip install -U autoforge
If you have problems running the code on your gpu, please refer to the Pytorch Homepage for help.
CUDA, ROCm, and MPS (Apple Metal) are supported, but you need to install the correct version of pytorch for your system.
Usage
The script is run from the command line and accepts several arguments. Below is an example command:
Note: You will need Hueforge installed to export your filament CSV.
To get your CSV file, simply go to the "Filaments" menu in Hueforge, click the export button, select your filaments, and export them as a CSV file.
autoforge --input_image path/to/input_image.jpg --csv_file path/to/materials.csv
We also support json files. If you want to use your personal Hueforge library (found in %APPDATA%\HueForge\Filaments\personal_library.json) you can run the command with:
autoforge --input_image path/to/input_image.jpg --json_file %APPDATA%\HueForge\Filaments\personal_library.json
If you want to limit the amount of colors the program can use, you can set these as command line arguments.
For Example: 8 colors and a maximum of 20 swaps:
autoforge --input_image path/to/input_image.jpg --csv_file path/to/materials.csv --pruning_max_colors 8 --pruning_max_swaps 20
FlatForge Mode
To use FlatForge mode for smooth, face-down printing:
autoforge --input_image path/to/input_image.jpg --csv_file path/to/materials.csv --flatforge --pruning_max_colors 4 --cap_layers 2
This will generate separate STL files for each color, allowing you to print face-down on the build plate for a smooth finish. With --pruning_max_colors 4, you'll get 2 colored materials + 1 clear filament + 1 background = 4 total filaments (perfect for a 4-slot AMS).
Command Line Arguments
--config (Optional) Path to a configuration file with the settings.
--input_image (Required) Path to the input image.
--csv_file Path to the CSV file containing material data. The CSV should include columns for the brand, name, color (hex code), and TD values.
--json_file Path to the json file containing material data.
Note: Either a csv or json file has to be given.
--output_folder Folder where output files will be saved (default: output).
--iterations Number of optimization iterations (default: 2000).
--warmup_fraction Fraction of iterations for keeping the tau at the initial value (default: 0.25).
--learning_rate_warmup_fraction Fraction of iterations that the learning rate is increasing (warmup) (default: 0.25).
--init_tau Initial tau value for Gumbel-Softmax (default: 1.0).
--final_tau Final tau value for the Gumbel-Softmax formulation (default: 0.01).
--learning_rate Learning rate for optimization (default: 0.015).
--layer_height Layer thickness in millimeters (default: 0.04).
--max_layers Maximum number of layers (default: 75).
Note: This is about 3mm + the background height
--min_layers Minimum number of layers (default: 0). Used to limit height of pruning.
--background_height Height of the background in millimeters (default: 0.24).
Note: The background height must be divisible by the layer height.
--background_color Background color in hexadecimal format (default: #000000 aka Black).
Note: The solver currently assumes that you have a solid color in the background, which means a color with a TD value of 4 or less (if you have a background height of 0.4).
--visualize enable live visualization of the composite image during optimization (default: True).
--stl_output_size Size of the longest dimension of the output STL file in millimeters (default: 200).
--processing_reduction_factor Reduction factor for the processing size compared to the output size (default: 2 - half resolution).
--nozzle_diameter Diameter of the printer nozzle in millimeters (default: 0.4).
Note: Details smaller than half this value will be ignored.
--early_stopping Number of steps without improvement before stopping (default: 3000).
--priority_mask (Optional) Path to a greyscale image the size of the input that marks the parts that matter most: white areas are matched more closely, black areas still count, just less.
--priority_mask_strength How many times more a white pixel of --priority_mask counts than a black one (default: 10; must be at least 1). Raise it if the marked areas still come out off, lower it for a gentler nudge.
--flatforge Enable FlatForge mode to generate separate STL files for each color (default: False).
Note: FlatForge creates flat prints where each color is its own STL file, allowing face-down printing for smooth, resin-like finishes. Requires a multi-material printer (AMS, MMU, or tool changer).
--cap_layers Number of complete transparent/clear layers to add on top in FlatForge mode (default: 0).
Note: Creates a glossy cap layer over the colored layers for a resin-filled appearance. Only used when --flatforge is enabled.