SIGN IN SIGN UP

feat(transforms): add mask_fn to DetConSTransform for callable segmentation (#1981)

Using unsupervised masks with DetConS previously required a helper
function that ran the segmenter, wrapped the result into a Mask, and
threaded it through the transform manually (see #1969, #1971).

Add an optional mask_fn that maps an image to segmentation labels. The
mask is generated once per image inside the transform (so it runs in the
dataloader workers and both views share the same segmentation) and is
wrapped into a torchvision Mask internally, so scikit-image / cv2
segmenters such as felzenszwalb work via functools.partial without any
Mask boilerplate. mask_fn and grid_size are mutually exclusive.

Simplify examples/pytorch/detcon.py to use mask_fn, dropping the
hand-rolled mask helper.

Closes #1972.

Co-authored-by: Saud Kamran <saud.kamran92@gmail.com>
S
Saud Kamran committed
da99523901737cae89f93a049dbaa5d559fd1432
Parent: 3f81505
Committed by GitHub <noreply@github.com> on 7/22/2026, 6:18:04 PM