1
votes

Hello i am trying to calculate average surface distance (asd) using Medpy with latest libraries of keras and tensorflow. Any help in this regard is appreciated. Here is my code and error:

from medpy import metric as M

asd=M.binary.asd(tf.cast(y_pred, np.float32),tf.cast(y_true, np.float32),voxelspacing=None,connectivity=1)

Error:

File "/home/rak038/Segmentation/U-net/noGPU/noGPU/lib/python3.7/site-packages/medpy/metric/binary.py", line 1200, in __surface_distances

result = numpy.atleast_1d(result.astype(numpy.bool))

AttributeError: 'Tensor' object has no attribute 'astype'

2
have you solved your issue? - MeanStreet

2 Answers

4
votes

astype is a Numpy function. Here I guess result is a tf.Tensor, so you need to use tf.cast to change its type instead (see https://www.tensorflow.org/api_docs/python/tf/cast).

0
votes

tensor.numpy() can change your type from tensor to numpy, it will have the attribute astype