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

PyTorch backend doesn't work in Kaggle notebook #150

Open
romanvelichkin opened this issue Dec 29, 2023 · 4 comments
Open

PyTorch backend doesn't work in Kaggle notebook #150

romanvelichkin opened this issue Dec 29, 2023 · 4 comments

Comments

@romanvelichkin
Copy link

I'm trying to run model on Kaggle notebook using PyTorch backend. I guess notebook by defaul has both Tensorflow and PyTorch. And because of that package create tensorflow model no matter if environ set to "torch".

Code:

os.environ["KECAM_BACKEND"] = "torch"
import torch
from keras_cv_attention_models import efficientnet

model = efficientnet.EfficientNetV2B0(is_torch_mode=True,
                                      pretrained='imagenet21k', # weights pretrained on imagenet21k
                                      num_classes=num_classes,
                                      classifier_activation=activation_fn,
                                      dropout=0.25,
                                     )
print(f"{isinstance(model, torch.nn.Module) = }")

Output:

torch
>>>> Load pretrained from: /root/.keras/models/efficientnetv2-b0-21k.h5
isinstance(model, torch.nn.Module) = False
@romanvelichkin
Copy link
Author

romanvelichkin commented Dec 29, 2023

I deleted tensorflow and keras, restarted kernel, and then kecam started to use pytorch backend.

@leondgarse
Copy link
Owner

Sorry for the late reply. Just back from a vacation.
Deleting tensorflow and keras shouldn't be necessary, as most time I'm also using all them installed. Also this colab basic test kecam_test.ipynb. I'm not sure, maybe keras_cv_attention_models is already imported before setting KECAM_BACKEND env?

@romanvelichkin
Copy link
Author

Sorry for the late reply. Just back from a vacation. Deleting tensorflow and keras shouldn't be necessary, as most time I'm also using all them installed. Also this colab basic test kecam_test.ipynb. I'm not sure, maybe keras_cv_attention_models is already imported before setting KECAM_BACKEND env?

The problem is not about os variable. Kecam creates tensorflow (not pytorch) model even if variable was set to 'torch' in situation when environment has both pytorch and tensorflow. I'm not sure about google collab or desktop jupyter, I met problem in Kaggle notebook. You can check again my first post.

@leondgarse
Copy link
Owner

Ya, It should work not matter colab or kaggle notebook. Here's my basic kaggle notebook test kaggle kecam_test.

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

No branches or pull requests

2 participants