Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make Hiera input channels and video normalization configurable#749

Open
AryanMoradi wants to merge 1 commit into
facebookresearch:mainfrom
AryanMoradi:feature/configurable-input-channels
Open

Make Hiera input channels and video normalization configurable#749
AryanMoradi wants to merge 1 commit into
facebookresearch:mainfrom
AryanMoradi:feature/configurable-input-channels

Conversation

@AryanMoradi

Copy link
Copy Markdown

Summary

  • All changes are backwards-compatible ΓÇö all new params default to their original values
  • SAM2 is increasingly used in non-RGB domains (medical imaging, satellite, IR, depth); currently requires forking just to support grayscale/single-channel inputs
  • Minimal changes: 3 files touched, 18 lines added, 5 removed

Changes

  • hieradet.py: Add in_chans param to Hiera.__init__ (default=3), passed through to PatchEmbed
  • sam2_video_predictor.py: Add img_mean/img_std params to SAM2VideoPredictor.__init__, forwarded to load_video_frames
  • misc.py: _load_img_as_tensor now accepts num_channels; grayscale images loaded as (H,W,1); hardcoded 3 in frame tensor allocation replaced with num_channels

Usage example (grayscale)

Config YAML:

model:
  _target_: sam2.modeling.sam2_base.SAM2Base
  image_encoder:
    _target_: sam2.modeling.backbones.image_encoder.ImageEncoder
    trunk:
      _target_: sam2.modeling.backbones.hieradet.Hiera
      in_chans: 1

Predictor instantiation:

predictor = SAM2VideoPredictor(
    ...,
    img_mean=(0.5,),
    img_std=(0.5,),
)

- Add in_chans param to Hiera backbone (default=3, backwards-compatible)
- Add img_mean/img_std params to SAM2VideoPredictor constructor
- Support single-channel image loading in _load_img_as_tensor

Enables use with non-RGB modalities (medical imaging, satellite, IR, etc.)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@meta-cla

meta-cla Bot commented Apr 7, 2026

Copy link
Copy Markdown

Hi @AryanMoradi!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@meta-cla

meta-cla Bot commented Apr 7, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@AryanMoradi

AryanMoradi commented Apr 7, 2026

Copy link
Copy Markdown
Author

Closes #751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant