I'm new to pytorch geometric, tried to install it to my computer but failed, so I'm trying to run the code on Google Colab instead. According to this previous question (which didn't help me and I'mnot sure its the same issue):
PyTorch Geometric CUDA installation issues on Google Colab
I did:
!pip install --upgrade torch-scatter
!pip install --upgrade torch-sparse
!pip install --upgrade torch-cluster
!pip install --upgrade torch-spline-conv
!pip install torch-geometric
!pip install torch-cluster==latest+cu101 -f https://s3.eu-central-1.amazonaws.com/pytorch-geometric.com/whl/torch-1.4.0.html
!pip install torch-scatter==latest+cu101 torch-sparse==latest+cu101 torch-spline-conv==latest+cu101 -f https://s3.eu-central-1.amazonaws.com/pytorch-geometric.com/whl/torch-1.4.0.html
they print:
Successfully installed torch-cluster-1.5.4
Successfully installed torch-scatter-2.0.4 torch-sparse-0.6.1 torch-spline-conv-1.2.0
However, when I try to run
import torch_geometric.datasets as datasets
I get:
RuntimeError: Detected that PyTorch and torch_sparse were compiled with different CUDA versions. PyTorch has CUDA version 10.1 and torch_sparse has CUDA version 0.0. Please reinstall the torch_sparse that matches your PyTorch install.
Any help would be greatly appretiated.
I came up with the following snippet that should work on Colab to install PyTorch Geometric and its dependencies:
https://gist.github.com/ameya98/b193856171d11d37ada46458f60e73e7
# Add this in a Google Colab cell to install the correct version of Pytorch Geometric.
import torch
def format_pytorch_version(version):
return version.split('+')[0]
TORCH_version = torch.__version__
TORCH = format_pytorch_version(TORCH_version)
def format_cuda_version(version):
return 'cu' + version.replace('.', '')
CUDA_version = torch.version.cuda
CUDA = format_cuda_version(CUDA_version)
!pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-geometric
I have updated the answer from that previous question. Hope this works now. Also don't forget to select GPU Runtime.
!pip install torch-geometric \
torch-sparse==latest+cu101 \
torch-scatter==latest+cu101 \
torch-cluster==latest+cu101 \
-f https://pytorch-geometric.com/whl/torch-1.4.0.html
I'm trying to run following code:
input_img = Input((height, width, 1), name='img')
model = get_unet(input_img, n_filters=16, dropout=0.05, batchnorm=True)
model.compile(optimizer=Adam(), loss="binary_crossentropy", metrics=["accuracy"])
But I'm getting "AttributeError: module 'tensorflow' has no attribute 'placeholder'".
Everywhere it is recommended to use
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
But I still keep getting such error.
If you are using Anaconda distribution the try to reinstall TensorFlow by using following commands
Remove tenserflow
conda remove tensorflow-gpu tensorflow tensorflow-base
re-installed tensorflow
conda install -c anaconda tensorflow
Reference:- https://anaconda.org/anaconda/tensorflow
If your code needs to run on GPU it is better to install tensorflow-gpu by using
conda install -c anaconda tensorflow-gpu
Reference:- https://anaconda.org/anaconda/tensorflow-gpu
Also if your project uses keras(Or distribution has keras(ex:-Colab)) then you can use tensorflow insides on keras by using "tensorflow.keras"
Ex:-
from keras.models import Sequential
Change to
from tensorflow.keras.models import Sequential
Python version of Colab has updated .
Add this
!pip uninstall keras-nightly
!pip install h5py==2.10.0
!pip install q keras==2.1.6
%tensorflow_version 1.x
PyTorch v1.0.0 stable was released on 8 December 2018 after being announced 7 months earlier.
I want get a version optimised for the hardware that my IPython kernel is running on.
How do I get this version on Google Colab?
try the following code snippet (it works equally for the runtime with or without gpu)
!pip install -q torch==1.0.0 torchvision
to check the version
import torch
print(torch.__version__)
here you have the version 1.0.0
UPDATE
!pip install torch
Works fine now, as the most stable version is 1.0.0
With version 1.0.0, PyTorch changed the download URL format from:
https://download.pytorch.org/whl/cu92/torch-1.0.0-cp36-cp36m-linux_x86_64.whl
to
https://download.pytorch.org/whl/cu90/torch-1.0.0-cp36-cp36m-linux_x86_64.whl
(The change is in the CUDA version part, where cu92 changes to cu90.)
To programmatically generate that URL, I used the following code:
from os.path import exists
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*\.\([0-9]*\)\.\([0-9]*\)$/cu\10/'
accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'
torch_url=f"http://download.pytorch.org/whl/{accelerator}/torch-{version}-{platform}-linux_x86_64.whl"
version='1.0.0'
!pip install -U {torch_url} torchvision
You can then change the version variable as desired as newer versions are released.
You can now just
import torch
No need for additional installation.
For version 1.1.0, this works
!pip install -q torch==1.1.0 torchvision
It worked for me you can try
!pip install torch
!pip install torchvision
!pip install mxnet-cu101
Here is a code to install pytorch. You can change it to whatever version you want.
!pip3 install http://download.pytorch.org/whl/cu92/torch-1.0.0-cp36-cp36m-linux_x86_64.whl
So basically, I am fairly new to programming and using python. I am trying to build an ANN model for which I have to use Tensor flow, Theano and Keras library. I have Anaconda 4.4.1 with Python 3.5.2 on Windows 10 x64 and I have installed these libraries by following method.
Create a new environment with Anaconda and Python 3.5:
conda create -n tensorflow python=3.5 anaconda
Activate the environment:
activate tensorflow
After this you can install Theano, TensorFlow and Keras:
conda install theano,
conda install mingw libpython,
pip install tensorflow,
pip install keras,
Update the packages:
conda update --all
All these packages are installed correctly and I have check them with conda list.
However, when I am trying to import any of these 3 libraries (i.e. Tensor flow, Theano and Keras), it is giving me the following error:
Traceback (most recent call last):
File "<ipython-input-3-c74e2bd4ca71>", line 1, in <module>
import keras
ImportError: No module named 'keras'
Hi I have an solution try this if you are using Anaconda-Navigator
go to Anaconda Environment and search keras package and then install.
after install just type import keras in shell its working.
Have you tried using keras documentation
Install Keras from PyPI (recommended):
Note: These installation steps assume that you are on a Linux or Mac environment. If you are on Windows, you will need to remove sudo to run the commands below.
sudo pip install keras
If you are using a virtualenv, you may want to avoid using sudo:
pip install keras
from: https://keras.io/
Now you need to have Tensorflow installed and then write, for example:
import tensorflow as tf
...
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Dense(12, input_dim=8, activation='relu'))
model.add(tf.keras.layers.Dense(8, activation='relu'))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
...
Works for Tensorflow version: 2.4.1.
Or just type:
import tensorflow as tf
from tensorflow import keras
...
Try
import sys
print(sys.path)
and see if your anaconda site-packages folder is in the list.
It should be something like WHERE_YOU_INSTALLED_ANACONDA\anaconda3\envs\ENVIRONMENT_NAME\lib\python3.5\site-packages
If the path setting is correct, then try listing the folder content, and see if Keras, TensorFlow and Theano are in this folder.
I ran into a very similar issue after switching computers and downloading the latest Anaconda, which comes with python 3.6. It was no problem to install python 3.5 in its own environment, and install keras to this environment, but import keraskept failing.
My inelegant solution (assuming you've already got tensorflow/theano/cntk working fine in your global environment)?
Move the keras folder installed to Anaconda3/envs//Lib/site-packages/keras to Anaconda3/Lib/site-packages/keras. Now import keras gives a depreciation warning when run from a jupyter notebook launched via start menu, but it does work, and correctly returns the backend keras is running on.
I spent the whole day to install Keras, tried all the available methods online, almost dying. But I still cannot import keras.
(1). After using conda install or pip install, and delete the "1 > null > 2&1" ... I activated in conda prompt by activating tensorflow_cpu, it doesn't work anyway.
(2). Then checked the keras, and print os.path(), no virtual environment inside. I got so braindead, just copied all the keras data file from virtual environment env, and put into the "C:\Users\Administrator\Anaconda3\Lib\site-packages".
(3). Now, tensorflow and keras work well.
Click Update Index and then try searching for Keras again.
I have the same problem with:
conda 4.13.0
tensorflow 2.6.0
Note: We should not have to install Keras separately, as it ships with Tensorflow, starting with Tensorflow 2.0.
Symptoms:
Keras import (from tensorflow import keras) does not return an error, BUT any further reference to Keras does throw "ModuleNotFoundError", e.g. the following statements fail:
print(keras.__version__)
from keras import Sequential
I still don't have a direct solution for this, this is more of a workaround, but here it is:
Import ANY class from Keras JUST ONCE using full top-down import syntax AND instantiate it
Import Keras (now "for real")
E.g.:
from tensorflow.keras.layers import Dense
layer = Dense(10)
from tensorflow import keras
Now the following statements should work:
print(keras.__version__)
model = keras.models.Sequential()
This looks like some sort of lazy module loading gone wrong.
A direct and simple way to fix it is as below,
#uninstall keras and tensorflow
pip uninstall keras
pip uninstall tensorflow
#Now install keras and tensorflow for required version with dependencies.
pip install keras==2.2.4
pip install tensorflow==1.13.1
Always make sure that you install right version of tensorflow which supports that keras version as well, else you may end up in trouble again. By the way , the above fix worked for me.
I solved this problem by running one of the following in the terminal according to anaconda website.
To install this package (keras) with conda run one of the following:
conda install -c conda-forge keras conda install -c
conda-forge/label/broken keras conda install -c
conda-forge/label/cf201901 keras conda install -c
conda-forge/label/cf202003 keras
If you never use conda before you can check anaconda.
A direct and simple way to fix it is as below, #uninstall keras and tensorflow
py -3 -m pip uninstall keras
py -3 -m pip uninstall tensorflow
#Now install keras and tensorflow for required version with dependencies.
py -3 -m pip install keras
py -3 -m pip install tensorflow
the above fix worked for me.
If you are sure that you ran pip install keras at the command line, ensure that you use the small letter 'k' instead of the Capital Alphabet. I had a similar error message.
These are some simple steps to install 'keras' simply using the Anaconda Navigator:
Launch Anaconda Navigator. Go to the Environments tab.
Select ‘Not installed’, and type in ‘tensorflow’.
Then, tick ‘tensorflow’ and do the same for ‘keras’.
Click on ‘Apply’. The pop-up window will appear, go ahead and apply.
This may take several minutes.
Done.
This tutorial will guide you more graphically: https://www.freecodecamp.org/news/install-tensorflow-and-keras-using-anaconda-navigator-without-command-line/
Remember to launch spyder in the environment or activate it in line command (conda activate [my_env]. afater that, execute your script python.
Try to import keras library from its reference parent which means import tensorflow.keras
When I save weights during training my CNN model using keras, it says ImportError:'save_weights' requires h5py, but I have already installed h5py.
I would greatly appreciate if someone could explain how to fix this issue.
Just install necessary packages
sudo apt-get install libhdf5-dev
pip install h5py
If you are using windows and python IDE, open cmd and input following commands:
pip install h5py
pip install cython
I hope it helps.
I was getting the same error as you.
I installed all the requirements listed here: https://github.com/fchollet/keras/issues/3426
Finally just needed to reboot and it started working.
As suggested by others:
pip install h5py
Note that this may not immediately resolve the issue in your active session and you may need to reload keras.models either through the following commands or by just creating a new session/re-opening your jupyter notebook.
In Python3:
from importlib import reload
reload(keras.models)
In Python2:
use importlib.import_module instead. See docs for a reference.
These additional steps may be necessary because of the try/except ImportError in keras sourcecode that assigns h5py = None when it's unable to locate it the first time it's executed.
In my case, re-installing did the trick:
pip uninstall -y cython h5py
pip install cython h5py
(Windows 10, Conda, Keras 2.4.3)
I think you may miss this
from keras.applications import imagenet_utils
I got the same problem even though I have imported the h5py.
It is the load error with the keras. It has to be reloaded.
import keras
from importlib import reload
reload(keras.models)
It has worked for me.
h5py==2.10.0 works well with TF >= 2.1 so try 'pip install h5py==2.10.0'
Have you tried directly installing h5py? http://docs.h5py.org/en/latest/build.html
Try running:
pip install h5py
or
sudo apt-get install libhdf5