Facebook's Hydra

本文探讨了软件配置管理的重要性,对比了Spring和Facebook的Hydra在配置解决方案上的不同。Spring通过XML和YAML提供全面的组件配置,而Hydra基于YAML,但在配置的灵活性和深度上有所欠缺。

Facebook’s Hydra

Configuration is always essential for any programming language. Spring’s configuration is the best and perfect solution for Java. In Python, there is no comparable solution. Facebook’s Hydra is another attempt to provide a solution based on YAML.

Configuration in software is to externalize settings so that users can alternate software behaviors. However, tackling only configuration is not enough to serve the purpose because configuration penetrates into internal structure, i.e., it has to know internal components in order to configure. Spring uses beans for universal representation of components and configuration. The bean structure provides grouping of specifications, like plastic bags for grocery shopping. I don’t see similar structure in Hydra, need more time to investigate.

Spring uses XML for bean structures. For universal treatment, it uses XML for configuration beans as well as component beans. This fact results that many folks do not like it because they prefer compilable code for component dependency. However, the new solution based on YAML, such as Spring Boot, is not my favorite either. First, there is only one key-value pair per line and so the settings are really long. Second, many of the settings for different components have to be in one file, because we can’t include one YAML in another. Last, YAML can not be used for component configuration. Though this is arguable since component configuration is not property configuration, it would be convenient if there is an uniform way to treat both configurations.

Software applications are trees of components. configuration settings can sit on any tree nodes/components. We may have many application level configurations, such as dev, uat, and prod. In each application configuration, we may choose to override some of the default configurations. Spring uses XML file order for overriding, Spring Boot uses profiles. Both can override many settings from a file, in a manageable/grouping fashion. Hydra does this from command line switches. This is convenient for small numbers of overriding, but will be messy for many.

We need a better YAML, YYAML.

FileNotFoundError Traceback (most recent call last) Cell In[33], line 28 25 sam2_checkpoint = "../checkpoints/sam2.1_hiera_large.pt" 26 model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml" ---> 28 sam2_model = build_sam2(model_cfg, sam2_checkpoint, device=device) 30 predictor = SAM2ImagePredictor(sam2_model) File D:\vscode\sam2-main\sam2\build_sam.py:93, in build_sam2(config_file, ckpt_path, device, mode, hydra_overrides_extra, apply_postprocessing, **kwargs) 91 OmegaConf.resolve(cfg) 92 model = instantiate(cfg.model, _recursive_=True) ---> 93 _load_checkpoint(model, ckpt_path) 94 model = model.to(device) 95 if mode == "eval": File D:\vscode\sam2-main\sam2\build_sam.py:166, in _load_checkpoint(model, ckpt_path) 164 def _load_checkpoint(model, ckpt_path): 165 if ckpt_path is not None: --> 166 sd = torch.load(ckpt_path, map_location="cpu", weights_only=True)["model"] 167 missing_keys, unexpected_keys = model.load_state_dict(sd) 168 if missing_keys: File c:\Users\yaoting.liu\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\serialization.py:1479, in load(f, map_location, pickle_module, weights_only, mmap, **pickle_load_args) 1476 if "encoding" not in pickle_load_args.keys(): 1477 pickle_load_args["encoding"] = "utf-8" ... File c:\Users\yaoting.liu\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\serialization.py:740, in _open_file.__init__(self, name, mode) 739 def __init__(self, name: Union[str, os.PathLike[str]], mode: str) -> None: --> 740 super().__init__(open(name, mode)) FileNotFoundError: [Errno 2] No such file or directory: '../checkpoints/sam2.1_hiera_large.pt' Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings... 现在是这个报错,确实是我从github上面下载的源代码checkpoints里面没有这个项目,里面只有这个东西,我现在应该怎么操作?#!/bin/bash # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # Use either wget or curl to download the checkpoints if command -v wget &> /dev/null; then CMD="wget" elif command -v curl &> /dev/null; then CMD="curl -L -O" else echo "Please install wget or curl to download the checkpoints." exit 1 fi # Define the URLs for SAM 2 checkpoints # SAM2_BASE_URL="https://dl.fbaipublicfiles.com/segment_anything_2/072824" # sam2_hiera_t_url="${SAM2_BASE_URL}/sam2_hiera_tiny.pt" # sam2_hiera_s_url="${SAM2_BASE_URL}/sam2_hiera_small.pt" # sam2_hiera_b_plus_url="${SAM2_BASE_URL}/sam2_hiera_base_plus.pt" # sam2_hiera_l_url="${SAM2_BASE_URL}/sam2_hiera_large.pt" # Download each of the four checkpoints using wget # echo "Downloading sam2_hiera_tiny.pt checkpoint..." # $CMD $sam2_hiera_t_url || { echo "Failed to download checkpoint from $sam2_hiera_t_url"; exit 1; } # echo "Downloading sam2_hiera_small.pt checkpoint..." # $CMD $sam2_hiera_s_url || { echo "Failed to download checkpoint from $sam2_hiera_s_url"; exit 1; } # echo "Downloading sam2_hiera_base_plus.pt checkpoint..." # $CMD $sam2_hiera_b_plus_url || { echo "Failed to download checkpoint from $sam2_hiera_b_plus_url"; exit 1; } # echo "Downloading sam2_hiera_large.pt checkpoint..." # $CMD $sam2_hiera_l_url || { echo "Failed to download checkpoint from $sam2_hiera_l_url"; exit 1; } # Define the URLs for SAM 2.1 checkpoints SAM2p1_BASE_URL="https://dl.fbaipublicfiles.com/segment_anything_2/092824" sam2p1_hiera_t_url="${SAM2p1_BASE_URL}/sam2.1_hiera_tiny.pt" sam2p1_hiera_s_url="${SAM2p1_BASE_URL}/sam2.1_hiera_small.pt" sam2p1_hiera_b_plus_url="${SAM2p1_BASE_URL}/sam2.1_hiera_base_plus.pt" sam2p1_hiera_l_url="${SAM2p1_BASE_URL}/sam2.1_hiera_large.pt" # SAM 2.1 checkpoints echo "Downloading sam2.1_hiera_tiny.pt checkpoint..." $CMD $sam2p1_hiera_t_url || { echo "Failed to download checkpoint from $sam2p1_hiera_t_url"; exit 1; } echo "Downloading sam2.1_hiera_small.pt checkpoint..." $CMD $sam2p1_hiera_s_url || { echo "Failed to download checkpoint from $sam2p1_hiera_s_url"; exit 1; } echo "Downloading sam2.1_hiera_base_plus.pt checkpoint..." $CMD $sam2p1_hiera_b_plus_url || { echo "Failed to download checkpoint from $sam2p1_hiera_b_plus_url"; exit 1; } echo "Downloading sam2.1_hiera_large.pt checkpoint..." $CMD $sam2p1_hiera_l_url || { echo "Failed to download checkpoint from $sam2p1_hiera_l_url"; exit 1; } echo "All checkpoints are downloaded successfully."
07-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值