Cannot find reference 'TextVectorization' in '__init__.py' - python

I'm using Pycharm 2021.2.3 with tensorflow 2.6.2 on ubuntu 18.04.6
When testing the Text classification tutorial from https://www.tensorflow.org/text/guide/word_embeddings
In this line :
from tensorflow.keras.layers import TextVectorization
I got the error:
Cannot find reference 'TextVectorization' in 'init.py'
But calling TextVectorization in my model is working. And if I use tf.keras.layers.TextVectorization, again no problem

This is a bug. I opened an issue on jetbrains
https://youtrack.jetbrains.com/issue/PY-51709

TextVectorization is found under tensorflow.keras.layers.experimental.preprocessing, not tensorflow.keras.layers

Related

module 'torch.optim' has no attribute 'NAdam'

nadam = torch.optim.NAdam(model.parameters())
This gives the error AttributeError: module 'torch.optim' has no attribute 'NAdam'. My PyTorch version is '1.9.1+cu102', the python version is 3.7.11. VS code does not even suggest the optimizer but the documentation clearly mentions the optimizer. I can import other optimizers like Adam
https://pytorch.org/docs/1.9.1/optim.html
From the official website, NAdam is not among the optimizers in pytorch v 1.9.1.
Try upgrading to v 1.10.0, and your code should work just fine.
According to documentation, NAdam is new in 1.10. It does not show in https://pytorch.org/docs/1.9.1/optim.html?highlight=optim#module-torch.optim
It is in https://pytorch.org/docs/1.10.0/optim.html?highlight=optim#module-torch.optim

"Cannot find reference" when import from Keras

Following this example to start https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/
# first neural network with keras tutorial
from numpy import loadtxt
from keras.models import Sequential
from keras.layers import Dense
Installed numpy and keras, numpy is ok, but there are red lines under "Sequential" and "Dense".
Here's the Error messages:
Cannot find reference 'Sequential' in 'models.py'
Cannot find reference 'Dense' in 'init.py'
Wonder how I can fix this? I had a look here but think it might be a different problem?
Also, on a completely different note, I can not install tensorflow for some reason? ...
As of October 2020 Tensorflow only supports the 64-bit version of Python and Tensorflow only supports Python 3.5 to 3.8.
Update your project in PyCharm to run Python 64-bit and this should solve your problem.

YOLOv3 ModuleNotFoundError: No module named 'tensorflow.python.keras.engine.base_layer_v1'

I need to train a model using YOLO. I am using the Kaggle kernel and I am training custom images.
When I execute the train module, I get this error.
ModuleNotFoundError: No module named 'tensorflow.python.keras.engine.base_layer_v1'
preinstalled is Tensorflow 2.+. I read somewhere that Yolov3 does not work with TensorFlow 2.+ so I installed Tensor 1.14.
I also tried using ImageAi and got exactly the same error.
Does anyone understand this basekayer_v1? Is it the tensorflow version that give the error?
Thanks
I found the solution
Well, it looks that I am doing things wrong or more difficult since no one encounter this error. I found the solution.
from keras.preprocessing import image
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D
from keras import backend as K
to:
from tensorflow.keras.preprocessing import image
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
from tensorflow.keras import backend as K
If you have the same problem.
YOLO files are outdated. They are said that they are not compatible with Tensorflow 1.14 but for me it worked. I needed to fork the git and edit the model.py. As shown above the important thing is add tensorflow.keras
I also needed to edit Change K.controlflowops.whileloop to tf.whileloop in the code or will give you an error.
I used Kaggle kernel. Using Tensorflow 2.0.2
It took me 4 days to solve this, now it is finally training. I hope it helps.

Can't import tensorflow.keras in VS Code

I'm running into problems using tensorflow 2 in VS Code. The code executes without a problem, the errors are just related to pylint in VS Code.
For example this import from tensorflow.keras.layers import Dense gives a warning "Unable to import 'tensorflow.keras.layers'pylint(import-error)". Importing tensorflow and using tf.keras.layers.Dense does not produce an error. I'm just using a global python environment (3.7.2) on Windows 10, tensorflow is installed via Pip.
The imports that were causing the issue for me:
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense
The way I resolved it:
from tensorflow import keras
from keras.models import Model
from keras.layers import Dense
My way to work with that: The problem is related to the custom import system in tf2 (see this issue). A work around for this is possible (Windows, Linux) which basically tricks VS Code to directly import tensorflow_core and don't use the custom lazy loader. If you just want to remove the red lines (as this is only an editor-problem), use
"python.linting.pylintArgs":
["--ignored-modules=tensorflow.keras"]
I solved it by pressing ctrl+shift+P in Visual Studio Code, searching Python: Select Interpreter, and choosing the main environment.
More detailed information can be found here.
I too faced the same issue. I solved it by installing keras as a new package and then I changed all packages name removing the prefix tensorflow.. So in your case after installing keras you should replace tensorflow.keras.layers with keras.layers
Instead of importing from tensorflow.keras import everything from "keras" solely. From one of the tensorflow versions until now there is a common error.
For instance:
Instead of
From tensorflow.keras import layers, models
Write this:
From keras import layers,models
Its just better to use pycharm instead of vscode. This issue does not exist in pycharm. However, if you are insistent on using vscode, then the import statements have to be changed as follows.
from tensorflow.python.keras import Sequential
from tensorflow.python.keras.layers import Dense

No module named 'tensorflow.python._impl

I want to run code for try neural network with python but
No module named 'tensorflow.python._impl
part of my code:
import tensorflow as tf
from tensorflow import keras
from tensorflow.python._impl import activations
I did all solutions that some sites said such as
- Uninstall and install package like tensorflow,..
also:
- Upgrade tensorflow
- Upgrade keras
but it doesn't solve yet. I have this error on co lab too.
please help me if you have any solution
thanks
from keras.layers.recurrent import ...
Official TensorFlow Support discourages use of tf.python.* as it is private and intended for development purposes only. While it may work in some cases, it will "break unannounced" in many others.
Instead, try importing tensorflow with the .python portion removed, e.g.:
from tensorflow._impl import activations

Categories