Skip to content

Is there any way of loading the encoder from local path instead of downloading it? #957

Open
@Rafaelca70x

Description

@Rafaelca70x

I'm implementing the API on a website. I made a code that loads the model I trained and predicts on some images, but every time I load the model, the model start downloading the encoder weights. This slows down my tests. I downloaded the encoder so I was wondering if there was any way to load these weights by passing the path to the encoder?

modle_path = os.path.join(os.path.dirname(__file__), 'modelos_seg/model_dpl_efficientnet-b7') 
model = smp.from_pretrained(modle_path) # Load the pre-trained model
Downloading: "https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b7-dcc49843.pth" to /root/.cache/torch/hub/checkpoints/efficientnet-b7-dcc49843.pth
100%|██████████| 254M/254M [00:57<00:00, 4.67MB/s] 

Activity

qubvel

qubvel commented on Oct 21, 2024

@qubvel
Collaborator

Hi @Rafaelca70x , thanks for the question! The reason is that in config "encoder_weights" is set to "imagenet". That is why the model first loads "encoder" weights, and then loads weights for the whole trained model. You can modify your saved config.json to store "encoder_weights: null", it should help.

This behavior should be avoided, I would appreciate the fix if you have the bandwidth! Thanks for reporting anyway!

Rafaelca70x

Rafaelca70x commented on Oct 23, 2024

@Rafaelca70x
Author

Hi @Rafaelca70x , thanks for the question! The reason is that in config "encoder_weights" is set to "imagenet". That is why the model first loads "encoder" weights, and then loads weights for the whole trained model. You can modify your saved config.json to store "encoder_weights: null", it should help.

This behavior should be avoided, I would appreciate the fix if you have the bandwidth! Thanks for reporting anyway!

Thanks for the reply, @qubvel ! I'm asking because I'm planning to put your model in a docker to send to a computer in a region that doesn't have internet, so I want to put all the files in the docker, including the encoder.

CvBokchoy

CvBokchoy commented on Oct 26, 2024

@CvBokchoy

你好,谢谢你的提问!原因是在配置中“encoder_weights”被设置为“imagenet”。这就是为什么模型首先加载“编码器”权重,然后加载整个训练模型的权重。你可以修改你保存的json.json来存储“encoder_weights:null”,这应该会有帮助。

应该避免这种行为,如果你有带宽,我会很感激你的修复!无论如何,谢谢你的报道!

请问如何将examples/camvid_segmentation_multiclass.ipynb 中训练好的模型保存到本地 并且转为onnx模型呢?谢谢(How do I save the trained models in examples/camvid_segmentation_multiclass.ipynb locally and convert them to onnx models? thank you)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @qubvel@Rafaelca70x@CvBokchoy

        Issue actions

          Is there any way of loading the encoder from local path instead of downloading it? · Issue #957 · qubvel-org/segmentation_models.pytorch