Tensorflow TypeError: expected bytes, Descriptor found - tensorflow

I've been following this tutorial for recognising an object using machine learning:
https://www.youtube.com/watch?v=Rgpfk6eYxJA
I've followed all the instructions on what to install and how, including those in this related tutorial:
https://www.youtube.com/watch?v=RplXYjxgZbw
I tried both with their version and the newest available versions of the software. With the exception that I create the virtual environment like this:
conda create -n tensorflow1 pip python=3.6
Because the tensorflow module isn't yet compatible with python 3.7.
After I install all the packages needed, also described here:
https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10
Under 2d. Set up new Anaconda virtual environment
and go through the code in the video, I run into a error when I run
python generate_tfrecord.py --csv_input=images\train_labels.csv --image_dir=images\train --output_path=train.record
which is working in the video at 19:35.
The error is
2019-12-11 10:13:43.410540: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
Traceback (most recent call last):
File "generate_tfrecord.py", line 17, in <module>
import tensorflow as tf
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
from tensorflow_core import *
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 947, in _find_and_load_unlocked
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\Anaconda\envs\tensorflow1\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow_core\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow_core\core\framework\graph_pb2.py", line 16, in <module>
from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow_core\core\framework\node_def_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow_core\core\framework\attr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow_core\core\framework\tensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow_core\core\framework\resource_handle_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "C:\Anaconda\envs\tensorflow1\lib\site-packages\tensorflow_core\core\framework\tensor_shape_pb2.py", line 112, in <module>
'__module__' : 'tensorflow.core.framework.tensor_shape_pb2'
TypeError: expected bytes, Descriptor found
This problem is the same that appears in the jupyter kernel when I run the imports that appear in the video at 14:25
How do I fix the
TypeError: expected bytes, Descriptor found
Error?
And what's with
Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
That also appears?
I can also share this with you, in the second tutorial, the one just about installing tensorflow-gpu library, after I create an account for cuDNN and download it as inscribed, I only get a cudnn64_7.dll file in C:\cuda\bin which is in my system path environment variable, just as are
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp and
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\extras\CUPTI\lib64,
as instructed in the tutorial. As you can see, I have version 10.1 of Cuda and cuDNN and the paths are a bit different. The GPU Driver is also updated.
P.S. in the tensorflow installing tutorial, the test code doesn't work either.
This is all the information I think I have to offer.
I've been trying to solve this problem for 4-5 days at this point (and this is not my first video I watch to get a .record file for an image recognition neural network)
and the solutions for this particular problem offered in TypeError: expected bytes, Descriptor found or any other place on stackoverflow are not useful.
What should I do?
P.S. The tensorflow-gpu version I have is 2.0.0, and it might not be compatible with Cuda and cuDNN. It might be why I only have a cudnn64_7.dll file and not a cudart64_100.dll file. If no one has other solutions, I'll just install tensorflow 1.5 and try the software again.
If someone has another solution however, by all means, post it. I'll post a reply if it works. I'll edit this if it doesn't.

I've followed a different tutorial, however came across the same errors.
In case anyone is still wondering, I've fixed it by updating the tensorflow version from 1.5 originally to 1.15
pip install --ignore-installed --upgrade tensorflow-gpu==1.15.0
This is the official issue where I got the idea from.
As for the second part,
Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
This is an issue with the CUDA drivers. In short, there's compatibility issue between the tensorflow and your GPU. In most cases, don't worry too much, since it will default to using your CPU over GPU for training of a model. In case you really want to use the GPU (for better performance etc) check if it's supported. You can check similarly asked question, or from an official source.
Alternatively, since you've installed CUDA 10.1, as per official documentation, you'll need to upgrade tensorflow 2.1.0 or above to make it work.
Personally, I had to opt to using tensorflow 1.15 over 2.2.0 and installing CUDA 9.0 to make everything run. However, I'm working on a laptop with a mobile 1050 GPU, and no matter what, I couldn't get it to run otherwise.

Related

How to fix error: Cannot register 2 metrics with the same name: /tensorflow/api/keras/optimizers

