RuntimeError: Resize coordinate_transformation_mode=pytorch_half_pixel is not supported in Tensorflow - tensorflow

I covert onnxmodel to pb, and get this problem:
Traceback (most recent call last):
File "/home/fffan/fffan_files/Experiment/Example/onnx2pb/onnx2pb.py", line 45, in <module>
onnx2pb_2(onnx_input_path)
File "/home/fffan/fffan_files/Experiment/Example/onnx2pb/onnx2pb.py", line 14, in onnx2pb_2
tf_rep = prepare(model,strict=False)
File "/home/fffan/下载/onnx-tensorflow-tf-1.x/onnx_tf/backend.py", line 65, in prepare
return cls.onnx_model_to_tensorflow_rep(model, strict)
File "/home/fffan/下载/onnx-tensorflow-tf-1.x/onnx_tf/backend.py", line 85, in onnx_model_to_tensorflow_rep
return cls._onnx_graph_to_tensorflow_rep(model.graph, opset_import, strict)
File "/home/fffan/下载/onnx-tensorflow-tf-1.x/onnx_tf/backend.py", line 146, in _onnx_graph_to_tensorflow_rep
strict=strict)
File "/home/fffan/下载/onnx-tensorflow-tf-1.x/onnx_tf/backend.py", line 241, in _onnx_node_to_tensorflow_op
return handler.handle(node, tensor_dict=tensor_dict, strict=strict)
File "/home/fffan/下载/onnx-tensorflow-tf-1.x/onnx_tf/handlers/handler.py", line 60, in handle
cls.args_check(node, **kwargs)
File "/home/fffan/下载/onnx-tensorflow-tf-1.x/onnx_tf/handlers/backend/resize.py", line 89, in args_check
"Tensorflow")
File "/home/fffan/下载/onnx-tensorflow-tf-1.x/onnx_tf/common/exception.py", line 50, in __call__
raise self._func(self.get_message(op, framework))
RuntimeError: Resize coordinate_transformation_mode=pytorch_half_pixel is not supported in Tensorflow.
The code is :
import onnx
from onnx_tf.backend import prepare
import numpy as np
model = onnx.load(onnx_input_path)
tf_rep = prepare(model,strict=False)
How can I solve this problem?
ps: The algorithm model I covert is PSEnet.

Related

how to convert imagenet/mobilenet_v2_130_224/classification into mlmodel

