Tag Archives: tensorflow

Tensorflow error: module ‘tensorflow’ has no attribute ‘xxx’

____tz_zs

good tensorflow appears suddenly: can import the tensorflow package, but using any module under tensorflow will report a “nonexistence” error.

such as: using tf.variable to create a Variable also reports AttributeError: module ‘tensorflow’ has no attribute ‘Variable ‘.

because tensorflow becomes a module without any content (the reason why tensorflow becomes empty is unknown)

solution: uninstall tensorflow (based on the PIP uninstall tensorflow or PIP uninstall tensorflow-gpu you installed) and reinstall it (based on the PIP install tensorflow or PIP install tensorflow-gpu you installed)

ps: according to some discussion information found by Google, when tensorflow was installed under Windows, it also appeared that the tensorflow was empty, possibly because of the permission problem.

add:

Windows TensorFlow installation: http://blog.csdn.net/tz_zs/article/details/74779953

making similar discussion: https://github.com/tensorflow/tensorflow/issues/7285

FCOS No CUDA runtime is found, using CUDA_HOME=’/usr/local/cuda-10.0′

FCOS appears No CUDA runtime is found, using CUDA_HOME=’/usr/local/cuda-10.0′

  • appear below error </ li>
    • reason for the error </ li>
    • view version </ li>
    • solution (cuda10.0 and torch did not match the 1.2.0) </ li> </ ul>

    )

    appears with the following error

    AssertionError:
    The NVIDIA driver on your system is too old (found version 10000).
    Please update your GPU driver by downloading and installing a new
    version from the URL: http://www.nvidia.com/Download/index.aspx
    Alternatively, go to: https://pytorch.org to install
    a PyTorch version that has been compiled with your version
    of the CUDA driver.

    error cause

    cuda version does not match the torch version
    . On my machine, the pytorch version is too new, while the cuda version is too old to match.
    is usually the torch version that does not fit

    view version

    NVCC -v

    # or pip3 list
    PIP list

    cuda10.0 with torch 1.3.1 mismatch </ p>

    solution (cuda10.0 and torch 1.2.0 match only)

    uninstall the original torch1.3.1
    pip3 uninstall torch
    # or
    PIP uninstall torch

    reshipment torch1.2.0
    pip3 install torch 1.2.0 torchvision </ mark> 0.4.0 -f https://download.pytorch.org/whl/torch_stable.html
    PIP install torch 1.2.0 torchvision </ mark> 0.4.0 – f https://download.pytorch.org/whl/torch_stable.html

    after checking whether torch1.2.0 has been installed successfully,
    pip3 list
    # or
    PIP list

    the final version of the cuda with torch version match go to website check can
    see pytorch website https://pytorch.org/get-started/previous-versions/ to see such a </ p>

Problem solving module ‘ tensorflow.compat . V2 ‘has no attribute’ contrib ‘and importerror cannot import name’ auto ‘

Error:
The current version of tensorflow is 1.13.1 and 2.0.0b1 report errors module ‘tensorflow.compat.v2’ has no attribute ‘contrib’,

try to import tensorflow.compat.v1 as tf instead of import tensorflow as tf,

But ImportError cannot import name ‘auto’

Solution:

as shown in the figure below, refer to article 1 to point out that tf2.0 alpha began to remove tf.contrib and needed to be upgraded.

therefore, upgrade to tensorflow 2.1.0 using PIP install –upgrade tensorflow.

reference article:

1. https://stackoverflow.com/questions/55870127/module-tensorflow-has-no-attribute-contrib

Solve the problem of using in tensoft 2. X tf.contrib.slim No module named appears in the package: tensorflow.contrib problem

introduction

tensorflow2.x has been greatly changed over 1.x to make TensorFlow users more efficient. Where Tf.contrib was abandoned altogether is a major change of 2.x version, but import tensorflow.contrib.slim as Slim as a superior package, has been widely used in many previous versions. Most of the source code is still written based on the TensorFlow1.x version, which makes some modules that have been removed from the 2.x version unusable.

main problem

when running a import tensorflow. Contrib. Slim as slim

: ModuleNotFoundError: No module named 'tensorflow. Contrib false

solution

query existing solutions, most of the use of the reduced version of the method, if you want to use this method can go to the query.
because I don't want to use the method of reducing the version to solve, after searching on github to find out the information
link: tf.contrib.slim is not worked in tensorflow 2.0 what is the alternative for that?.

