Medpy AttributeError:“张量”对象没有属性“astype”

Ray*_*han 3 python keras tensorflow

您好,我正在尝试使用 Medpy 以及最新的 keras 和 tensorflow 库来计算平均表面距离(asd)。感谢这方面的任何帮助。这是我的代码和错误:

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)
Run Code Online (Sandbox Code Playgroud)

错误:

文件“/home/rak038/Segmentation/U-net/noGPU/noGPU/lib/python3.7/site-packages/medpy/metric/binary.py”,第 1200 行,在 __surface_distances 中

result = numpy.atleast_1d(result.astype(numpy.bool))
Run Code Online (Sandbox Code Playgroud)

AttributeError:“张量”对象没有属性“astype”

Mea*_*eet 5

astype是一个 Numpy 函数。这里我猜result是 a tf.Tensor,所以你需要使用tf.cast来更改它的类型(参见https://www.tensorflow.org/api_docs/python/tf/cast)。