Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'tensorflow' has no attribute 'py_func'

I'm trying to run a code on ubuntu that uses tensorflow, it gives me the error:

AttributeError: module 'tensorflow' has no attribute 'py_func'

how can I fix it?
the relevant part of the code:

for i in range(cfg.num_layers):
  neighbour_idx = tf.py_func(DP.knn_search, [batch_xyz, batch_xyz, cfg.k_n], tf.int32)
  sub_points = batch_xyz[:, :tf.shape(batch_xyz)[1] // cfg.sub_sampling_ratio[i], :]
  pool_i = neighbour_idx[:, :tf.shape(batch_xyz)[1] // cfg.sub_sampling_ratio[i], :]
  up_i = tf.py_func(DP.knn_search, [sub_points, batch_xyz, 1], tf.int32)
  input_points.append(batch_xyz)
  input_neighbors.append(neighbour_idx)
  input_pools.append(pool_i)
  input_up_samples.append(up_i)
  batch_xyz = sub_points

input_list = input_points + input_neighbors + input_pools + input_up_samples
input_list += [batch_features, batch_labels, batch_pc_idx, batch_cloud_idx]

It can't get the tf.py_func.

PS: I tried adding tf.compat.v1.py_func and it didn't work.

like image 506
youssef Avatar asked Aug 16 '26 14:08

youssef


1 Answers

tf.py_func is designed for Tensorflow 1.

In Tensorflow 2,tf.numpy_function is a near-exact replacement, just drop the stateful argument (all tf.numpy_function calls are considered stateful). It is compatible with eager execution and tf.function.

tf.py_function is a close but not an exact replacement, passing TensorFlow tensors to the wrapped function instead of NumPy arrays, which provides gradients and can take advantage of accelerators.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!