티스토리 뷰
meta sam2 Config files are missing --> hydra.errors.MissingConfigException:Cannot find primary config 'sam2_hiera_l.yaml' 에러
developer0hye 2025. 4. 30. 20:53sam2 모델 쓸일이 있었는데 모델 load 하려니 config 파일을 자꾸 못찾는다고 하더라...
해결은 했다. 아래 프로젝트 구조랑 코드 참고

위 사진은 내 프로젝트 구조다 sam2 clone하고 프로젝트 폴더안에서 sam2 폴더만 필요해서 sam2 폴더만 가져왔다.
hydra 세팅을 내 코드에서 해줬다. clear(), initialize(~) 해당하는 부분이다. 이렇게 하면 코드 돌아간다. 웨이트 로드하는 건 일부러 뺐는데 될거다. 나는 official pretrained weights 말고 custom dataset pretrained weights 받아서 돌린거라 official pretrained weights load 부분은 제외했다.
import torch
from sam2.build_sam import build_sam2
from sam2.sam2_image_predictor import SAM2ImagePredictor
from hydra import initialize, compose
from hydra.core.global_hydra import GlobalHydra
from pathlib import Path
def main():
model_cfg_path = Path("sam2/configs/sam2.1")
model_cfg_file = "sam2.1_hiera_l"
GlobalHydra.instance().clear()
# 명시적 Hydra 초기화
initialize(config_path=str(model_cfg_path), job_name="sam2_inference", version_base=None)
sam2_model = build_sam2(model_cfg_file, device="cuda")
predictor = SAM2ImagePredictor(sam2_model)
GlobalHydra.instance().clear()
if __name__ == "__main__":
main()
config 쓰기 쉽고 관리하기 쉽게 만들어진 hydra... 마블의 하이드라가 돼버리다...

https://github.com/facebookresearch/sam2/issues/81
Config files are missing --> hydra.errors.MissingConfigException:Cannot find primary config 'sam2_hiera_l.yaml' · Issue #81 ·
While loading sam2 model in predictor, got an error for loading config file: "hydra.errors.MissingConfigException: Cannot find primary config 'sam2_hiera_l.yaml'. Check that it's in your config sea...
github.com
'Deep Learning' 카테고리의 다른 글
| internvl3 이 나왔었네 (0) | 2025.05.04 |
|---|---|
| hugging face grounding dino base demo space 개설 (0) | 2025.05.02 |
| u-net이 이리 오래전에 나온 모델일줄이야 (0) | 2025.04.06 |
| 2025년 2월 22일 기준 최신 vision encoder! (0) | 2025.02.22 |
| pytorch docker 이미지에서 onnxruntime-gpu cuda 인식 안되는 경우 (0) | 2025.02.21 |
- Total
- Today
- Yesterday
- MOT
- 단축키
- PyCharm
- 백준 11437
- 문제집
- 백준
- cosine
- 가장 긴 증가하는 부분 수열
- 백트래킹
- Lowest Common Ancestor
- C++ Deploy
- 백준 11053
- 순열
- 조합
- 위상 정렬 알고리즘
- 이분탐색
- 인공지능을 위한 선형대수
- 파이참
- FairMOT
- 백준 1766
- ㅂ
- LCA
- 자료구조
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
