ModuleNotFoundError: No module named 'pytorch_grad_cam.metrics' - pytorch

Pytorch Grad-Cam was working well with my resnet18 models till 23rd of Aug 2022. Suddenly from today, 24th Aug I am constantly getting this error
ModuleNotFoundError: No module named 'pytorch_grad_cam.metrics'
when I run the code in both, colab and spyder:
from pytorch_grad_cam import GradCAM, HiResCAM, ScoreCAM, GradCAMPlusPlus, AblationCAM,
XGradCAM, EigenCAM, FullGrad
from pytorch_grad_cam.utils.model_targets import ClassifierOutputTarget
from pytorch_grad_cam.utils.image import show_cam_on_image
from torchvision.models import resnet18

try to install: pip install pytorch-gradcam

The problem is solved with this commit. You can install the latest version of the package and try again.

Related

Tensorflow federated can't be imported on google collabs notebook

I wrote following codes on a new google collabs notebook:
!pip install --quiet --upgrade tensorflow-federated-nightly
import tensorflow as tf
import tensorflow_federated as tff
And I got these error messages while importing tensorflow_federeated:
/usr/local/lib/python3.7/dist-packages/keras/api/_v1/keras/experimental/__init__.py in <module>()
8 from keras.feature_column.sequence_feature_column import SequenceFeatures
9 from keras.layers.rnn.lstm_v1 import PeepholeLSTMCell
---> 10 from keras.optimizers.learning_rate_schedule import CosineDecay
11 from keras.optimizers.learning_rate_schedule import CosineDecayRestarts
12 from keras.premade_models.linear import LinearModel
ModuleNotFoundError: No module named 'keras.optimizers.learning_rate_schedule'; 'keras.optimizers' is not a package
These errors seem to be spawning from the modules installed on the colabs itself, instead of my code.
Any idea on what can be done to fix this?
Collab Defaults to 3.7 according to a similar problem But although the solution to upgrade to 3.9 did indeed upgrade to python 3.9, TFF still didn't work for me, even when I installed locally. So, find a different path.

ImportError: cannot import name '_print_elapsed_time'

Hi so I'm trying to use the make_pipeline module in sklearn. But when I try to import it with:
from sklearn.pipeline import make_pipeline
I get this error:
ImportError: cannot import name '_print_elapsed_time'
I've googled it but there seems to be no other posts about this. I tried reinstalling scikitlearn but I still get the same error :/ Anyone have any ideas?
It looks like this was a bug introduced into one of the newer versions of scikit-learn (I got this same issue in version 0.21.2).
I was able to fix this by downgrading to scikit-learn version 0.20.0
>> pip install scikit-learn==0.20.0

Cannot import Sklearn from sklearn.externals.joblib

I am a beginner and I just started with machine learning. I am trying to import classes like imputer from sklearn but i am unable to do it.
from sklearn.preprocessing import Imputer,LabelEncoder,OneHotEncoder,StandardScaler
ImportError: cannot import name 'version' from
'sklearn.externals.joblib'
(C:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\joblib__init__.py)
I had the same problem.
I have replaced
from sklearn.externals import joblib
with
import joblib
and it works fine in Python 3.7.2
I believe there was an update on Scikit-learn that render that import unusable.
I had my local installation to be version 0.20.3 and this import is pefectly working. But on my server I have installation 0.23.1 and this error pop up. Something must be chaging in the new version.
For my case, use import joblib fix the problem. In your case it seems more complicated. This sounds very much likeky to be caused if you have more than one Scikit-learn version installed on your system. You need to uninstall all of them and do a clean install of sklearn.
The problem sometimes happens due to the version. This may help:
If you has written like this
from sklearn.externals import joblib
Modify it as this:
import joblib
Try
python -m pip install sklearn --upgrade
and
python -m pip install joblib --upgrade
and then, use this :
import joblib
Good luck.
import joblib
This works for me. Actually I was having that kinda challenge

Missing scikit-learn packages

When I try to run
import sklearn.linear_model
I get an error
~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone1\lib\site-packages\sklearn\linear_model\least_angle.py in <module>
21 from .base import LinearModel
22 from ..base import RegressorMixin
---> 23 from ..utils import arrayfuncs, as_float_array, check_X_y, deprecated
24 from ..model_selection import check_cv
25 from ..exceptions import ConvergenceWarning
ImportError: DLL load failed: The specified module could not be found.
I did some digging, and it looks like I don't have the as_float_array package
ModuleNotFoundError: No module named 'sklearn.utils.as_float_array'
I tried reinstalling, but no change. What's going on?
This appears to be very specific to your IDE/environment. It will be easier to solve if you provide more details. You can try the following:
Are you able to run the following code?
import sklearn
print(sklearn.__version__)
Can you list the packages installed and see if sklearn is there?
pip3 list
Do you see the same problem in Anaconda alone, or when you run this in command line?
Edit: possible solution
This looks like an access issue.
If you are on Windows OS, remove Anaconda & re-install it in a common folder, instead of under admin controlled folders (for example C:\anaconda, instead of under C:\Program Files).
Launch a new terminal from Anaconda Navigator -> Environments, then run this code.
Usually a conda install solves the problem:
conda install -c anaconda scikit-learn
It happened to me, for numpy

How to import WordEmbeddingSimilarityIndex function from gensim module?

When i try to import WordEmbeddingSimilarityIndex, it's giving me the following error:
>> from gensim.models import WordEmbeddingSimilarityIndex
ImportError: cannot import name 'WordEmbeddingSimilarityIndex
The same issue occurs for SparseTermSimilarityMatrix function:
>> from gensim.similarities import SparseTermSimilarityMatrix
ImportError: cannot import name 'SparseTermSimilarityMatrix
Note: I have installed and imported gensim, gensim.models and gensim.similarities. But still it's giving me the ImportError while importing the above mentioned functions.
Can you tell me what I am doing wrong, please?
Fix is change "models" to "similarities"
from gensim.similarities import WordEmbeddingSimilarityIndex
it works in gensim 4.0.1
Try to check the version of gensim that you are using. Usually, the older versions of gensim cause this issue.
from gensim.models import WordEmbeddingSimilarityIndex
print(gensim.__version__)
if the gensim version is 3.6.x or older update it to 3.7.x or latest version by running the below command. Once you update gensim version should get rid of this issue.
pip install --upgrade gensim

Resources