ZoeDepth icon indicating copy to clipboard operation
ZoeDepth copied to clipboard

Can we load model from local with out internet?

Open dreamlychina opened this issue 1 year ago • 6 comments

I just follow the #9, but the code still need the internet? conf = get_config("zoedepth", "infer", pretrained_resource="local::/path/to/checkpoint.pt") model_zoe_n = build_model(conf)

I just want to know how inference the image without the internet? Could please give some advices?

dreamlychina avatar Oct 12 '23 01:10 dreamlychina

+1

yahooo-m avatar Oct 12 '23 09:10 yahooo-m

可以离线,需要修改下配置就可以

| | 钱文明 | | @.*** | 签名由网易邮箱大师定制

On 01/23/2024 14:03,Wenyuan @.***> wrote:

any ideas now?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

dreamlychina avatar Jan 24 '24 01:01 dreamlychina

MiDaS repository is also downloaded from the Internet. https://github.com/isl-org/ZoeDepth/blob/edb6daf45458569e24f50250ef1ed08c015f17a7/zoedepth/models/base_models/midas.py#L341-L342

Also, torch.hub.load accesses the Internet to get the main branch name(main or master) if the branch name is not specified, even if the repository cache exists. (However, in this case, unsuccessful Internet access does not result in an error) If you want to stop access to the Internet completely, you will need to change the code.

nagadomi avatar Jan 24 '24 15:01 nagadomi

@nagadomi

MiDaS repository is also downloaded from the Internet.

https://github.com/isl-org/ZoeDepth/blob/edb6daf45458569e24f50250ef1ed08c015f17a7/zoedepth/models/base_models/midas.py#L341-L342

Also, torch.hub.load accesses the Internet to get the main branch name(main or master) if the branch name is not specified, even if the repository cache exists. (However, in this case, unsuccessful Internet access does not result in an error) If you want to stop access to the Internet completely, you will need to change the code.

Yes , you are correct , I have modified it midas = DPTDepthModel( path="dpt_beit_large_384.pt", backbone="beitl16_384", non_negative=True, ) it works for me

JunLFang avatar Jan 26 '24 07:01 JunLFang

@nagadomi

MiDaS repository is also downloaded from the Internet. https://github.com/isl-org/ZoeDepth/blob/edb6daf45458569e24f50250ef1ed08c015f17a7/zoedepth/models/base_models/midas.py#L341-L342

Also, torch.hub.load accesses the Internet to get the main branch name(main or master) if the branch name is not specified, even if the repository cache exists. (However, in this case, unsuccessful Internet access does not result in an error) If you want to stop access to the Internet completely, you will need to change the code.

Yes , you are correct , I have modified it midas = DPTDepthModel( path="dpt_beit_large_384.pt", backbone="beitl16_384", non_negative=True, ) it works for me

I modified the code as you said, but there's still a problem. Because DPTDepthModel is in ~/.cache/torch/hub/intel-isl_MiDaS_master/midas/dpt_depth.py, I tried several ways to import it in midas.py but they all failed. I wonder how you solved this problem. Maybe I should change the path of Midas model?

CDJdplus avatar Jan 30 '24 03:01 CDJdplus

@nagadomi I changed the code ZoeDepth/zoedepth/models/base_models/midas.py

Lines 341 to 342 in edb6daf

 midas = torch.hub.load("intel-isl/MiDaS", midas_model_type, 
                        pretrained=use_pretrained_midas, force_reload=force_reload)

to

local_repo_path = '/root/.cache/torch/hub/intel-isl_MiDaS_master'  # 替换为实际路径
midas = torch.hub.load(local_repo_path, midas_model_type, source='local')

and Downloading: "https://github.com/isl-org/MiDaS/releases/download/v3_1/dpt_beit_large_384.pt" to /root/.cache/torch/hub/checkpoints/dpt_beit_large_384.pt or vim /root/.cache/torch/hub/intel-isl_MiDaS_master/hubconf.py change Lines 44 to 52

if pretrained:
        checkpoint = (
            "local_weights/dpt_beit_large_384.pt"
        )
        state_dict = torch.load(checkpoint, map_location=torch.device('cpu'))
        # state_dict = torch.hub.load_state_dict_from_url(
        #     checkpoint, map_location=torch.device('cpu'), progress=True, check_hash=True
        # )
        model.load_state_dict(state_dict)
    return model

Load successfully in the absence of network

shuai-dian avatar Apr 11 '24 02:04 shuai-dian