Tensorflow installation issues on RaspberryPi 3 B+ - tensorflow2.0

Tried installing Tensorflow on RaspberryPi 3b+ model which gives the following error:
Traceback (most recent call last):
File "/home/infant-cry-detector/infant-cry-detector/_cnn__real_time_audio.py", line 22, in <module>
from tensorflow.keras import losses, models, optimizers
ModuleNotFoundError: No module named 'tensorflow.keras'
Tried to install Tensorflow versions<1.6 on RaspberryPi 3 b+ model but while using the same it shows module not found and unable to import tensorflow.keras which also returns module not found error.
We are complete beginners in coding with RaspberryPi, hence requesting detailed help that would help us get through the error.

Related

Error when "import tensorflow as tf" in colab

When I "import tensorflow as tf" in google colab I am getting the following error. Any idea how to fix it ?
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-37-07e0f991eb97> in <module>()
----> 1 import tensorflow as tf
2
3 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/client/pywrap_tf_session.py in <module>()
17 # pylint: disable=invalid-import-order,g-bad-import-order, wildcard-import, unused-import
18 from tensorflow.python import pywrap_tensorflow
---> 19 from tensorflow.python.client._pywrap_tf_session import *
20 from tensorflow.python.client._pywrap_tf_session import _TF_SetTarget
21 from tensorflow.python.client._pywrap_tf_session import _TF_SetConfig
ImportError: SystemError: <built-in method __contains__ of dict object at 0x7f79368db0a0> returned a result with an error set
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
This issue has been fixed now in 2.8.0 stable version. If it still persists ,please install Numpy 1.21.5 manually and Try again.
I've post a similar error on tensorflow github issue.
Tensorflow 2.8.0 | Error Message: ImportError: SystemError.
My solution (since I'm using conda environment on Windows 10), is to downgrade the Tensorflow version to 2.7.0. Hope help helps.

ModuleNotFoundError: No module named 'official.modeling.optimization'

Please give solution on the following error. The tricky part is that the verification and testing is running "OK" but when I run command for training it throws following error.
The system details are as follows
Win10 - python 3.7.6
cuda 10.1 cudnn - 7.6.5
opencv - 4.5.1.48
tensorflow / tensorflow-gpu ==2.2.0
object_detection-0.1
protoc - 3.17.3
tf-models-official
tensorflow-model-optimization
Paths are already created
(Working on jupyter notebook on TFOD-API)
Traceback (most recent call last): File
"Tensorflow\models\research\object_detection\model_main_tf2.py", line
32, in
from object_detection import model_lib_v2 File "D:\Code_kida\ANPR\Tensorflow\models\research\object_detection\model_lib_v2.py",
line 31, in
from object_detection import model_lib File "D:\Code_kida\ANPR\Tensorflow\models\research\object_detection\model_lib.py",
line 34, in
from object_detection.builders import optimizer_builder File "D:\Code_kida\ANPR\Tensorflow\models\research\object_detection\builders\optimizer_builder.py",
line 25, in
from official.modeling.optimization import ema_optimizer ModuleNotFoundError: No module named 'official.modeling.optimization'
Make sure that the folder "D:\Code_kida\ANPR\Tensorflow\models\official" is exist and it has "modeling/optimization/ema_optimizer.py" inside.
I had the same error and that was the fix for me. might work for you too. or whoever comes here in the future

AttributeError : module 'tensorflow' has no attribute 'contrib' [duplicate]

This question already has answers here:
Module 'tensorflow' has no attribute 'contrib'
(10 answers)
Closed 2 years ago.
I followed instructions (https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html) to install the Tensorflow Object Detection API. I use Anaconda on ubuntu18.4 and all of the steps in the instructions seemed to complete OK.
When I train to train my model with the following command:
python model_main_tf2.py --model_dir=models/my_ssd_resnet50_v1_fpn --pipeline_config_path=models/my_ssd_resnet50_v1_fpn/pipeline.config
I get the following error:
Instructions for updating:
non-resource variables are not supported in the long term
Traceback (most recent call last):
File "model_main_tf2.py", line 34, in <module>
from object_detection import model_lib_v2
File "/home/chanitda/Desktop/Tensorflow/workspace/training_demo/object_detection/model_lib_v2.py", line 28, in <module>
from object_detection import eval_util
File "/home/chanitda/Desktop/Tensorflow/workspace/training_demo/object_detection/eval_util.py", line 30, in <module>
slim = tf.contrib.slim
AttributeError: module 'tensorflow' has no attribute 'contrib'
I get the error mentioned in the headline. I would be very thankful if someone could help me with a code example to solve the problem.
It looks like you are using the tensorflow 2.0 version, but the code you use needs tf 1.14. The module contrib is not available in tf 2.0 anymore, thats why you are seeing this error. So you should set up a new environment and install tf 1.14 there, so you can run the code properly without ruining your tf 2.0 environment

"ImportError: DLL load failed: The specified module could not be found" when trying to import gensim

While trying to import gensim, I run into the following error
Traceback (most recent call last):
File "c:\Users\usr\Documents\hello\test.py", line 3, in <module>
import gensim
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\gensim\__init__.py", line 5, in <module>
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\gensim\corpora\__init__.py", line 6, in <module>
from .indexedcorpus import IndexedCorpus # noqa:F401 must appear before the other classes
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\gensim\corpora\indexedcorpus.py", line 15, in <module>
from gensim import interfaces, utils
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\gensim\interfaces.py", line 21, in <module>
from gensim import utils, matutils
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\gensim\matutils.py", line 21, in <module>
from scipy.stats import entropy
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\stats\__init__.py", line 384, in <module>
from .stats import *
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\stats\stats.py", line 179, in <module>
from scipy.spatial.distance import cdist
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\spatial\__init__.py", line 99, in <module>
from .qhull import *
ImportError: DLL load failed: The specified module could not be found.
I have tried uninstalling numpy, scipy and gensim using pip in the command prompt and installing them again, but this does not resolve the issue.
I have also looked at the suggestions to a similar problem here, and tried installing numpy‑1.19.0+mkl‑cp37‑cp37m‑win_amd64.whl, but it resulted in a separate error Importing the numpy c-extensions failed. Thus, I have stuck to using numpy, scipy and gensim installed via pip.
Additionally, I installed scipy version 1.4.1 as the latest 1.5.0 version will give the following error as described in this link:
Error when loading scipy: OSError: [WinError 126] The specified module could not be found
Any help is greatly appreciated!
For additional information, I am using Python 3.7 and Windows 10.
I had the same problem and tried various things, but the only thing that worked for me was to install an older version of Gensim.
pip install gensim==3.7.0

Tensorflow importing error in Jupyter notebook

So I managed all other packages (such as cv2, pandas, matplotlib..) work well in the default kernel or Python 3 kernel, except Tensorflow.
Tensorflow does not import with Kernel: "Python 3" or "Python default".
import tensorflow as tf
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-41389fad42b5> in <module>()
----> 1 import tensorflow as tf
ImportError: No module named tensorflow
When I choose "env: tensorflow" kernel, my other packages such as pandas, cv2 all collapse. Thus, I try to use "default" kernel or "Python 3" kernel.
Thanks a lot.
You haven't loaded the tensorflow kernel, please follow instructions here.