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

'DeepLabV3Plus' object has no attribute 'save_pretrained' #880

Open
Marcus2331 opened this issue Jun 3, 2024 · 9 comments
Open

'DeepLabV3Plus' object has no attribute 'save_pretrained' #880

Marcus2331 opened this issue Jun 3, 2024 · 9 comments
Labels
question Information

Comments

@Marcus2331
Copy link

Marcus2331 commented Jun 3, 2024

Почему тут есть возможность сохранения модели https://smp.readthedocs.io/en/latest/save_load.html как в документации. А я не могу сохранить модель DeepLabV3Plus?

Why is it possible to save the model here https://smp.readthedocs.io/en/latest/save_load.html as in the documentation. Can't I save the DeepLabV3Plus model?

@Marcus2331
Copy link
Author

Marcus2331 commented Jun 3, 2024

import torch
import segmentation_models_pytorch as smp
model = smp.DeepLabV3Plus(
    encoder_name="efficientnet-b5",    # Выбранный энкодер
    encoder_weights=None,        # Использование предобученных весов на ImageNet
    in_channels=1,                     # Количество входных каналов (например, 1 для черно-белых изображений)
    classes=1,                         # Количество классов для выходной маски
    activation='sigmoid'              # Функция активации
)
model = torch.nn.DataParallel(model)
model = model.cpu()

# Путь к сохраненной модели
PATH = 'best_model_epoch_8.pt'
model.load_state_dict(torch.load(PATH, map_location=torch.device('cpu')))
if isinstance(model, torch.nn.DataParallel):
    model = model.module
# Перевод модели в режим оценки
model.eval()
# After training your model, save it to a directory
model.save_pretrained('./model')

AttributeError: 'DeepLabV3Plus' object has no attribute 'save_pretrained'

@qubvel
Copy link
Owner

qubvel commented Jun 3, 2024

Hi @Marcus2331, thanks for the issue!
The feature has not been released yet to PyPI package!

But you could try it out if you reinstall the library from the source with

pip install -U git+https://github.com/qubvel/segmentation_models.pytorch

I will release it to PyPI in a few days or so!

@qubvel qubvel added the question Information label Jun 3, 2024
@Marcus2331
Copy link
Author

Привет@Marcus2331, спасибо за проблему! Эта функция еще не добавлена ​​в пакет PyPI!

Но вы можете попробовать, если переустановите библиотеку из исходного кода с помощью

pip install -U git+https://github.com/qubvel/segmentation_models.pytorch

Я выпущу его для PyPI примерно через несколько дней!

Thanks for the quick feedback

@Marcus2331
Copy link
Author

Привет@Marcus2331, спасибо за проблему! Эта функция еще не добавлена ​​в пакет PyPI!

Но вы можете попробовать, если переустановите библиотеку из исходного кода с помощью

pip install -U git+https://github.com/qubvel/segmentation_models.pytorch

Я выпущу его для PyPI примерно через несколько дней!

Прошу прощения возможно за глупый вопрос. Но есть ли возможность экспорта модели обученной на библиотеке smp в формат tf_saved_model Для tensorflow_serving?

@qubvel
Copy link
Owner

qubvel commented Jun 4, 2024

I tried an approach that Chat-GPT recommended, it seems to work fine, check this out in Colab:

https://colab.research.google.com/drive/1J5dAmPfMcoJkDv9Bh_IbDxKjafhCFCmM?usp=sharing

And, please, let me know if you have any questions or this solves your issue 🙂 I will include this example to examples folder then and in docs

@Marcus2331
Copy link
Author

I tried an approach that Chat-GPT recommended, it seems to work fine, check this out in Colab:

https://colab.research.google.com/drive/1J5dAmPfMcoJkDv9Bh_IbDxKjafhCFCmM?usp=sharing

And, please, let me know if you have any questions or this solves your issue 🙂 I will include this example to examples folder then and in docs

Слезно прошу вас помочь мне с конвертацией модели которую я сохранил с помощью model.save_pretrained('./model') сконвертировать в формат tf_saved_model для дальнейшего использования в tensorflow_serving:((

@qubvel
Copy link
Owner

qubvel commented Jun 7, 2024

Did you try to do it with provided colab example?

@qubvel
Copy link
Owner

qubvel commented Jun 9, 2024

Consider also looking at
PINTO0309/onnx2tf#543

@Marcus2331
Copy link
Author

Consider also looking at PINTO0309/onnx2tf#543

Thank you so much!!! this solved my problem)

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

No branches or pull requests

2 participants