When I am trying to run a Python code for deep learning utilizing the TensorFlow library, I am getting the following error:
2021-10-24 10:07:13.619481: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-10-24 10:07:13.619752: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-10-24 10:07:18.797570: E tensorflow/core/lib/monitoring/collection_registry.cc:77] `Cannot register 2 metrics with the same name: /tensorflow/api/keras/optimizers`
Traceback (most recent call last):
File "C:\Users\Admin\Downloads\Compressed\Face-Mask-Detection-master\detect_mask_image.py", line 5, in <module>
from tensorflow.keras.applications.mobilenet_v2 import preprocess_input
File "C:\Python39\lib\site-packages\keras\api\_v2\keras\__init__.py", line 8, in <module>
from keras import __version__
File "C:\Python39\lib\site-packages\keras\__init__.py", line 25, in <module>
from keras import models
File "C:\Python39\lib\site-packages\keras\models.py", line 20, in <module>
from keras import metrics as metrics_module
File "C:\Python39\lib\site-packages\keras\metrics.py", line 26, in <module>
from keras import activations
File "C:\Python39\lib\site-packages\keras\activations.py", line 20, in <module>
from keras.layers import advanced_activations
File "C:\Python39\lib\site-packages\keras\layers\__init__.py", line 23, in <module>
from keras.engine.input_layer import Input
File "C:\Python39\lib\site-packages\keras\engine\input_layer.py", line 21, in <module>
from keras.engine import base_layer
File "C:\Python39\lib\site-packages\keras\engine\base_layer.py", line 43, in <module>
from keras.mixed_precision import loss_scale_optimizer
File "C:\Python39\lib\site-packages\keras\mixed_precision\loss_scale_optimizer.py", line 18, in <module>
from keras import optimizers
File "C:\Python39\lib\site-packages\keras\optimizers.py", line 26, in <module>
from keras.optimizer_v2 import adadelta as adadelta_v2
File "C:\Python39\lib\site-packages\keras\optimizer_v2\adadelta.py", line 22, in <module>
from keras.optimizer_v2 import optimizer_v2
File "C:\Python39\lib\site-packages\keras\optimizer_v2\optimizer_v2.py", line 36, in <module>
keras_optimizers_gauge = tf.__internal__.monitoring.BoolGauge(
File "C:\Python39\lib\site-packages\tensorflow\python\eager\monitoring.py", line 360, in __init__
super(BoolGauge, self).__init__('BoolGauge', _bool_gauge_methods,
File "C:\Python39\lib\site-packages\tensorflow\python\eager\monitoring.py", line 135, in __init__
self._metric = self._metric_methods[self._label_length].create(*args)
tensorflow.python.framework.errors_impl.
AlreadyExistsError: Another metric with the same name already exists.
Environment:
Python version: 3.9
OS: Windows
Library: TensorFlow API
This appears to be a bug with tensorflow 2.6 see https://forums.developer.nvidia.com/t/unable-to-import-keras-models-on-tensorflow-2-6-0-jetpack-v46/191904
I had the same issue and solved it by downgrading to tensorflow 2.5 until the issue is resolved in a future update.
**Edit: 2.7 is out and seems to have fixed the issue.
*Note: I am using tensorflow with my CPU, not a GPU.
Update: TensorFlow has now released version 2.7.0 (here), so using the latest version will fix your issue.
This specific bug was fixed in version 2.6.2 though actually.
I starting having this issue yesterday during a Github CI build job, but the code was running locally fine.
I solved it by temporarily downgrading to TensorFlow 2.5.2 until the issue is resolved in a future update.
Version 2.5.2 is the latest version before version 2.6.0. I confirmed 2.6.0 and 2.6.1 didn't work for me (at the time of writing).
I happen to have encountered about the same problem on a CI build job today, and wasn't occurring yesterday. So I investigated, and the culprit seems to be keras 2.7 and not tensorflow: https://github.com/keras-team/keras/issues/15585
On my end, the solution was to constraint the version index of Keras to <2.7 but I'll report back if a more stable fix is implemented.
Cheers!
EDIT: the patch release of TF 2.6.2 fixes this (the formerly loose version constraint for keras). So either add a constraint <2.7.0 for keras with your existing TF version or upgrade to TF 2.6.2!
Here, you have got two issues:
CUDA installation missing.
TensorFlow library issue.
For the first case, you can follow the procedure described here
For the issue with the TensorFlow, what worked for me is to downgrade Keras to 2.6.0 using pip install keras==2.6.0 (it should be probably 2.6.1 as of now) to same version as TensorFlow (in my case, TensorFlow version is 2.6.0). Please let me know it works for you.
Encountered this while running code on external GPU, resolved it by upgrading TensorFlow to the 2.7 version

"ImportError: DLL load failed" when importing tensorflow

I get an error when trying to import Tensorflow (v.2.2):
In order to make sure that there are no issues with the Tensorflow installation, I re-installed all the relevant packages in a virtual environment. The error stack that results is the following (both in the virtual and in the original environments)
ImportError: Traceback (most recent call last):
File "C:\Anaconda\envs\cifar_env\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Anaconda\envs\cifar_env\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Anaconda\envs\cifar_env\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "c:\anaconda\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "c:\anaconda\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
Failed to load the native TensorFlow runtime.
Is it possible to tell What DLL is failing to load exactly?
Edit:
If I downgrade to Tensorflow v2.0 the import doesn't fail, but all scripts need to be re-written
If I downgrade to Tensorflow v2.1, the import still fails.
It would be really helpful if somebody could point at what the issue might be.
Downgrading to Tensorflow v1.13.1, which I am using in another machine, results in a collection of warnings, but no errors.
Ridiculous altogether
I had this issue and there didn't appear to be any smoking gun solution - none of them worked in isolation. For anyone truly desperate, this is what I did that cumulatively solved the issue. Note, I am working in an Anaconda Virtual Environment (venv):
I ensured the C++ redistributable was correctly installed, as suggested by xdhmoore in the this related post. After uninstalling and reinstalling it, to be certain, I upgraded Visual Studio from 2019 to 2022.
I updated Conda to the newest version.
Thereafter, I created a wholly new venv. However, I did not use Conda to install any packages except the mandatory packages that it uses to create the environment. I then installed tensorflow using pip (and all other desired packages that I was having issues with pip as well).
Due to this GitHub post, I copied msvcp140.dll from the System32 folder to my venv's DLL folder.
Thereafter, tensorflow works again.

Anaconda install of Tensorflow missing 'audio_ops' from contrib framework

I'm trying to follow along the Audio Recognition Network tutorial.
I've created an Anaconda environment with python 3.6 and followed the install instruction accordingly for installing the GPU whl.
I can run the 'hello world' TF example.
When I go to run 'train.py' in the Audio Recognition Network tutorial/example, I get:
Traceback (most recent call last):
File "train.py", line 79, in <module>
import input_data
File "/home/philglau/speech_commands/input_data.py", line 35, in <module>
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
ImportError: cannot import name 'audio_ops'
The code in the tutorial that fails is:
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
I then backed up that chain until I could import some part of it:
import tensorflow.contrib.framework as test ==> works
import tensorflow.contrib.framework.python as test --> fail:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow.contrib.framework' has no attribute 'python'
Not sure where I'm going wrong on my install.
Details:
Ubuntu 16.04
Anaconda env with python 3.6
Followed the 'anaconda' instruction on the TF install page. (GPU version)
I also tried using a python 2.7 env for anaconda but got the same results.
It looks like they're releasing the audio_ops modules in version 1.4 (https://github.com/tensorflow/tensorflow/issues/11339#issuecomment-327879009).
Until v1.4 is released, an easy way around this is to install the nightly tensorflow build
pip install tf-nightly
or with the docker image linked in the issue comment.
The short answer:
The framework is missing the "audio_ops.py" and the example wont work until the file is released. Or you code the wrappers.
More on this:
If you go to the: tensorflow.contrib.framework.python.ops local folder you can find other *_ops.py files but not the "audio_ops.py".
If you get it from the Master at: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/framework/python/ops
You will find the file is almost empty and with import labels wrong: "audio_ops" vs "gen_audio_ops".
With almost empty I mean that: decode_wav, encode_wav, audio_spectrogram , mfcc are not implemented/wrapped.
So, no working example and no fun.
We need to check again when "audio_ops.py" is released.
Here:
https://github.com/tensorflow/tensorflow/issues/11339
You can find a Developer saying: "we don't actually want to make them public / supported yet. I'm sorry this decision wasn't better documented"

ERROR (theano.gpuarray): Could not initialize pygpu, support disabled

I am trying to configure theano 0.9 to use gpu, but got such error.
I use windows 10 with nvidia GeForce 940m and cuda 8. Previously my system works fine with theano 0.8 for gpu computation. I just updated the theano.
ERROR (theano.gpuarray): Could not initialize pygpu, support disabled
Traceback (most recent call last):
File "C:\Users\YL\Anaconda2\lib\site- packages\theano\gpuarray\__init__.py",
line 175, in <module>
use(config.device)
File "C:\Users\YL\Anaconda2\lib\site-packages\theano\gpuarray\__init__.py", line 162, in use
init_dev(device, preallocate=preallocate)
File "C:\Users\YL\Anaconda2\lib\site-packages\theano\gpuarray\__init__.py", line 65, in init_dev
sched=config.gpuarray.sched)
File "pygpu\gpuarray.pyx", line 614, in pygpu.gpuarray.init (pygpu/gpuarray.c:9415)
File "pygpu\gpuarray.pyx", line 566, in pygpu.gpuarray.pygpu_init (pygpu/gpuarray.c:9106)
File "pygpu\gpuarray.pyx", line 1021, in pygpu.gpuarray.GpuContext.__cinit__ (pygpu/gpuarray.c:13468)
GpuArrayException: Error loading library: -1
Without gpu configuration, theano works fine, otherwise it produces the error. I think I must do something wrong with the configuration. My .theanorc file is as follows:
[global]
device = cuda
floatX = float32
[cuda]
root = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5
[nvcc]
fastmath = True
I am getting the same (similar) error when I run Theano code. I'm using a laptop with two gpu's (optimus technology). What fixed it for me is to run my python code with enabled gpu like so:
optirun python2 my_code.py
Hope this helps.

Why do I get an ImportError when I import TensorFlow?

I'm trying to install tensorflow and now I'm stuck with the following warning:
ranj#ranj-Aspire-V3-772G:~$ python3 -c 'import tensorflow as tf; print(tf.__version__)' # for Python 3Traceback (most recent call last):
...
File "/usr/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libnvidia-fatbinaryloader.so.375.39: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
...
File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libnvidia-fatbinaryloader.so.375.39: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
Can someone tell me how I can solve it?
I'm not sure what exactly caused the error you report, but it seems like an issue with CUDA and/or communication with the NVIDIA card in general. Also, I don't know why the installation of the graphics driver failed as you mention in the comments, but if you want to have GPU support, having a working graphics driver is essential obviously. So either the driver you have currently installed works fine already or then you will have to find out why installing a new version of the driver fails.
You could proceed like this:
Make sure your graphics card fulfills the requirements (CUDA compute capability >= 3.0, check the compute capability of your card here).
Make sure your installation of cuDNN and CUDA Toolkit works fine. For this, you could follow the instructions here (point 6.2.2).
If this works fine, it might just be that Tensorflow cannot find the required CUDA libraries. Check this related Stackoverflow post: GPU tensorflow install issue
As a side note: the tutorial you linked in the comments seems to suggest that you have to build Tensorflow from source using bazel, which is in fact not always necessary. I would recommend you take a look at the official installation instructions - those are pretty comprehensive and consider all the details you require for the installation. So if all fails, consider starting from scratch and follow the official tutorial linked above.
I finally fixed it in gnome (ctrl+alt+f3) and logged in with my account and then used:
"sudo init 3"
"sudo -i"
Went to downloads dir and installed the nvidia driver: "sh NVIDIAxxx.run"
"reboot"
In the gnome I can use python3 and import tensorflow
The problem is now that I cannot login to the os in the normal manner. I still can log into the gmome