I have codes like this
import tensorflow as tf
mapp = tf.nest.map_structure(lambda x : x.reshape([-1]+list(x.shape[2:]), data))
No problem happens when running this code, but in vscode editor, the resolved result for nest and map_structure is Incomplete. And autocomplete also fails for tensorflow.
Additionally, for all other tensorflow functions, it shows same error. The IntelliSense for tensorflow only have data type and Tensor class and Variable class, etc.
But for other modules like numpy, everything works fine. And if in Jupyter in the same python env, it works fine even for tensorflow.
So I think the problem should be in the vscode, but have no idea where it should be exactly.
Any idea about this problem is appreciated!
Version
vscode : 1.75.1
python : 3.8.10
tensorflow : 2.11
More Info
I checked the extension installed as
and I can show the resolve result for tensorflow and numpy as
I have tried many times and found a possible solution.
This may be because your Python Language Server is not defined. So Pylance was not enabled.
You can add the following codes to your settings.json to enable it:
"python.languageServer": "Pylance",
Related
I am using some code based on Tensorflow 1.x and I am using the latest version of TensorFlow (2.8).
I have run tf_upgrade_v2 (following these migration instructions) on the python file to generate a new compatible file.
However, this doesn't work with the line of code; from TensorFlow.contrib import training as contrib_training.
Getting the error ModuleNotFoundError: No module named 'tensorflow.contrib'
I understand that contrib has been deprecated, so the modules have been moved around. But I haven't been able to find where this training module has moved to or if it has been deleted. I have looked for information first on this document on the status of tf.contrib and after this spreadsheet on TF2.0 Symbols map and haven't found any information on the fate of this training module;
I have also tried looking around TensforFlow/tf.compat.v1 but with no success.
Of course uninstalling this version of TensorFlow and instead installing an earlier version is an option. But not an option that I am overly keen on.
I feel like I may be missing something fairly obvious here...
Thanks in advance!!
The reason behind this error - ModuleNotFoundError: No module named 'tensorflow.contrib' is, tf.contrib has been deprected to use in Tensorflow 2.x. You can use Tensorflow Addons or Tensorflow Slim in the pace of tf.contrib api.
Please check this link for more details.
When I was using jupyter in vscode, I found that it could not remember remember I had import tensorflow in the last block. like:
block1: import tensorflow as tf (success)
block2: print(tf.__version) (false -->"name 'tf' is not defined")
This problem is only for tensorflow. Vscode works well with other modules.
I am using Apple M1 max
Restart Jupyter kernel will lose all variables. After I restart it then only run print(tf.__version__) i get the same error as yours:
After restarting, you should run the previous code cell again to make the following code run successfully.
I tried running this command but i get erros that i dont have tenserflow 2.2 or higher. But I checked and I have the correct version of tenserflow. I also did pip3 install keras command
I know for a fact that all of the code is correct because it worked for my teacher the other day and nothing has changed. I just need to run his commands but i keep running into problems
I am doing this course following everything he does in a recorded video so there must be no issue there but for some reason it just doesn't work
just install tensorflow as requested in the last line of the error message: pip install tensorflow. It is needed as backend for Keras.
Also, since keras is part of tensorflow now, I recommend to write imports as from tensorflow.keras.[submodule name] import instead of from keras.[submodule name] import
When I try to run code using keras and numpy or keras and Matplotlib in one Jupyter notebook I always get the message: The kernel appears to have died. It will restart automatically.
When I run the code in two different notebooks it works perfectly fine. I have installed it using anaconda and I am using macOS. I would really appreciate an answer, everything else I've found and tried so far did not work. Thank you!
I have a very simple question. I recently had to format my pc and therefore I recreated my whole working environment. I'm using Anaconda (latest version) and I used conda to install tensorflow-gpu, keras..
The code, like before, is working fine but I'm seeing a lot of warnings about deprecations and I'm sure a lot of them are related to tf version 2.x but I'm using tf 1.14 (I printed it after importing tensorflow in my code and so I'm sure, moreover I never asked Anaconda to install any 2.x version)
For example:
W0813 19:25:46.491560 15288 nn_ops.py:4224] Large dropout rate: 0.75 (>0.5).
In TensorFlow 2.x, dropout() uses dropout rate instead of keep_prob.
Please ensure that this is intended.
W0813 19:36:22.136491 15288 deprecation_wrapper.py:119]
From C:\Users\-----\Anaconda3\envs\tensorflow_GPU\lib\site-packages\keras\callbacks.py:850:
The name tf.summary.merge_all is deprecated.
Please use tf.compat.v1.summary.merge_all instead.
Is this normal? Do I have to correct them or can I disable this types of warnings?
The purpose of these warning messages is to spread awareness of TensorFlow 2.0
Because in the long run TF 2.X is likely to be widely adopted.
This is normal and you can safely ignore these warnings by,
import logging, os
logging.disable(logging.WARNING)
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"