Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config files are missing --> hydra.errors.MissingConfigException:Cannot find primary config 'sam2_hiera_l.yaml' #81

Closed
delvingdeep opened this issue Jul 31, 2024 · 11 comments

Comments

@delvingdeep
Copy link

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 search path.

Config search path:
	provider=hydra, path=pkg://hydra.conf
	provider=main, path=pkg://sam2_configs
	provider=schema, path=structured://

sam2 config files at /sam2_configs are missing from hydra config search path.

It would be great if they are added at package level and hence no hydra.errors.MissingConfigException

@liweiyangv
Copy link

copy the sam2_configs folder under the root project path

@CoderZhangYx
Copy link

modify here.
add relative path to the first param.

@Zora333
Copy link

Zora333 commented Aug 1, 2024

I encountered the same problem. I use the code below to solve hydra.errors.MissingConfigException, while a new error occurs: ConfigAttributeError: Key 'endswith' is not in struct .
It seems that the config file cannot be parsed properly.
Can anyone please help?

from hydra import initialize, compose
from sam2.build_sam import build_sam2

config_dir="./sam2_configs"
model_cfg = "sam2_hiera_l.yaml"
sam2_checkpoint = "./checkpoints/sam2_hiera_large.pt"

with initialize(config_path=config_dir):
    cfg = compose(config_name=model_cfg)
    sam2_model = build_sam2(cfg, sam2_checkpoint, device="cuda")

predictor = SAM2ImagePredictor(sam2_model)

@YasserElj
Copy link

you can do
pip show SAM-2
go to the packages path you get
path to packages /site-packages

copy the .yaml config file into sam2_configs under the /site-packages/

then us this code :

sam2_checkpoint = "checkpoints/sam2_hiera_large.pt"
model_cfg = "sam2_hiera_l.yaml"

sam2_model = build_sam2(model_cfg, sam2_checkpoint, device="cuda")

predictor = SAM2ImagePredictor(sam2_model)

@catalys1
Copy link

catalys1 commented Aug 1, 2024

You can fix it by reconfiguring the Hydra search path. This worked for me:

import hydra
from sam2.build_sam import build_sam2

# hydra is initialized on import of sam2, which sets the search path which can't be modified
# so we need to clear the hydra instance
hydra.core.global_hydra.GlobalHydra.instance().clear()
# reinit hydra with a new search path for configs
hydra.initialize_config_module('<path-to-sam2_configs>', version_base='1.2')

# this should work now
model = build_sam2('<config-name>', '<checkpoint-path>')

@delvingdeep
Copy link
Author

I was able to resolve this issue by building C extensions and placing the complied module in the source directory.

python setup.py build_ext --inplace

@lxin98
Copy link

lxin98 commented Aug 17, 2024

copy the sam2_configs folder under the root project path
works for me,thanks

@royvelich
Copy link

I suggested a fix if anyone is interested:
#188

@AmirulOm
Copy link

I fix by placing __init__.py in your root project (assuming that you are storing the .yaml file in the root project too). To be specific, i created a folder sam2_configs too. Here is the folder structure

- __init__.py
- sam2_configs/
   - __init__.py
   - sam2_hiera_l.yaml  

@matthias-tschoepe
Copy link

I also got this error, although I tried all before mentioned solutions, but nothing worked for me. So, I had a look at the hydra implementation and in the docu of the compose function they mention the following:

def compose(
    config_name: Optional[str] = None,
    overrides: Optional[List[str]] = None,
    return_hydra_config: bool = False,
    strict: Optional[bool] = None,
) -> DictConfig:
    """
    :param config_name: the name of the config
           (usually the file name without the .yaml extension)
    :param overrides: list of overrides for config file
    :param return_hydra_config: True to return the hydra config node in the result
    :param strict: DEPRECATED. If false, returned config has struct mode disabled.
    :return: the composed config
    """

So, I tried
sam2_model = build_sam2("sam2_hiera_s", sam2_checkpoint, device=device, apply_postprocessing=False)
instead of
sam2_model = build_sam2("/PATH_TO_CONFIG/sam2_hiera_s.yaml", sam2_checkpoint, device=device, apply_postprocessing=False)
and everything worked fine. I'm not sure if it is only me, but maybe it helps someone.

@bulat15g
Copy link

just model_cfg = "sam2_hiera_l.yaml" without full path worked for me

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

No branches or pull requests