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

Question:

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?

Asked By: Atul Balaji

||

Answers:

It sounds like this is perhaps the same problem as can be found in the Theano issues tracker 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).

Answered By: ryanjdillon

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
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.