Tutorial tf-nightly not woring - tensorflow

I am pretty new to tensorflow and right now I'm following the tutorials on their website to learn more about it. While going through the text classification one, whenever I get to step that wants me to do:
**batch_size = 32
seed = 42
raw_train_ds = tf.keras.preprocessing.text_dataset_from_directory(
'aclImdb/train',
batch_size=batch_size,
validation_split=0.2,
subset='training',
seed=seed)**
I get an error saying AttributeError: module 'tensorflow.keras.preprocessing' has no attribute 'text_dataset_from_directory'. I looked online and it seems that the problem is that tf-nightly isn't installed. But I already installed tf-nightly on my anaconda prompt. Is there another issue I'm missing?
Thank you

I suspect that the package named keras-preprocessing is missing in Anaconda in your Machine.
You could install it by running the below command in the cell of Jupyter Notebook,
!pip install keras_preprocessing
As I could successfully execute the code in my Jupyter Notebook, I will share the packages which I have, that may be useful to you in executing Tensorflow Code.
Please find the screenshots below:

Related

module 'tensorflow' has no attribute 'Session', sparkdl errors

I am trying to use deep learning in pyspark but it's not working.
here is my code :
featurizer = DeepImageFeaturizer(inputCol="image",
outputCol="features",
modelName="InceptionV3")
lr = LogisticRegression(maxIter=5, regParam=0.03,
elasticNetParam=0.5, labelCol="label")
sparkdn = Pipeline(stages=[featurizer, lr])
spark_model = sparkdn.fit(train)
The last part of The error:
File ~/anaconda3/lib/python3.9/site-packages/sparkdl/transformers/keras_applications.py:45, in KerasApplicationModel.getModelData(self, featurize)
44 def getModelData(self, featurize):
---> 45 sess = tf.Session()
46 with sess.as_default():
47 K.set_learning_phase(0)
AttributeError: module 'tensorflow' has no attribute 'Session'
I tried to uninstall and install tf.
also I am running pyspark with deep-learning package:
pyspark --packages databricks:spark-deep-learning:0.1.0-spark2.1-s_2.11
Looks like you are trying to use the DeepImageFeaturizer transformer from the spark-deep-learning package. This error usually occurs if you have an old version of TensorFlow installed on your system, or if your using a version of TensorFlow that is not compatible with the spark-deep-learning package.
Try the following:
Uninstall the current version of TensorFlow using pip uninstall tensorflow.
Then install the latest version of TensorFlow: pip install tensorflow.
Make sure that the version of TensorFlow that you are using is compatible with the spark-deep-learning package. According to the documentation it requires TensorFlow 1.6 or later.
Try setting the environment variable TF_CPP_MIN_LOG_LEVEL to 3 before running your code. This can help suppress some TensorFlow warnings and errors.

Running Train a GPT-2 (or GPT Neo) Text-Generating Model w/ GPU on Colab

When I start "Running Train a GPT-2 (or GPT Neo) Text-Generating Model w/ GPU on Colab" in my Colab, following error comes up:
ERROR: tensorflow 2.5.0 has requirement tensorboard~=2.5, but you'll
have tensorboard 2.4.1 which is incompatible. ERROR: pytorch-lightning
1.3.8 has requirement PyYAML<=5.4.1,>=5.1, but you'll have pyyaml 3.13 which is incompatible.
What to do? Is it because of my Mac, or do I need to upgrade my Colab account would that help?
The problem comes from the default packages installed in the Colab environment. I does not depend on the platform you are using to access Colab or on the type of your subscription.
You have to upgrade the Python packages using pip.
In general you can run shell commands like pip in Colab prepending a ! character,
so in your case the following lines should be sufficient to fix the problem
!pip install tensorboard==2.5
!pip install pyyaml==5.4.1
If you need to run more shell commands, you can use more user-friedly methods (see the answers to this question).

Jupyter Notebook kernel dies when importing tensorflow 1.5.0

Jupyter Notebook kernel dies when importing tensorflow 1.5.0
I have read a lot of posts relating to this but they have all had higher version numbers of tensorflow and have solved it by downgrading to 1.5.0. I also had higher version number and followed the advice to downgrade but I still have the problem.
Does anyone know what to try next?
pip install h5py==2.8.0
worked for me
When trying using the command prompt I got an error message not related to the tensorflow issue (I think);
"Warning! HDF5 library version mismatched error"
The key information from that message body was "Headers are 1.10.1, library is 1.10.2" so I downgraded hdf5 library by "conda install -c anaconda hdf5=1.10.1" and now the error message is gone and the kernel does not die when importing tensorflow.
I got similar problems, any tensorflow or tensorflow related packages (e.g. keras) made my kernel to die when loading, from any interface (jupyter, spyder, console....)
For those having this kind of problems, try running python from the console with verbose mode (python -v) then import tensorflow and look for errors.
I spot errors related to h5py, similar to the reply of #DBSE. I just upgraded the h5py package then everything was solved !
If you are using a conda environment, then the easiest method for fixing this issue is to just create a new environment and install tensorflow with just a single command. I had the same issue, I have tried a lot on most of the version of python and tensorflow. But at the last I have successfully configured it with just a single steps.
Run this command for installing GPU version
conda create --name tf_gpu tensorflow-gpu
The above line of code will automatically install that version of python and tf which is comaptible with your GPU or CPU.
For CPU, Run this command
conda create --name tf_env tensorflow
Both of these command work 100 % with my system for GPU and CPU access and will download the latest version which are compatible with system. It will resolved/fixed "Illegal Instruction (code dumps)" error.
pip install h5py==3.1.0
This is the most updated version which worked for me.
Try using import numpy before Keras and Tensorflow.

How to connect tensoflow to jupyter notebook?

I have installed Anaconda with jupyter notebook in /home/serg/anaconda/bin and installed tensoflow in ./.local/lib/python3.5/site-packages/tensorflow. My operation system is Ubuntu 16.04.
Is it possible to use tensorflow in jupyter notebook via changing some configuration in anaconda or jupyter?
P.S.: I know it is possible for most python IDE, but I need to do it with jupyter notebook in anaconda.
Looks like you may have installed stuff in the wrong order.
I run TensorFlow in Jupyter notebook all the time, I don't get your issue? If you have installed Anaconda and it is active eg when you type python, you get the Anaconda version of python, you just install TensorFlow with Pip (following instructions at TF.. ) and the fire up jupyter notebook do your imports including TF and you should be off and going, nothing special required. If you did it in the wrong order, eg TF then Anaconda just make sure that Anaconda is your default interpeter (as above) and re-install TF with pip. If that does not seem to fix whatever issue you are having, post more info...
post your notebook info that tries to import TF?
I understood my problem: just used anaconda promts and installed tensoflow right here. Then I run jupyter notebook in anaconda promts and imported tensorflow.

Getting ImportError while importing keras

I have followed every step for installing keras but whenever I am trying to import keras it gives me an error No module named tensorflow. But I have already installed tensorflow.
I have two questions-
1. How can I solve this particular ImportError?
2. If possible can anyone give me a detailed step by step instruction on installing theano, tensorflow and keras? Please don't give any links to install keras because i have tried them all but they keep giving some kind of error or problem.
If possible please take a look at my other question since they are related No module named keras
Thank You
Try sudo -H python -m pip install --upgrade --force-reinstall tensorflow