-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Updating the tutorial file #907
Conversation
Hi @ytzfhqs, Thanks for opening PR! Overall, it looks great to me!
Thanks once again for this contribution! I will be happy to merge it after the update! |
@qubvel ,The cars segmentation (camvid) has been changed as requested. However, binary_segmentation_intro will report an error when uploading the model to the HF Hub: ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[19], line 4
2 smp_model = model.model
3 # if push_to_hub=True, model will be saved to repository with this name
----> 4 commit_info = smp_model.save_pretrained(
5 save_directory="qubvel-hf/oxford-pet-segmentation",
6 push_to_hub=True, # optional, push model to HF Hub
7 metrics=test_metrics, # optional, save metrics in model card
8 dataset="Oxford Pet", # optional, save dataset name in model card
9 )
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1695, in Module.__getattr__(self, name)
1693 if name in modules:
1694 return modules[name]
-> 1695 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'FPN' object has no attribute 'save_pretrained' I tried the example in ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
[<ipython-input-2-17ebc9899347>](https://localhost:8080/#) in <cell line: 6>()
4
5 # After training your model, save it to a directory
----> 6 model.save_pretrained('./my_model')
[/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in __getattr__(self, name)
1707 if name in modules:
1708 return modules[name]
-> 1709 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
1710
1711 def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None:
AttributeError: 'Unet' object has no attribute 'save_pretrained' colad link, I can't fix the bug.Can you give me some advice? |
You have to install the library from the source and paste this installation on the top of the script (the pypi package is not released yet)
|
Thanks for the suggestion, I solved the model saving problem, but it was running: commit_info = smp_model.save_pretrained(
save_directory=‘ytzfhqs/oxford-pet-segmentation’,
push_to_hub=True, # optional, push model to HF Hub
metrics=test_metrics, # optional, save metrics in model card
dataset=‘Oxford Pet’, # optional, save dataset name in model card
) An error occurs: ---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-9-63eccb09cc45> in <cell line: 2>()
1 smp_model = model
----> 2 commit_info = smp_model.save_pretrained(
3 save_directory=‘ytzfhqs/oxford-pet-segmentation’,
4metrics=test_metrics, # optional, save metrics in model card
5 push_to_hub=True, # optional, push model to HF Hub
6 dataset=‘Oxford Pet’, # optional, save dataset name in model card
/usr/local/lib/python3.10/dist-packages/segmentation_models_pytorch/base/hub_mixin.py in save_pretrained(self, save_directory, *args, * *kwargs)
121 # delete the additional attributes
122 self._del_attrs([‘save_directory’, ‘metrics’, ‘dataset’])
--> 123 self._hub_mixin_config.pop(‘_model_class’)
124
125 return result
KeyError: ‘_model_class’ I checked the ...
self._hub_mixin_config.pop(‘_model_class’)
... It looks like the ...
result = super().save_pretrained(save_directory, *args, **kwargs)
... Then I checked the ...
if config is None.
config = self._hub_mixin_config
... The above overrides the ...
self._hub_mixin_config.pop(‘_model_class’)
... An error occurs, and because of the limitations of my current device I can't make further refinements, so I simply comment out the ...
self._hub_mixin_config.pop(‘_model_class’)
... Then Save model to HF Hub works fine! You can check out cars segmentation (camvid) at kaggle,binary_segmentation_intro at github. |
Thanks for the investigation of this HF hub problem. Would you like to make a small PR to fix the mixin issue? Then we will be able to merge these PRs too for example we can add self._hub_mixin_config.pop(‘_model_class’, None) |
Sure, very happy to help, I've proposed a new PR. I would recommend releasing the new version in the pypi package as soon as possible for support pushing the model to the HF hub. otherwise users may need to use I will update the installation section of the |
Thanks for the update, I think it's in good shape to merge! May I ask you to update also a few more things for consistency in CamVid notebook:
Thanks for iterating! |
import albumentations as albu -> import albumentations as A # 训练集增强策略 -> # training set images augmentation
Already iterated as required. |
Ok, thanks a lot for the update! looks good to me! |
Hi, I noticed that the tutorial files have not been updated for a long time, including version dependencies on
pytorch-Lightning
andalbumentations
in the fileexamples/binary_segmentation_intro.ipynb
:Unfortunately
pytorch-Lightning
has deprecated this approach in v2.0.0, so I've fixed this section according to the migration guide and kept the original as much as possible structure of the code as much as possible.in the file
examples/cars segmentation (camvid).ipynb
:Due to a version update of
segmentation-models-pytorch
, this writeup is no longer supported, so I rewrote it based on the structure of thepytorch-Lightning
code in the fileexamples/binary_segmentation_intro.ipynb
, and additionally in the image enhancement usingalbumentations
:albumentations
has been deprecated in newer versions of official documentation. So I fixed it usingalbu.Sharpen()
Overall, the new tutorial files run perfectly with the latest versions of
pytorch-Lightning
andalbumentations
. Here's a link to my notebook running the tutorial files on kaggle, binary_segmentation_intro, cars segmentation (camvid)