device_util not found in tensorflow - tensorflow

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

Related

How to overcome "No module named 'keras'" while importing tensoflow_hub

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

How to import tensorflow in google colab

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

ImportError: cannot import name 'VirtualDeviceConfiguration' from 'tensorflow.python.eager.context'

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

How to solve ImportError even Rasa_nlu and tensorflow are installed successfully

I faced the following error after installing Rasa_nlu and Tensorflow.
ImportError: Failed to import `tensorflow`. Please install `tensorflow`. For example with `pip install tensorflow`.
Before getting the above error message, I have successfully import the following packages as shown below.
from rasa_nlu.training_data import load_data
from rasa_nlu.config import RasaNLUModelConfig
from rasa_nlu.model import Trainer
from rasa_nlu import config
import tensorflow as tf
The following is the version of Anaconda3, Tensorflow, Rasa_nlu and python.
Anaconda-client: 1.6.14,
Anaconda-navigator: 1.8.7,
Anaconda-project: 0.8.2,
Python: 3.6,
Tensorflow: 1.8.0,
Could someone help me about me? Thank you so much.

Unable to import distributions module from Tensorflow (Dockerized)

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