i m very new to this but I am trying to solve the issue somehow. this is my convert.py file
import numpy as n
import tensorflow as tf
import coremltools as ct
print(n.__version__)
print(tf.__version__)
print(ct.__version__)
loaded_model = tf.saved_model.load("mobilenet_v2_130_224.h5")
mlmodel = ct.convert(loaded_model, inputs=[ct.ImageType()], classifier_config=ct.ClassifierConfig("labels.txt"), source='tensorflow')
mlmodel.short_description = "My Classifier"
mlmodel.license = "Apache 2.0"
spec = mlmodel.get_spec()
ct.utils.rename_feature(spec, "input_1", "imageInput")
ct.utils.rename_feature(spec, "Identity", "classResult")
mlmodel = ct.models.MLModel(spec)
print(mlmodel)
mlmodel.save("model_299x299.mlmodel")
I downloaded the model from [here][1] and unzipped on desktop. I have M1 iMac. why do I get these errors below? how can I convert this particular model into mlmodel? if my convert file is wrongly written what should be the best practice of it ?
Traceback (most recent call last):
File "/Users/asduskun/Desktop/convert.py", line 20, in <module>
mlmodel = ct.convert(loaded_model, inputs=[ct.ImageType()], classifier_config=ct.ClassifierConfig("labels.txt"), source='tensorflow')
File "/Users/asduskun/miniconda3/lib/python3.10/site-packages/coremltools/converters/_converters_entry.py", line 444, in convert
mlmodel = mil_convert(
File "/Users/asduskun/miniconda3/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 187, in mil_convert
return _mil_convert(model, convert_from, convert_to, ConverterRegistry, MLModel, compute_units, **kwargs)
File "/Users/asduskun/miniconda3/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 211, in _mil_convert
proto, mil_program = mil_convert_to_proto(
File "/Users/asduskun/miniconda3/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 281, in mil_convert_to_proto
prog = frontend_converter(model, **kwargs)
File "/Users/asduskun/miniconda3/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 99, in __call__
return tf2_loader.load()
File "/Users/asduskun/miniconda3/lib/python3.10/site-packages/coremltools/converters/mil/frontend/tensorflow/load.py", line 61, in load
self._graph_def = self._graph_def_from_model(output_names)
File "/Users/asduskun/miniconda3/lib/python3.10/site-packages/coremltools/converters/mil/frontend/tensorflow2/load.py", line 133, in _graph_def_from_model
cfs, graph_def = self._get_concrete_functions_and_graph_def()
File "/Users/asduskun/miniconda3/lib/python3.10/site-packages/coremltools/converters/mil/frontend/tensorflow2/load.py", line 125, in _get_concrete_functions_and_graph_def
raise NotImplementedError(msg.format(self.model))
NotImplementedError: Expected model format: [SavedModel | [concrete_function] | tf.keras.Model | .h5 | GraphDef], got <tensorflow.python.saved_model.load.Loader._recreate_base_user_object.<locals>._UserObject object at 0x1676455a0>
[1]: https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/5

tensorflow.python.framework.errors_impl.NotFoundError while running deep learning model on Google Colaboratory

I'm trying to run on cloud this deep learning model:
https://github.com/razvanmarinescu/brgm#image-reconstruction-with-pre-trained-stylegan2-generators
What I do is simply utilizing their Colab Notebook: https://colab.research.google.com/drive/1G7_CGPHZVGFWIkHOAke4HFg06-tNHIZ4?usp=sharing#scrollTo=qMgE6QFiHuSL
When I try to exectute:
!python recon.py recon-real-images --input=/content/drive/MyDrive/boeing/EDGEconnect/val_imgs --masks=/content/drive/MyDrive/boeing/EDGEconnect/val_masks --tag=brains --network=dropbox:brains.pkl --recontype=inpaint --num-steps=1000 --num-snapshots=1
I receive this error:
args: Namespace(command='recon-real-images', input='/content/drive/MyDrive/boeing/EDGEconnect/val_imgs', masks='/content/drive/MyDrive/boeing/EDGEconnect/val_masks', network_pkl='dropbox:brains.pkl', num_snapshots=1, num_steps=1000, recontype='inpaint', superres_factor=4, tag='brains')
Local submit - run_dir: results/00004-brains-inpaint
dnnlib: Running recon.recon_real_images() on localhost...
Processing image 1/4
Loading networks from "dropbox:brains.pkl"...
Setting up TensorFlow plugin "fused_bias_act.cu": Preprocessing... Loading... Failed!
Traceback (most recent call last):
File "recon.py", line 270, in <module>
main()
File "recon.py", line 263, in main
dnnlib.submit_run(sc, func_name_map[subcmd], **kwargs)
File "/content/drive/MyDrive/boeing/brgm/brgm/dnnlib/submission/submit.py", line 343, in submit_run
return farm.submit(submit_config, host_run_dir)
File "/content/drive/MyDrive/boeing/brgm/brgm/dnnlib/submission/internal/local.py", line 22, in submit
return run_wrapper(submit_config)
File "/content/drive/MyDrive/boeing/brgm/brgm/dnnlib/submission/submit.py", line 280, in run_wrapper
run_func_obj(**submit_config.run_func_kwargs)
File "/content/drive/MyDrive/boeing/brgm/brgm/recon.py", line 189, in recon_real_images
recon_real_one_img(network_pkl, img_list[image_idx], masks, num_snapshots, recontype, superres_factor, num_steps)
File "/content/drive/MyDrive/boeing/brgm/brgm/recon.py", line 132, in recon_real_one_img
_G, _D, Gs = pretrained_networks.load_networks(network_pkl)
File "/content/drive/MyDrive/boeing/brgm/brgm/pretrained_networks.py", line 83, in load_networks
G, D, Gs = pickle.load(stream, encoding='latin1')
File "/content/drive/MyDrive/boeing/brgm/brgm/dnnlib/tflib/network.py", line 297, in __setstate__
self._init_graph()
File "/content/drive/MyDrive/boeing/brgm/brgm/dnnlib/tflib/network.py", line 154, in _init_graph
out_expr = self._build_func(*self.input_templates, **build_kwargs)
File "<string>", line 395, in G_synthesis_stylegan2
File "<string>", line 359, in layer
File "<string>", line 106, in modulated_conv2d_layer
File "<string>", line 75, in apply_bias_act
File "/content/drive/MyDrive/boeing/brgm/brgm/dnnlib/tflib/ops/fused_bias_act.py", line 68, in fused_bias_act
return impl_dict[impl](x=x, b=b, axis=axis, act=act, alpha=alpha, gain=gain)
File "/content/drive/MyDrive/boeing/brgm/brgm/dnnlib/tflib/ops/fused_bias_act.py", line 122, in _fused_bias_act_cuda
cuda_kernel = _get_plugin().fused_bias_act
File "/content/drive/MyDrive/boeing/brgm/brgm/dnnlib/tflib/ops/fused_bias_act.py", line 16, in _get_plugin
return custom_ops.get_plugin(os.path.splitext(__file__)[0] + '.cu')
File "/content/drive/MyDrive/boeing/brgm/brgm/dnnlib/tflib/custom_ops.py", line 156, in get_plugin
plugin = tf.load_op_library(bin_file)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/framework/load_library.py", line 61, in load_op_library
lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: /content/drive/MyDrive/boeing/brgm/brgm/dnnlib/tflib/_cudacache/fused_bias_act_237d55aca3e3c3ec0547da06888d8e66.so: undefined symbol: _ZN10tensorflow12OpDefBuilder4AttrENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
I found that the very last part of an error:
tensorflow.python.framework.errors_impl.NotFoundError: /content/drive/MyDrive/boeing/brgm/brgm/dnnlib/tflib/_cudacache/fused_bias_act_237d55aca3e3c3ec0547da06888d8e66.so: undefined symbol: _ZN10tensorflow12OpDefBuilder4AttrENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Can be solved by changing a flag in Cuda Makefile: https://github.com/mgharbi/hdrnet_legacy/issues/2 or by installing tf 1.14(colab runs on 1.15.2 and this change made no positive effect).
My question is, how can I get rid of this error, is there an option to change smth inside Google Colab's Cuda Makefile?

AttributeError: module 'tensorflow.python.pywrap_tensorflow' has no attribute 'TFE_MonitoringNewCounter0'

I'm using Rasa for a chatbot project and recently completed the installation. When I try to train my bot using the 'rasa train' command, it shows me this error and I cant seem to find a way to solve it.
I've reinstalled tensorflow as suggested on another forum, but it didnt make a difference
Traceback (most recent call last):
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Rithesh\Anaconda3_update\envs\tf_gpu\Scripts\rasa.exe\__main__.py", line 9, in <module>
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\rasa\__main__.py", line 69, in main
set_log_level(log_level)
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\rasa\utils\common.py", line 68, in set_log_level
update_tensorflow_log_level()
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\rasa\utils\common.py", line 87, in update_tensorflow_log_level
import tensorflow as tf
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow\__init__.py", line 29, in <module>
from tensorflow._api.v1 import compat
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow\_api\v1\compat\__init__.py", line 21, in <module>
from tensorflow._api.v1.compat import v1
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow\_api\v1\compat\v1\__init__.py", line 626, in <module>
child_package_str=('tensorflow_estimator.python.estimator.api.estimator'))
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow\python\tools\component_api_helper.py", line 56, in package_hook
child_pkg = importlib.import_module(child_package_str)
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow_estimator\__init__.py", line 8, in <module>
from tensorflow_estimator._api.v1 import estimator
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow_estimator\_api\v1\estimator\__init__.py", line 8, in <module>
from tensorflow_estimator._api.v1.estimator import experimental
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow_estimator\_api\v1\estimator\experimental\__init__.py", line 8, in <module>
from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow_estimator\python\estimator\__init__.py", line 25, in <module>
import tensorflow_estimator.python.estimator.estimator_lib
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow_estimator\python\estimator\estimator_lib.py", line 22, in <module>
from tensorflow_estimator.python.estimator.canned.baseline import BaselineClassifier
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow_estimator\python\estimator\canned\baseline.py", line 67, in <module>
from tensorflow_estimator.python.estimator import estimator
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 37, in <module>
from tensorflow.python.eager import monitoring
File "c:\users\rithesh\anaconda3_update\envs\tf_gpu\lib\site-packages\tensorflow\python\eager\monitoring.py", line 31, in <module>
create=pywrap_tensorflow.TFE_MonitoringNewCounter0,
AttributeError: module 'tensorflow.python.pywrap_tensorflow' has no attribute 'TFE_MonitoringNewCounter0'
Did you read this already?
AttributeError: module 'tensorflow.python.pywrap_tensorflow' has no attribute 'TFE_Py_RegisterExceptionClass'
In my experience a clean conda environment goes a long way. Also the order in which you type your conda install commands matters.

How to fix this "TypeError: __init__() missing 1 required positional argument: 'deprecated_to_canonical'?

I am new to Tensorflow and following this tutorial please help me to fix this
I don't what's wrong i can't undarstant why this error
$ python tfml.py
Traceback (most recent call last):
File "tfml.py", line 2, in <module>
import tensorflow as tf
File "C:\Users\rkria\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 34, in <module>
from tensorflow._api.v1 import compat
File "C:\Users\rkria\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\_api\v1\compat\__init__.py", line 21, in <module>
from tensorflow._api.v1.compat import v1
File "C:\Users\rkria\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\_api\v1\compat\v1\__init__.py", line 643, in <module>
'tensorflow_estimator.python.estimator.api._v1.estimator'))
File "C:\Users\rkria\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\tools\component_api_helper.py", line 56, in package_hook
child_pkg = importlib.import_module(child_package_str)
File "C:\Users\rkria\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\rkria\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\__init__.py", line 8, in <module>
from tensorflow_estimator._api.v1 import estimator
File "C:\Users\rkria\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\__init__.py", line 8, in <module>
from tensorflow_estimator._api.v1.estimator import experimental
File "C:\Users\rkria\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\experimental\__init__.py", line 29, in
<module>
_sys.modules[__name__], "estimator.experimental")
TypeError: __init__() missing 1 required positional argument: 'deprecated_to_canonical'

