Add SAM-style segmentation architecture#21492
Conversation
So a PR that enables SAM3 specifically, if merged, says that darktable is endorsing running SAM3, which it's not. If you want to make a generic (non model specific) way to add ANY model to darktable, then that would be acceptable. If the user wanted to use SAM3 darktable isn't going to stand in the way, but neither is it going to endorse it. An example: In the lua-scripts there is contrib/gimp.lua,, which lets a user export an image and edit it with GIMP. Since it's open source, anyone could take that script and change it to launch photoshop instead of GIMP and that's OK. But, if they want that script merged into the lua-scripts, it won't happen because the script is promoting the use of commercial software. However, if someone makes a script that allows you to open an image and edit it with any executable that you specify, such as contrib/ext_editor.lua, then that's fine. It's up to the user what editor they use and darktable isn't endorsing anything. |
I understand and will try to make a generic arch. Perhaps if put the dimensions in the config.json or something like that. |
|
The last commit remove the SAM3 and add a generic "SAM-style" architecture. The input and mask size can be defined in the config.json. {
"arch": "sam",
"attributes": {
"input_size": 1008,
"prev_mask_size": 288,
"encoder_optimization": "disabled"
}
}To test it, you can download sam3.pt from the Hugging Face and run this script to create the .dtmodel. |
|
Have you looked at the following page to ensure this meets our policy about AI: https://github.com/darktable-org/darktable/wiki/AI-Model-Integration-Policy |
|
SAM3 model does not meet requirements of our AI policy. First of all in terms of license - it is not compatible with GPL-3 and not a free model. So SAM3 model can not be added to out official model repository. However, adding attributes support to the I will review this PR a bit later. Need some time for this. |
I did and I know SAM3 don't meet your policy. It uses a custome license called the SAM licience. It is permissive, but not open sourced. My goal was not to have darktable distribute SAM3 in a repositorry. I understand this will never happen. I wanted to create the arch so people could manually add SAM3 they get from a third-party. But like Bill pointed out adding a SAM3 arch means that darktable endorse that model and it's not acceptable. That's why 2c042d2 only add attributes support. We set the dimensions in the config.json, which allows darktable to accept any "SAM-style" segmentation because we can define the parameters within the configuration file.
Thanks and no rush. I'm not sure I'm allowed to upload SAM3, so I put a script to convert the .pt into a .dtmodel. You can get the .pt from the HF. |
This PR Add support for the SAM3 segmentation models ("arch": "sam3"). I know darktable can't ship SAM3 because of licences, but someone could get the model on its own if it is supported.
SAM3 uses the existing SAM-style encoder/decoder flow but with different dimensions:
The SAM2 path remains unchanged at 1024x1024 input and 256x256 mask size. SegNext behavior is unchanged.
For SAM3 encoder loading, graph optimizations are disabled to avoid ONNX Runtime session creation issues.
To test it, you can request access to SAM3 and download sam3.pt (https://huggingface.co/facebook/sam3). Place it alongside this script and run it with
uv run export_sam3_native.py. This will createmask-object-sam3.dtmodelyou can import in darktable.Disclaimer: Co-created with Codex.