Tensor2tensor: My customed problem never registered with registry problems - tensorflow

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'

Related

mixed_precision.experimental.LossScaleOptimizer() in TF version 2.2.0

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'

AttributeError: module 'tensorflow.contrib' has no attribute 'checkpoint'

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'

Errors in converting Tensorflow Model to Tensorflow Lite Model

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.

No module named 'tensorflow_datasets.image.cityscapes'

I installed TensorFlow Datasets using conda, as:
conda install -c anaconda tensorflow-datasets
I've tried importing Cityscapes:
from tensorflow_datasets.image.cityscapes import Cityscapes
but this raises the following error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'tensorflow_datasets.image.cityscapes'
How can I fix it?
PS: I can import the following without errors:
import tensorflow_datasets as tfds
Edit:
I've already downloaded Cityscapes data, as recommended in the official guide.

Linking the French Spacy model but failing to load it

I successfully downloaded SpaCy and the French model to apply it to the Rasa starter pack. Yet when running the rasa_nlu training command it seems the OS can't find the French model.
C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
2019-05-02 19:14:58 INFO rasa_nlu.utils.spacy_utils - Trying to load spacy model with name 'fr'
Traceback (most recent call last):
File "C:\Python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_nlu\train.py", line 184, in <module>
num_threads=cmdline_args.num_threads)
File "C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_nlu\train.py", line 148, in do_train
trainer = Trainer(cfg, component_builder)
File "C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_nlu\model.py", line 155, in __init__
self.pipeline = self._build_pipeline(cfg, component_builder)
File "C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_nlu\model.py", line 166, in _build_pipeline
component_name, cfg)
File "C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_nlu\components.py", line 441, in create_component
cfg)
File "C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_nlu\registry.py", line 142, in create_component_by_name
return component_clz.create(config)
File "C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_nlu\utils\spacy_utils.py", line 73, in create
nlp = spacy.load(spacy_model_name, parser=False)
File "C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\spacy\__init__.py", line 27, in load
return util.load_model(name, **overrides)
File "C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\spacy\util.py", line 136, in load_model
raise IOError(Errors.E050.format(name=name))
OSError: [E050] Can't find model 'fr'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.
(staenv) C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack>python -m spacy download fr
Requirement already satisfied: fr_core_news_sm==2.1.0 from https://github.com/explosion/spacy-models/releases/download/fr_core_news_sm-2.1.0/fr_core_news_sm-2.1.0.tar.gz#egg=fr_core_news_sm==2.1.0 in c:\users\antoi\documents\programming\paco\starter-pack-rasa-stack\staenv\lib\site-packages (2.1.0)
You are using pip version 10.0.1, however version 19.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
✔ Download and installation successful
You can now load the model via spacy.load('fr_core_news_sm')
You do not have sufficient privilege to perform this operation.
✔ Linking successful
C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\fr_core_news_sm
-->
C:\Users\antoi\Documents\Programming\PACO\starter-pack-rasa-stack\staenv\lib\site-packages\spacy\data\fr
You can now load the model via spacy.load('fr')
My spacy version is 2.1.3
I think this is actually a SpaCy issue.
Due to the line You do not have sufficient privilege to perform this operation. I think you have to run the Windows command line as administrator.
This spaCy issues describes the same problem and gives further recommendations.