Import Error of TensorFlow in Visual Studio Code - python

I work on the python code in VS Code for image processing and i need to use tensorflow. When I want to import tensorflow i get this error:
import tensorflow as tf
E0401:Unable to import 'tensorflow'
I have read ImportError: No module named tensorflow for Visual Studio Code but it is used for working with GPU but I only want to work with CPU.
How can I fix it?
Thanks in advance.

You should create an environment for your python project.
After that, you should install tensorflow with pip.

Related

I imported tensorflow as tf in notebook and run it successfully, but when I used tf.__version__ it says NameError: name 'tf' is not defined. Help me

Image here The first block ran without any errors. but second says name error tf not defined even though i have imported tensorflow as tf.
Yes, simply
import tensorflow as tf
print(tf.__version__)
Additionally, check this is installed.
Open the CMD in the administrator mode and install the libraries using pip install
pip show to check the path where it is installed.
Import the path using the following code:
import sys
sys.path.append('c:/users/admin/appdata/roaming/python/python39/site-packages')
sys.path.append('c:/python/python39/lib/site-packages')
The path will vary as in step 2.
I would suggest rolling tensorflow back to a previous stable version, in this case. It might be a bug with the current version.

which python and tensorflow version is used to train DeepLab v3+ using tensorflow api?

I have been getting multiple errors which are due to conflicts in the TensorFlow version installed in my system and the version used to write the code in Tensorflow API.
I am using python 3.6.7 and Tensorflow 2.0 to get started with the code https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/installation.md
But I am getting several errors :
flags = tf.app.flags
AttributeError: module 'tensorflow' has no attribute 'app.
As I am using 2.0 , I replaced tf.app.flags with tf.compat.v1.flags.
from tensorflow.contrib import slim as contrib_slim
ModuleNotFoundError: No module named 'tensorflow.contrib'
I am not able to solve the second one.
Can I get help to know which python and tensorflow version should be used to run DeepLab v3+?
You should use the Tensorflow version 1.x to run the DeepLabV3+ model because it uses a session to run and also the slim library which is based on the TensorFlow 1.x. And so your two problems can be solved as:
Do not need to replace tf.app.flags with tf.compat.v1.flags.
To run DeepLabV3+ model, you need to put deeplab and slim folder in a folder (deeplab_slim),
and export them by running following export commands from this parent folder (deeplab_slim):
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/deeplab

tensorflow.keras like imports show warnings in PyCharm, work well on command line

I get this error when I import modules from TensorFlow in PyCharm.
Cannot find reference 'keras' in 'init.py'
But when I use the tensorflow.python.keras prefix, the warning is not shown. Also, in the command line, no such warning is shown.
>> from tensorflow.keras import activations
>> # No errors!
How can I fix that warning in PyCharm and freely use tensorflow.keras and not tensorflow.python.keras? I'm using Windows 10, TF version 1.12.0 installed using Anaconda and PyCharm 2018.2.5.
After tensorflow gobbled keras, there were problem with tf.keras imports on IDEs although the code works.This was then raised an as issue (Issue #26502)
It seems that there is no import command for keras module in __init_.py of tensorflow package.
When I added from tensorflow.python import keras to __init__.py manually, everything work well.
Maybe there are some problem for package importing after keras was moved from _api to python.
As of tensorflow 2.0, even from tensorflow.python import keras wouldn't work: basically there is no way of making PyCharm / IDEA help you with syntax. However, this issue is fixed in IDEA 2019.3+ (currently in EAP, so should be in PyCharm EAP)

example_parser_configuration_pb2 import issue for tensorflow

Using Python 2.7 (miniconda) and trying to run below example, but it is said Unresolved reference to example_parser_configuration_pb2, does anyone have any solutions?
BTW, my machine is configured with tensorflow and I can run some tensorflow examples, so tensorflow basic configuration should be ok.
from tensorflow.core.example import example_parser_configuration_pb2
https://github.com/tensorflow/tensorflow/blob/754048a0453a04a761e112ae5d99c149eb9910dd/tensorflow/python/util/example_parser_configuration_test.py#L70
regards,
Lin

Failure to import sknn.mlp / Theano

I'm trying to use scikit-learn's neural network module in iPython... running Python 3.5 on a Win10, 64-bit machine.
When I try to import from sknn.mlp import Classifier, Layer , I get back the following AttributeError: module 'theano' has no attribute 'gof' ...
The command line highlighted for the error is class DisconnectedType(theano.gof.type.Type), within theano\gradient.py
Theano version is 0.8.2, everything installed via pip.
Any lights on what may be causing this and how to fix it?
Apparently it was caused by some issue with Visual Studio. The import worked when I reinstalled VS and restarted the computer.
Thanks #super_cr7 for the prompt reply!

Categories

Resources