Tensorflow NotFoundError: data/mscoco_label_map.pbtxt; No such file or directory

I am trying to run this script from the YouTuber sentdex, but I get this error:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
The backend was *originally* set to 'TkAgg' by the following code:
File "Desktop/object.py", line 11, in <module>
from matplotlib import pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 71, in <module>
from matplotlib.backends import pylab_setup
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/__init__.py", line 16, in <module>
line for line in traceback.format_stack()
import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements
Traceback (most recent call last):
File "Desktop/object.py", line 86, in <module>
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/models/research/object_detection/utils/label_map_util.py", line 132, in load_labelmap
label_map_string = fid.read()
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 120, in read
self._preread_check()
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 80, in _preread_check
compat.as_bytes(self.__name), 1024 * 512, status)
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/python/framework/errors_impl.py", line 519, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: data/mscoco_label_map.pbtxt; No such file or directory
OS: Ubuntu 18.04
Python: 2.7
Could you please help me ?
It would help immensly if you provided the file/function you called to produce the traceback. However, in absence of that and based on the below:
tensorflow.python.framework.errors_impl.NotFoundError: data/mscoco_label_map.pbtxt; No such file or directory
The *_label_map.pbtxt path is specified in two lines of the model.config file (exact line numbers depends on the model you chose). It appears one or both the training/test file paths are incorrect.