facebookresearch / segment-anything

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
45.46k stars 5.37k forks source link

Model Registration Conflict in tiny_vit_sam.py #658

Open halqadasi opened 6 months ago

halqadasi commented 6 months ago

Hello,

I've encountered a recurring warning when working with the tiny_vit_sam.py script in the SAM repository. It seems like there's a conflict with model registration where models are being overwritten in the registry. This issue arises when different models with the same name are registered multiple times.

The script throws warnings indicating that it's overwriting models in the registry. This might lead to confusion or potential issues, especially in cases where different model versions are expected to coexist.

/usr/local/lib/python3.10/dist-packages/controlnet_aux/segment_anything/modeling/tiny_vit_sam.py:654: UserWarning: Overwriting tiny_vit_5m_224 in registry with controlnet_aux.segment_anything.modeling.tiny_vit_sam.tiny_vit_5m_224. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/usr/local/lib/python3.10/dist-packages/controlnet_aux/segment_anything/modeling/tiny_vit_sam.py:654: UserWarning: Overwriting tiny_vit_11m_224 in registry with controlnet_aux.segment_anything.modeling.tiny_vit_sam.tiny_vit_11m_224. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/usr/local/lib/python3.10/dist-packages/controlnet_aux/segment_anything/modeling/tiny_vit_sam.py:654: UserWarning: Overwriting tiny_vit_21m_224 in registry with controlnet_aux.segment_anything.modeling.tiny_vit_sam.tiny_vit_21m_224. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/usr/local/lib/python3.10/dist-packages/controlnet_aux/segment_anything/modeling/tiny_vit_sam.py:654: UserWarning: Overwriting tiny_vit_21m_384 in registry with controlnet_aux.segment_anything.modeling.tiny_vit_sam.tiny_vit_21m_384. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/usr/local/lib/python3.10/dist-packages/controlnet_aux/segment_anything/modeling/tiny_vit_sam.py:654: UserWarning: Overwriting tiny_vit_21m_512 in registry with controlnet_aux.segment_anything.modeling.tiny_vit_sam.tiny_vit_21m_512. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)

I hope this information is helpful for resolving this issue. Thank you for your attention to this matter.

XHao1997 commented 5 months ago

@halqadasi Hi, how do you fix that, I checked my code and think it's registered once

Is this where arising the warning? image

halqadasi commented 5 months ago

@XHao1997 Yes, I think this line, but multiple lines register the model. I had no choice, thus I suppressed these warnings without any solution.

geekac commented 3 months ago

I solved this problem by downgrade package timm version from 0.9.16 to 0.9.2 And, I have tested that the last version is 0.9.10 which do not print this warning.