SAM3SegmentConverter
Detect a prompted object in every image and append ranked columns.
Runs a promptable segmenter over the image column and appends, for every
row, up to max_masks ranked pairs of columns: segment_i holds the
i-th highest scoring detected object rendered as its own masked image,
and seg_score_i holds that object's confidence. When
keep_binary_mask is enabled, mask_i columns are appended too. The
row count never changes: an image with fewer detected objects than
max_masks simply leaves the remaining segment_i and
seg_score_i (and, when enabled, mask_i) cells null for that row.
Because CHANGES_ROW_COUNT is false, the converter job folds the
columns this converter produces back into the dataset with
rebuild_dataset_with_transformed_columns, which preserves every
column left out of the scope untouched, but treats any scoped column
absent from this converter's own return value as removed. transform
therefore returns every column of its input unchanged, verbatim,
alongside the new ranked columns, rather than only the columns it
actually computes. The scope is expected to cover only the image column
(and any other image column the segmenter should also run over); the
image to segment among the scoped columns is chosen through the
image_column schema field.
Parameters
- prompt : string, default=
- Text describing the object to find in each image, for example 'cow'. Passed verbatim to the segmenter.
- image_column : integer, default=
1 - 1 based index, among the columns selected in the scope, of the image column to segment.
- max_masks : integer, default=
1 - Maximum number of detected instances kept per image. Instances are ranked by descending confidence score, and only the top max_masks are kept. This also fixes the number of segment_i, seg_score_i, and, when keep_binary_mask is enabled, mask_i columns the converter produces, so the output schema depends on this configuration.
- min_score : number, default=
0.5 - Minimum confidence score an instance must have to be kept.
- mask_threshold : number, default=
0.5 - Probability above which a pixel counts as part of the detected object. Lower values grow every mask, higher values tighten it. Unrelated to min_score, which drops whole instances by their confidence.
- min_area_fraction : number, default=
0.0 - Minimum fraction of the image area an instance's mask must cover to be kept.
- crop_to_bbox : boolean, default=
True - When enabled, each emitted segment image is cropped to the detected object's bounding box instead of keeping the full original image size.
- background_fill : string, default=
black - Fill applied to every pixel outside the detected object in the emitted segment image: 'black', 'white', or 'blur'.
- keep_binary_mask : boolean, default=
False - When enabled, an additional column with the object's binary mask as its own image is kept for each detected object.
- on_no_detection : string, default=
empty - What to do when no instance is detected in an image: 'empty' leaves every segment and score cell null for that row, 'keep_original' fills segment_1 with the unmodified source image and seg_score_1 with 0.0 while leaving the rest null, or 'error' to stop.
- device : string, default=
CPU - Device the segmentation model runs on. SAM 3 is a large model, so a GPU is considerably faster than the CPU.
Methods
download(cls, report: Optional[Callable[[Optional[float], Optional[str]], NoneType]] = None) -> None
SAM3SegmentConverterLog in to HuggingFace before downloading these gated weights.
Parameters
- report : ProgressReporter, optional
- Progress callback forwarded to
HFPretrainedDownloadMixin.download.
fit(self, x: 'DashAIDataset', y: 'DashAIDataset' = None) -> 'SAM3SegmentConverter'
SAM3SegmentConverterRecord the incoming column types. No model state is learned.
Parameters
- x : DashAIDataset
- The scoped dataset the converter will later transform, normally just the image column.
- y : DashAIDataset, optional
- Ignored. Defaults to None.
Returns
- SAM3SegmentConverter
- The fitted converter instance (self).
get_output_type(self, column_name: str = None) -> DashAI.back.types.dashai_data_type.DashAIDataType
SAM3SegmentConverterReturn the DashAI type produced for a given output column.
Parameters
- column_name : str, optional
- Name of the column to look up. Defaults to None.
Returns
- DashAIDataType
DashAIImage()for asegment_iormask_icolumn,Float(pa.float64())for aseg_score_icolumn, and the recorded type fromself.column_typesfor any other column.
transform(self, x: 'DashAIDataset', y: 'DashAIDataset' = None) -> 'DashAIDataset'
SAM3SegmentConverterSegment every image and append ranked segment and score columns.
Parameters
- x : DashAIDataset
- The scoped dataset to segment, normally just the image column.
- y : DashAIDataset, optional
- Ignored. Defaults to None.
Returns
- DashAIDataset
- Every column of
xunchanged, in its original position, plussegment_iandseg_score_icolumns (and, whenkeep_binary_maskis true,mask_i) for every rank from 1 tomax_masks. Every scoped column must come back out, not just the image column: the converter job folds this return value into the dataset withrebuild_dataset_with_transformed_columns, which treats any scoped column absent from this output as removed. Row count is unchanged, so this is a straight column graft ontox's own Arrow table, never a rebuild through pandas.
component_dir(cls) -> pathlib.Path
DownloadableMixinReturn this component's own storage directory.
Returns
- pathlib.Path
<COMPONENT_PATH>/<ClassName>.
delete(cls) -> None
DownloadableMixinRemove the component's downloaded artifacts.
get_credential(self, name: str)
ConfigObjectResolve a registered credential component by name.
Parameters
- name : str
- Credential component class name (e.g. "HuggingFaceCredential").
Returns
- BaseCredential
- An instance of the requested credential component.
get_metadata(cls) -> 'Dict[str, Any]'
BaseConverterGet metadata for the converter, used by the DashAI frontend.
Parameters
- cls : type
- The converter class (injected automatically by Python for classmethods).
Returns
- Dict[str, Any]
- Dictionary containing display name, short description, image preview path, category, icon, color, and whether the converter is supervised.
get_schema(cls) -> dict
ConfigObjectGenerates the component related Json Schema.
Returns
- dict
- Dictionary representing the Json Schema of the component.
hf_repos(cls)
HFPretrainedDownloadMixinDerive the single repo entry from MODEL_NAME.
Returns
- list of tuple of (str, str)
[(MODEL_NAME, "model")]or an empty list when unset.
is_downloaded(cls) -> bool
HFDownloadableMixinReturn whether all repo directories exist and are non-empty.
Returns
- bool
Truewhen every repo listed inhf_repos()has a non-empty local directory;Falseotherwise (including when the list is empty).
validate_and_transform(self, raw_data: dict) -> dict
ConfigObjectIt takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.
Parameters
- raw_data : dict
- A dictionary with the data provided by the user to initialize the model.
Returns
- dict
- A validated dictionary with the necessary objects.