I have tried to run my first demo using keras with tensorflow backend but failed:
Traceback (most recent call last):
File "mnist_cnn.py", line 26, in <module>
if K.image_data_format() == 'channels_first':
AttributeError: 'module' object has no attribute 'image_data_format'
keras version: 1.2.1
tensorflow version: 1.0.1
How to fix?
update keras to 2.0.2 and it fixed.
Related
I am trying to use mixed_precision in TensorFlow 2.2.0. Since I wrote the code in tf version 2.9.2 and need to run it on a computer with version 2.2.0. I couldn't find a page for the experimental mixed_precision page since it is embedded into core tf.
POLICY:
policy = mixed_precision.experimental.Policy('mixed_float16')
mixed_precision.experimental.set_policy(policy)
OPTIMIZER:
self.optimizer = tf.keras.optimizers.Adam(learning_rate=LR_SCHEDULE, epsilon=1e-08)
self.optimizer = mixed_precision.experimental.LossScaleOptimizer(self.optimizer)
ERRROR:
Traceback (most recent call last):
File "my_code.py", line 354, in <module>
model.train(total_it=TRAIN_IT)
File "my_code.py", line 166, in train
self.optimizer = mixed_precision.experimental.LossScaleOptimizer(self.optimizer)
TypeError: __init__() missing 1 required positional argument: 'loss_scale'
I am implementing the below link and getting a TensorFlow version error. I am working in Pycharm under Conda environment.
https://github.com/ZhaoJ9014/High-Performance-Face-Recognition/tree/master/src/Look%20Across%20Elapse-%20Disentangled%20Representation%20Learning%20and%20Photorealistic%20Cross-Age%20Face%20Synthesis%20for%20Age-Invariant%20Face%20Recognition.TensorFlow
I tried many versions, in some versions, the problem has been solved but the GPU available is False. The problem is in the version I didn't find any compatible version in which the GPU available is True.
pip install tensorflow-gpu==1.6.0, 1.5.0, 1.8.0
Traceback
Traceback (most recent call last):
File "/home/khawar/Desktop/AAAIFace/train_main.py", line 4, in <module>
import modeleag as M
File "/home/khawar/Desktop/AAAIFace/modeleag.py", line 1, in <module>
import layers2 as L
File "/home/khawar/Desktop/AAAIFace/layers2.py", line 36, in <module>
class Layer(tf.contrib.checkpoint.Checkpointable):
File "/home/khawar/anaconda3/envs/AAAIFace/lib/python3.6/site-packages/tensorflow/python/util/lazy_loader.py", line 54, in __getattr__
return getattr(module, item)
AttributeError: module 'tensorflow.contrib' has no attribute 'checkpoint'
I wanted to use yolov4-tiny in the Tensorflow lite framework to count objects that cross a virtual line in a video.
I converted my darknet weights trained from AlexeyAB's repo using these commands:
python save_model.py --weights yolov4-tiny.weights --output ./checkpoints/yolov4-tiny-608-tf --input_size 608 --model yolov4 --tiny --framework tflite
python convert_tflite.py --weights ./checkpoints/yolov4-tiny-608-tf --output ./checkpoints/yolov4-tiny-608.tflite
You can find the convert_tflite.py here
The first command is successful using numpy==1.19.0. However, the second one shows these errors:
loc("batch_normalization/moving_mean"): error: is not immutable, try running tf-saved-model-optimize-global-tensors to prove tensors are immutable
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\tensorflow\lite\python\convert.py", line 213, in toco_convert_protos
enable_mlir_converter)
File "C:\Python37\lib\site-packages\tensorflow\lite\python\wrap_toco.py", line 38, in wrapped_toco_convert
enable_mlir_converter)
Exception: <unknown>:0: error: loc("batch_normalization/moving_mean"): is not immutable, try running tf-saved-model-optimize-global-tensors to prove tensors are immutable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "convert_tflite.py", line 76, in <module>
app.run(main)
File "C:\Python37\lib\site-packages\absl\app.py", line 303, in run
_run_main(main, args)
File "C:\Python37\lib\site-packages\absl\app.py", line 251, in _run_main
sys.exit(main(argv))
File "convert_tflite.py", line 71, in main
save_tflite()
File "convert_tflite.py", line 45, in save_tflite
tflite_model = converter.convert()
File "C:\Python37\lib\site-packages\tensorflow\lite\python\lite.py", line 762, in convert
result = _convert_saved_model(**converter_kwargs)
File "C:\Python37\lib\site-packages\tensorflow\lite\python\convert.py", line 648, in convert_saved_model
enable_mlir_converter=True)
File "C:\Python37\lib\site-packages\tensorflow\lite\python\convert.py", line 216, in toco_convert_protos
raise ConverterError(str(e))
tensorflow.lite.python.convert.ConverterError: <unknown>:0: error: loc("batch_normalization/moving_mean"): is not immutable, try running tf-saved-model-optimize-global-tensors to prove tensors are immutable
I have tried other versions of Tensorflow (2.2, 2.3, 2.4) but I had no luck. What should I do?
There is a similar issue raised here: Tensorflow Issue 44790
Here are my system details:
Windows 10, x64
GeForce GTX 1060
NVIDIA Driver 460.89
CUDA 11.0.3
CuDNN 8.0.5.39
Python 3.7.2
pip install tensorflow==2.3.0rc0
and restart runtime before starting conversion
I resolved the problem by following a thread on Github issues.
In google colab, I had this issue if I used the default TF version, which was 2.4.0 or above.
Running !pip install tensorflow==2.3.0 and restarting the runtime, then converting corrected the issue.
For me this solved my problem :
import tensorflow as tf
if tf.__version__ != '2.3.0-rc0':
!pip uninstall -y tensorflow
!pip install tensorflow-gpu==2.3.0rc0
And restart runtime, in order to use newly installed versions.
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
Description
I am following a tutorial of microsoft from this website
to get a model to inference Chinese couplet.
Now I have trained the model on Google cloud and I can also get good inference.
Howerver, when I am constructing inference service, I found my function to communicate with tensorflowserverapi can't find my problem get registered.
I also have trained this model for one step and add t2t_trainer --registry_help, and I can see my problem is actually registered under problems Problems.
My code is just the same as the one in this repo script
And here is my test code:
from up2down_model.up2down_model import up2down
upper_couplet = input()
up2down.get_down_couplet([upper_couplet])
Environment information:
OS: Ubuntu 20.04
$ pip freeze | grep tensor
tensor2tensor 1.15.6
tensorboard 1.14.0
tensorflow 1.14.0
tensorflow-addons 0.10.0
tensorflow-datasets 1.3.0
tensorflow-estimator 1.14.0
tensorflow-gan 2.0.0
tensorflow-hub 0.8.0
tensorflow-metadata 0.22.0
tensorflow-probability 0.7.0
tensorflow-serving-api 1.14.0
$ python -3.7.7
Error logs:
raceback (most recent call last):
File "/home/enigma/anaconda3/envs/NLP/lib/python3.7/site-packages/tensor2tensor/utils/registry.py", line 509, in problem
return Registries.problems[spec.base_name](
File "/home/enigma/anaconda3/envs/NLP/lib/python3.7/site-packages/tensor2tensor/utils/registry.py", line 254, in __getitem__
(key, self.name, display_list_by_prefix(sorted(self), 4)))
KeyError: 'translate_up2down never registered with registry problems. Available:
All problems without my own
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 1, in <module>
from up2down_model.up2down_model import up2down
File "/home/enigma/Desktop/NLP/service/up2down_model/up2down_model.py", line 85, in <module>
up2down = up2down_class(FLAGS,server_address) # inference model
File "/home/enigma/Desktop/NLP/service/up2down_model/up2down_model.py", line 40, in __init__
self.problem = registry.problem(self.FLAGS.problem)
File "/home/enigma/anaconda3/envs/NLP/lib/python3.7/site-packages/tensor2tensor/utils/registry.py", line 513, in problem
return env_problem(problem_name, **kwargs)
File "/home/enigma/anaconda3/envs/NLP/lib/python3.7/site-packages/tensor2tensor/utils/registry.py", line 527, in env_problem
ep_cls = Registries.env_problems[env_problem_name]
File "/home/enigma/anaconda3/envs/NLP/lib/python3.7/site-packages/tensor2tensor/utils/registry.py", line 254, in __getitem__
(key, self.name, display_list_by_prefix(sorted(self), 4)))
KeyError: 'translate_up2down never registered with registry env_problems. Available:\n reacher:\n * reacher_env_problem\n tic:\n * tic_tac_toe_env_problem'