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

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

Open
Rafaelca70x opened this issue Oct 21, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Rafaelca70x
Copy link

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] 
@qubvel
Copy link
Collaborator

qubvel commented Oct 21, 2024

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!

@qubvel qubvel added the bug Something isn't working label Oct 21, 2024
@Rafaelca70x
Copy link
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
Copy link

你好,谢谢你的提问!原因是在配置中“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
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants