3

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.

2

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.