【问题标题】:Medpy AttributeError: 'Tensor' object has no attribute 'astype'Medpy AttributeError:“张量”对象没有属性“astype”
【发布时间】:2020-03-03 15:26:45
【问题描述】:

您好,我正在尝试使用 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)

错误:

文件“/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))

AttributeError: 'Tensor' 对象没有属性 'astype'

【问题讨论】:

  • 你的问题解决了吗?

标签: python tensorflow keras


【解决方案1】:

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

【讨论】:

  • 我已经使用 tf.cast 更改了它的数据类型,但问题仍然存在
  • result 是什么类型?
【解决方案2】:

tensor.numpy() 可以将你的类型从张量更改为numpy,它将具有属性astype

【讨论】:

    猜你喜欢
    • 2019-12-07
    • 2020-10-22
    • 2019-02-20
    • 2017-12-06
    • 2018-07-02
    相关资源
    最近更新 更多