Tf - slim has a independent of tensorflow mirror to tf.com pat. V1 compatible mode is used, install the package can be

tf-slim is a lightweight library for defining, training, and evaluating complex models in TensorFlow. Tf-slim's components can be freely blended with the native TensorFlow and other frameworks.
here you can find information about Slim: link.

operation

use PIP to download tf-slim

in CMD

pip install --upgrade tf_slim

download:

note when using Slim library:

#import tensorflow.contrib.slim as slim
import tf_slim as slim

where the commented out part is the source code, modified no longer report an error.
(ps: the ability is limited, if there is an error, please point out.

FileNotFoundError: [Errno 2] No such file or directory: ‘./mnist_image_label/mnist_train_jpg_6000028

FileNotFoundError: [Errno 2] No such file or directory: ‘./mnist_image_label/mnist_train_jpg_6000028755_0.jpg ‘

error in reading file

in tensorflow

Traceback (most recent call last):
  File "Tensorflow/Test/9-26 mnist_train_ex1.py", line 43, in <module>
    x_train,y_train = generateds(train_path,train_txt)
  File "Tensorflow/Test/9-26 mnist_train_ex1.py", line 25, in generateds
    img = Image.open(img_path) #读入图片
  File "\envs\tf2.0-gpu\lib\site-packages\PIL\Image.py", line 2878, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: './mnist_image_label/mnist_train_jpg_6000028755_0.jpg'

locates to line 25

img = Image.open(img_path) #读入图片

error reading image
view path

train_path = './mnist_image_label/mnist_train_jpg_60000'

found is missing “\”

reflect on the foundation and summarize

here

here is what’s under the file, so backslash

I am a small white, welcome to communicate

ModuleNotFoundError: No module named ‘tensorflow.python’ And the pits encountered after installation

error
ModuleNotFoundError: No module named 'tensorflow.python'

after we installed tensorflow, we thought we had debuggable the environment and PIP install tensorflow, if

is entered in CMD

import tensorflow

(normally installed the GPU version tensorflow) :

but may be submitted to the above error, on the Internet a lot according to the results there is no use, 😂 is outrageous.
reason (personal summary) : the computer installed multiple python environment, not only the environment, but also anconda, etc., constitute the virtual environment, so you will encounter various problems when using the command conda to assemble the tensflow environment.
the solution: delete other environment, if you remove after the computer did not have the python environment, then reinstall it again, because I have more than one person has them around, “reshipment can solve the problem of ninety-nine percent”, but if pycharm with few words, I do not recommend to assemble anconda, unloading directly, in python’s official website to download the new version of python. After that, tensorFlow is assembled in the whole large Python environment; With the PIP command, there is little problem with reloading.

after installed, we can run the minist a piece of code: </ p>

from tensorflow.examples.tutorials.mnist import input_data

#加载数据集,参数为下载的路径,如果该路径下没有数据集的话,则会从网上自动下载。
#read_data_sets函数
mnist = input_data.read_data_sets("E:\\桌面\\datatest")
# 打印训练数据大小
print("Training data size:", mnist.train.num_examples)
# 打印验证集大小
print("Validating data size:", mnist.validation.num_examples)
# 打印测试集大小
print("Testing data size:", mnist.test.num_examples)
# 打印训练样例
print("Example training data", mnist.train.images[0])
# 打印训练样例的标签
print("Example training data label:", mnist.train.labels[0])

When

, ninety-nine percent of the time will error and remind:

ModuleNotFoundError: No module named 'tensorflow.tutorials'

We first enter the installation environment of tensorflow, and we can find the installation path

through python’s path method

import tensorflow as tf
print(tf.__path__)

after entering python environment, type the command and get the path, and then find the path of files
(about) the new version of the tensflow

enter the examples of the first file,
there should be no my red line mark.
portal
go here to download, then copy in the directory, if it is the old version, find the examples file, the effect is the same, after found on the Internet part of the introduction code may also have problems. Note that we must refer to pylab with

from matplotlib import pylab

so, when you’re done, you can run the following code.
1.

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data", one_hot=True)
print ( ' 输入数据:', mnist.train.images)
print ( ' 输入数据打shape :', mnist.train.images.shape)
from matplotlib import pylab
im = mnist.train.images[1]
im = im.reshape(-1 ,28)
pylab.imshow(im)
pylab.show()
  • note that our read_data_sets should never be interrupted when downloading data. If they are interrupted, they will report an error if they continue executing later. At this time, either change the path to download again, or find the original download path, delete it and run again.