Google Colab seems throwing the below error while trying to import Tensorflow, while it was working okey couple of weeks ago
%tensorflow_version 1.x
import sys
import codecs
import tensorflow as tf
from tqdm import tqdm
from chardet import detect
from keras_radam import RAdam
from keras import backend as K
from keras_bert import load_trained_model_from_checkpoint
import os
import numpy as np
import pandas as pd
/usr/local/lib/python3.6/dist-packages/keras/__init__.py in <module>()
4 except ImportError:
5 raise ImportError(
----> 6 'Keras requires TensorFlow 2.2 or higher. '
7 'Install TensorFlow via `pip install tensorflow`')
8
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
NOTE : am running on TPU and alreadt tried !pip install tensorflow but reuirements are satisfaied
This should suffice i feel
%tensorflow_version 2.x
import tensorflow as tf
This has always worked for me in Google Colab. I think the issue is that you are giving %tensorflow_version as 1.x please try changing that to 2.x
I had to re-order my imports like below and used keras version 2.3.0
%tensorflow_version 1.x
import sys
import codecs
import tensorflow as tf
!pip install keras-bert
!pip install keras-rectified-adam
!pip install keras==2.3.0
from tqdm import tqdm
from chardet import detect
from keras_radam import RAdam
from keras import backend as K
from keras_bert import load_trained_model_from_checkpoint
import os
import numpy as np
import pandas as pd
Related
I am using Anaconda and Jupyter Notebook. I need a tensorflow_hub to import the ResNet model, however, I get the error No module named Keras. I've installed keras and tensorflow_hub in Anaconda. I have no issues when I am using keras.
This "AlreadyExistsError: Another metric with the same name already exists." error shows up when you have a mismatch version of TensorFlow and Keras installed in your system.
To verify this, please run below code in jupyter notebook:
import tensorflow as tf
print(tf.__version__)
import keras
print(keras.__version__)
You can resolve this error by upgrading the TensorFlow to the latest version as this error has been resolved in the latest TF releases - 2.7, 2.8:
!pip install --upgrade tensorflow
and import Keras from TensorFlow like this:
from tensorflow import keras
Now you can install and import tensorflow_hub using the below code without any error:
!pip install tensorflow_hub
import tensorflow_hub
I want to use keras with the code shown below:
from sklearn.model_selection import train_test_split
from keras.models import Sequential
df = DataReader('AAPL', data_source='yahoo', start='2012-01-01', end=datetime.now())
but I keep getting the error:
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow
I have both keras 2.4.3 and tensorflow 2.2.0 installed in anaconda environment. I uninstalled and installed jupiter notebook but it didn't help.
From comments
Solved the problem by simply installing different versions of keras
(2.3.1 instead of 2.4.3) and tensorflow (2.0.0 instead of 2.2.0). Keras are integrated with Tensorflow from 2.3 onwards, you can upgrade tensorflow to latest version and use module tf.keras (paraphrased from Vivi and jakub)
To run code in TF 2.4 is as shown below
from sklearn.model_selection import train_test_split
from tensorflow.keras import Sequential
df = DataReader('AAPL', data_source='yahoo', start='2012-01-01', end=datetime.now())
Getting import error while trying to download fashion_mnist data
Below is the script that I used in spyder.
from tensorflow.keras.datasets import fashion_mnist
Tensorflow version
Name: tensorflow
Version: 2.1.0
I'm trying to import device_util using:
from tensorflow.python.distribute import device_util
However device_util isn't found. The version is tensorflow-gpu 1.12.0.
It has been moved recently.
Try under training for release 1.12.0:
from tensorflow.python.training import device_util
Source code: https://github.com/tensorflow/tensorflow/blob/v1.12.0/tensorflow/python/training/device_util.py
I'm running the official TF docker repo using the Jupyter UI on localhost. It seems that TF is working in general, as I am able to import it, but when trying to import the distributions module I get an error:
print tf.__version__
import tf.distributions as dist
1.8.0
ImportErrorTraceback (most recent call last)
<ipython-input-3-4d440943cb46> in <module>()
1 print tf.__version__
----> 2 import tf.distributions as dist
ImportError: No module named tf.distributions
Try this
import tensorflow as tf
from tensorflow import distributions as dist
I don't think you can use import aliases for other import statements in python. I'm not too sure about this, but I think that's the problem.
FYI, I tested this on Python 3.5.2 and Tensorflow 1.8.0