tf.image.ssim() not accepting 'return_index_map' argument - tensorflow

The documentation for Tensorflow's tf.image.ssim() says that if you want to return an element-wise structural similarity map, you can set "return_index_map" to True. It is returning an error when I define the argument as either True or False. I am running Tensorflow 2.10 on an Apple M1 Max.
When I run:
import tensorflow as tf
a = tf.ones((20, 20, 20, 20))
b = tf.zeros((20, 20, 20, 20))
sim = tf.image.ssim(a, b, max_val=1, return_index_map=True)
I get the error:
Traceback (most recent call last):
File "/Users/miguel/opt/miniconda3/envs/py39_tensorflow/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3433, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-967be677c86c>", line 1, in <module>
sim = tf.image.ssim(a, b, max_val=1, return_index_map=True)
File "/Users/miguel/opt/miniconda3/envs/py39_tensorflow/lib/python3.9/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/Users/miguel/opt/miniconda3/envs/py39_tensorflow/lib/python3.9/site-packages/tensorflow/python/util/dispatch.py", line 1170, in op_dispatch_handler
result = api_dispatcher.Dispatch(args, kwargs)
TypeError: Got an unexpected keyword argument 'return_index_map'

Related

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?

RuntimeError: Resize coordinate_transformation_mode=pytorch_half_pixel is not supported in 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.

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 Error when using tf.gradients and tf.hessian: TypeError: Fetch argument None has invalid type <type 'NoneType'>

I just started learning tensorflow and came across the following error when using the tf.gradients and tf.hessain functions. Given below is the code and error for tf.gradients.
import tensorflow as tf
a = tf.placeholder(tf.float32,shape = (2,2))
b = [[1.0,2.0],[3.0,4.0]]
c = a[0,0]*a[0,1]*a[1,0] + a[0,1]*a[1,0]*a[1,1]
e = tf.reshape(b,[4])
d = tf.gradients(c,e)
sess = tf.Session()
print(sess.run(d,feed_dict={a:b}))
I get the following error for the last line
>>> print(sess.run(d,feed_dict={a:b}))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/share/apps/tensorflow/20170218/python2.7/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 767, in run
run_metadata_ptr)
File "/share/apps/tensorflow/20170218/python2.7/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 952, in _run
fetch_handler = _FetchHandler(self._graph, fetches, feed_dict_string)
File "/share/apps/tensorflow/20170218/python2.7/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 408, in __init__
self._fetch_mapper = _FetchMapper.for_fetch(fetches)
File "/share/apps/tensorflow/20170218/python2.7/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 230, in for_fetch
return _ListFetchMapper(fetch)
File "/share/apps/tensorflow/20170218/python2.7/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 337, in __init__
self._mappers = [_FetchMapper.for_fetch(fetch) for fetch in fetches]
File "/share/apps/tensorflow/20170218/python2.7/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 227, in for_fetch
(fetch, type(fetch)))
TypeError: Fetch argument None has invalid type <type 'NoneType'>
any ideas as to how I can debug this?
It is because c is calculated based on a, not e. You could change the line of gradient tensor as below.
d = tf.gradients(c,a)
BTW, in your original code, if you print d, you will find it is a [None]

type matching error in tensor

I am following a Tensorflow example. However, running the code gives me the following error message.
It seems to me that the following code segment causes the problem. Or the last dimension of h_conv10 has float64. But there is no place where float64 is setup explicitly. Thank you for the suggestions and hints.
# Deconvolution 1
W_deconv_1 = weight_variable_devonc([max_pool_size, max_pool_size, 8*chanel_root, 16*chanel_root])
b_deconv1 = bias_variable([8*chanel_root])
h_deconv1 = tf.nn.relu(deconv2d(h_conv10, W_deconv_1, max_pool_size) + b_deconv1)
h_deconv1_concat = crop_and_concat(h_conv8,h_deconv1,[n_image,(((nx-180)/2+4)/2+4)/2+4,(((ny-180)/2+4)/2+4)/2+4,8*chanel_root])
python u-net.py
Traceback (most recent call last):
File "/experiment/tfw/lib/python3.4/site-
packages/tensorflow/python/ops/op_def_library.py", line 377, in apply_op
as_ref=input_arg.is_ref)
File "/experiment/tfw/lib/python3.4/site-
packages/tensorflow/python/framework/ops.py", line 608, in convert_n_to_tensor
ret.append(convert_to_tensor(value, dtype=dtype, name=n, as_ref=as_ref))
File "/experiment/tfw/lib/python3.4/site-
packages/tensorflow/python/framework/ops.py", line 566, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/experiment/tfw/lib/python3.4/site-
packages/tensorflow/python/framework/ops.py", line 510, in
_TensorTensorConversionFunction
% (dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype
float64: 'Tensor("truediv:0", shape=(), dtype=float64)'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "u-net.py", line 193, in <module>
h_deconv1 = tf.nn.relu(deconv2d(h_conv10, W_deconv_1, max_pool_size) + b_deconv1)
File "u-net.py", line 77, in deconv2d
output_shape = tf.pack([tf.shape(x)[0], tf.shape(x)[1]*2, tf.shape(x)[2]*2, tf.shape(x)[3]/2])
File "/experiment/tfw/lib/python3.4/site-packages/tensorflow/python/ops/array_ops.py", line 241, in pack
return gen_array_ops._pack(values, name=name)
File "/experiment/tfw/lib/python3.4/site-packages/tensorflow/python/ops/gen_array_ops.py", line 916, in _pack
return _op_def_lib.apply_op("Pack", values=values, name=name)
File "/experiment/tfw/lib/python3.4/site-packages/tensorflow/python/ops/op_def_library.py", line 396, in apply_op
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'Pack' Op have types [int32, int32, int32, float64] that don't all match.