Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'

like image 704
Rayyan Khan Avatar asked Oct 23 '25 15:10

Rayyan Khan


2 Answers

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).

like image 143
MeanStreet Avatar answered Oct 26 '25 04:10

MeanStreet


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

like image 26
Astrosolar Avatar answered Oct 26 '25 04:10

Astrosolar



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!