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

Issue

I have cloned the repository for U-net with tensorflow.

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

I get an error in the 3rd line saying:

TypeError: ufunc ‘invert‘ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ”safe

How do I debug this?

Solution

invert function can be applied only to np.bool arrays.

According to U-net repo call hierarchy is like that:

  1. _load_data_and_label: prepare all the data
  2. _next_data: load data (as np.float32) and (important) load labels as np.bool
  3. _load_file: please check that resulting array is really of np.bool.

E.g.:

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)

Answered By – Ilya Chidyakin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published