TypeError: ufunc 'invert' not supported for input types,

TypeError: ufunc 'invert' not supported for input types,

我已经用 tensorflow 克隆了 U-net 的存储库。

        labels = np.zeros((ny, nx, self.n_class), dtype=np.float32)
        labels[..., 1] = label
        labels[..., 0] = ~label

我在第 3 行收到一条错误消息:

TypeError: 输入类型不支持 ufunc 'invert',输入无法安全地强制转换为任何支持的类型根据铸造规则 ''safe''

我该如何调试?

听起来这可能与 Theano 问题跟踪器 here 中发现的问题相同。

The error comes from numpy and is from the fact that you are mixing symbolic (Theano) and numeric (scipy) code. This will not work.

If you want to use a scipy function in theano you have to wrap it up as an op (maybe with @as_op http://deeplearning.net/software/theano/library/compile/ops.html#theano.compile.ops.as_op).

invert 函数只能应用于 np.bool 个数组。

根据 U-net repo 调用层次结构是这样的:

  1. _load_data_and_label: 准备所有数据
  2. _next_data:加载数据(作为 np.float32)和 (重要) 将标签加载为 np.bool
  3. _load_file:请检查结果数组是否真的是 np.bool.

例如:

def _load_file(self, path, dtype=np.float32):
    img = Image.open(path)
    img = np.array(img, dtype=np.float32)
    img = cv2.copyMakeBorder(img, top=self.border, bottom=self.border, left=self.border, right=self.border, borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0])
    return np.array(img, dtype)