I'm attempting to configure the TensorFlow object detection API TFOD in a Python virtual environment with python=3.10.9, TensorFlow=2.8.0, CUDA=11.2 and CuDNN=8.1. I've already passed the verification script and everything works fine until I want to train the model and paste the command below into the command prompt:
python Tensorflow\models\research\object_detection\model_main_tf2.py --model_dir=Tensorflow\workspace\models\my_ssd_mobnet --pipeline_config_path=Tensorflow\workspace\models\my_ssd_mobnet\pipeline.config --num_train_steps=2000
The error it shows me is:
C:\Users\vetran2\pyproj\tfodnew\lib\site-packages\tensorflow_addons\utils\ensure_tf_install.py:53: UserWarning: Tensorflow Addons supports using Python ops for all Tensorflow versions above or equal to 2.9.0 and strictly below 2.12.0 (nightly versions are not supported).
The versions of TensorFlow you are currently using is 2.8.0 and is not supported.
Some things might work, some things might not.
If you were to encounter a bug, do not file an issue.
If you want to make sure you're using a tested and supported configuration, either change the TensorFlow version or the TensorFlow Addons's version.
You can find the compatibility matrix in TensorFlow Addon's readme:
https://github.com/tensorflow/addons
warnings.warn(
Traceback (most recent call last):
File "D:\ObjectDetection\TensorFlow Object Detection\TFODCourse\Tensorflow\models\research\object_detection\model_main_tf2.py", line 31, in <module>
from object_detection import model_lib_v2
File "C:\Users\vetran2\pyproj\tfodnew\lib\site-packages\object_detection-0.1-py3.10.egg\object_detection\model_lib_v2.py", line 31, in <module>
from object_detection import model_lib
File "C:\Users\vetran2\pyproj\tfodnew\lib\site-packages\object_detection-0.1-py3.10.egg\object_detection\model_lib.py", line 35, in <module>
from object_detection.builders import optimizer_builder
File "C:\Users\vetran2\pyproj\tfodnew\lib\site-packages\object_detection-0.1-py3.10.egg\object_detection\builders\optimizer_builder.py", line 25, in <module>
from official.modeling.optimization import ema_optimizer
File "C:\Users\vetran2\pyproj\tfodnew\lib\site-packages\tf_models_official-2.11.3-py3.10.egg\official\modeling\optimization\__init__.py", line 21, in <module>
from official.modeling.optimization.ema_optimizer import ExponentialMovingAverage
File "C:\Users\vetran2\pyproj\tfodnew\lib\site-packages\tf_models_official-2.11.3-py3.10.egg\official\modeling\optimization\ema_optimizer.py", line 24, in <module>
class ExponentialMovingAverage(tf.keras.optimizers.legacy.Optimizer):
AttributeError: module 'tensorflow.keras.optimizers' has no attribute 'legacy'
Related
I ran through the TensorFlow object detection installation on Windows.
https://medium.com/riow/tensorflow-object-detection-on-windows-ad10bfde217c
After successfully installing TensorFlow object detection,
I ran following command to test, and receiving error below. How can this be fixed?
python object_detection/builders/model_builder_test.py
Error: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing pywrap_tensorflow_internal: The specified module could not be found.
Traceback (most recent call last):
File "object_detection/builders/model_builder_test.py", line 21, in
from object_detection.builders import model_builder
File "c:\testimage\models\research\object_detection\builders\model_builder.py", line 23, in
from object_detection.builders import anchor_generator_builder
File "c:\testimage\models\research\object_detection\builders\anchor_generator_builder.py", line 23, in
from object_detection.anchor_generators import flexible_grid_anchor_generator
File "c:\testimage\models\research\object_detection\anchor_generators\flexible_grid_anchor_generator.py", line 17, in
import tensorflow.compat.v1 as tf
File "C:\TestImage\models\venv\lib\site-packages\tensorflow_init.py", line 41, in
from tensorflow.python.tools import module_util as module_util
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python_init.py", line 40, in
from tensorflow.python.eager import context
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\eager\context.py", line 35, in
from tensorflow.python import pywrap_tfe
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in
from tensorflow.python import pywrap_tensorflow
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Currently using Python 3.8 with latest tensorflow, with tensorflow-cpu
tldr;
You need to install the C++ redistributable mentioned on the install page before installing TensorFlow so that TensorFlow can use it to generate code at install time.
Details:
I'm not an expert but it sounds like this was key:
The pywrap_tensorflow_internal.py module you are missing appears to me to be a SWIG-generated python interface to a C++ library, or something of that nature. My guess is, that file gets generated when you install TensorFlow (it reminds me of how some Ruby gems have to compile C++ when you install them, for whatever that's worth). Since you don't have that generated file, my guess is that the C++ package mentioned on the TensorFlow install page is needed for that code generation, so you need to have the C++ package installed before installing TensorFlow.
Totally a guess, but perhaps you installed the C++ package after TF. In that case, you should be able to uninstall TF, install the C++ package, and then install TF again.
Maybe a lingering question is if there were any indicative error messages on installing TF about the missing C++ package and if not, maybe there should be.
I ran through the TensorFlow object detection installation on Windows.
https://medium.com/riow/tensorflow-object-detection-on-windows-ad10bfde217c
After successfully installing TensorFlow object detection,
I ran following command to test, and receiving error below. How can this be fixed?
python object_detection/builders/model_builder_test.py
Error: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing pywrap_tensorflow_internal: The specified module could not be found.
Traceback (most recent call last):
File "object_detection/builders/model_builder_test.py", line 21, in
from object_detection.builders import model_builder
File "c:\testimage\models\research\object_detection\builders\model_builder.py", line 23, in
from object_detection.builders import anchor_generator_builder
File "c:\testimage\models\research\object_detection\builders\anchor_generator_builder.py", line 23, in
from object_detection.anchor_generators import flexible_grid_anchor_generator
File "c:\testimage\models\research\object_detection\anchor_generators\flexible_grid_anchor_generator.py", line 17, in
import tensorflow.compat.v1 as tf
File "C:\TestImage\models\venv\lib\site-packages\tensorflow_init.py", line 41, in
from tensorflow.python.tools import module_util as module_util
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python_init.py", line 40, in
from tensorflow.python.eager import context
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\eager\context.py", line 35, in
from tensorflow.python import pywrap_tfe
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in
from tensorflow.python import pywrap_tensorflow
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Currently using Python 3.8 with latest tensorflow, with tensorflow-cpu
tldr;
You need to install the C++ redistributable mentioned on the install page before installing TensorFlow so that TensorFlow can use it to generate code at install time.
Details:
I'm not an expert but it sounds like this was key:
The pywrap_tensorflow_internal.py module you are missing appears to me to be a SWIG-generated python interface to a C++ library, or something of that nature. My guess is, that file gets generated when you install TensorFlow (it reminds me of how some Ruby gems have to compile C++ when you install them, for whatever that's worth). Since you don't have that generated file, my guess is that the C++ package mentioned on the TensorFlow install page is needed for that code generation, so you need to have the C++ package installed before installing TensorFlow.
Totally a guess, but perhaps you installed the C++ package after TF. In that case, you should be able to uninstall TF, install the C++ package, and then install TF again.
Maybe a lingering question is if there were any indicative error messages on installing TF about the missing C++ package and if not, maybe there should be.
I have tensorflow 1.5 and everything is working fine with tensorflow.
Now i want to convert my tensorflow keras model to be used in web app so i installed tensorflowjs successfully but when i import i get the error.
I have tried changing the following versions:
numpy from 1.16.4 to 1.15.1,
tensorflow 1.5.0 to 1.8.0 and 1.12.0,
tensorflowjs 1.1.2 to 1.0.0
tensorflow test:
import tensorflow as tf
print(tf.__version__)
hello = tf.constant("Hello Tensorflow")
with tf.Session() as sesh:
print(sesh.run(hello))
Output:
1.12.0
2019-06-11 12:02:11.140827: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
b'Hello Tensorflow'
So i guess everything is fine with tensorflow but still i cant import tensorflowjs due to some files missing in my tensorflow installation.
i got this error first:
Traceback (most recent call last):
File "C:/Users/Uxama/PycharmProjects/untitled1/test.py", line 2, in <module>
import tensorflowjs as tfjs
File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\__init__.py", line 21, in <module>
from tensorflowjs import converters
File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\converters\__init__.py", line 24, in <module>
from tensorflowjs.converters.tf_saved_model_conversion_v2 import convert_tf_saved_model
File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\converters\tf_saved_model_conversion_v2.py", line 29, in <module>
from tensorflow.python.framework import convert_to_constants
ImportError: cannot import name 'convert_to_constants'
Then i placed the file (convert_to_constants) manually because changing the versions doesn't seems to work and change anything.
Then i got this error:
Traceback (most recent call last):
File "C:/Users/Uxama/PycharmProjects/untitled1/test.py", line 2, in <module>
import tensorflowjs as tfjs
File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\__init__.py", line 21, in <module>
from tensorflowjs import converters
File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\converters\__init__.py", line 24, in <module>
from tensorflowjs.converters.tf_saved_model_conversion_v2 import convert_tf_saved_model
File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\converters\tf_saved_model_conversion_v2.py", line 29, in <module>
from tensorflow.python.framework import convert_to_constants
File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflow\python\framework\convert_to_constants.py", line 26, in <module>
from tensorflow.python.eager import wrap_function
ImportError: cannot import name 'wrap_function'
I did the same thing again and placed the file but the errors seems to kept coming.
I don't know what exactly causing the problem i installed tensorflow with pip and also tried installing it with wheels as well.
I just want to successfully install tensorflowjs so that i can convert my keras model to use in web app.
Tensorflow 1.12 doesn't define a function called wrap_function(). Consider upgrading to API r1.13. Here are the functions defined in API r1.12, which you are currently using, and here is the wrap_function() method which is defined in API r1.13.
I am trying to use tensorflowjs for the first time alongside react to build a web application, I have trained my model using keras and have saved my weights into a hdf5 file format and am referring to this link here - https://www.tensorflow.org/js/guide/conversion
$ tensorflowjs_converter --input_format=keras /tmp/model.h5 /tmp/tfjs_model
This ^ is what I tried but then I am getting errors.
Initially got this error given here (no add_to_collection was found when using tensorflowjs_converter) I solved it by installing a different version of tensorflowjs v0.6.4
Now that I have installed tensorflowjs v0.6.4 I am getting another error described below :
gaganganapathyas:~ codhek$ tensorflowjs_converter --input_format=keras /tmp/model.h5 /tmp/tfjs_model
Using TensorFlow backend.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/bin/tensorflowjs_converter", line 6, in <module>
from tensorflowjs.converters.converter import main
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflowjs/__init__.py", line 21, in <module>
from tensorflowjs import converters
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflowjs/converters/__init__.py", line 24, in <module>
from tensorflowjs.converters.tf_saved_model_conversion import convert_tf_saved_model
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflowjs/converters/tf_saved_model_conversion.py", line 34, in <module>
import tensorflow_hub as hub
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/__init__.py", line 25, in <module>
from tensorflow_hub.feature_column import image_embedding_column
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/feature_column.py", line 25, in <module>
from tensorflow_hub import module
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/module.py", line 23, in <module>
from tensorflow_hub import native_module
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/native_module.py", line 26, in <module>
from tensorflow_hub import compressed_module_resolver
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/compressed_module_resolver.py", line 35, in <module>
from tensorflow_hub import resolver
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/resolver.py", line 34, in <module>
FLAGS = tf.flags.FLAGS
AttributeError: 'module' object has no attribute 'flags'
Even tried to add the absolute path along with the above command, but didn't work :
/Library/Frameworks/Python.framework/Versions/2.7/bin/tensorflowjs_converter --input_format=keras /tmp/weights.model /tmp/tfjs_model
Here is the link to my keras cnn model : https://www.kaggle.com/codhek/cnn-using-keras-using-csv-accuracy-99-82
Does model.save_weights() and model.save() make any difference?
Also, if I save a .json version of my model can I directly load it into my js app ?
It worked once you use tensorflow v0.6.4 with keras v2.1.6 although keras install might give you a warning that
ERROR: tensorflowjs 0.6.4 has requirement keras==2.2.2, but you'll have keras 2.1.6 which is incompatible.
This is because tensorflow v0.6.4 needs keras==2.2.2 but then keras-preprocessing version don't match!
I am running Python 2.7.10 and I successfully installed TensorFlow, using pip install
https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl.
When I run the python interpreter and attempt to import the tensorflow module, I get the following error:
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\__init__.py", line 4, in <module>
from tensorflow.python import *
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\python\__init__.py", line 22, in <module>
from tensorflow.python.client.client_lib import *
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\python\client\client_lib.py", line 35, in <module>
from tensorflow.python.client.session import InteractiveSession
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\python\client\session.py", line 11, in <module>
from tensorflow.python import pywrap_tensorflow as tf_session
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
import _pywrap_tensorflow
ImportError: No module named _pywrap_tensorflow
you can use pip to install tensorflow
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl
If you are trying to install on windows , you will have to have python3.5 x64 bit and along with that you need to install Visual C++ 2015 redistributable (x64 version) to be able to import tensorflow
Judging by the paths in the output, it looks like you are trying to run TensorFlow on Windows. The package that you have installed is a Mac OS X binary distribution of TensorFlow.
Unfortunately, Windows is not currently supported by TensorFlow, and it is unlikely to be supported before its build system (Bazel) adds Windows support. There is some discussion of progress towards a Windows version on this GitHub issue, and an unsupported contribution that builds TensorFlow using CMake on Windows.