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?
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).
invert
function can be applied only to np.bool arrays.
According to U-net repo call hierarchy is like that:
- _load_data_and_label: prepare all the data
- _next_data: load data (as np.float32) and (important) load labels as
np.bool
- _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)
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?
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).
invert
function can be applied only to np.bool arrays.
According to U-net repo call hierarchy is like that:
- _load_data_and_label: prepare all the data
- _next_data: load data (as np.float32) and (important) load labels as
np.bool
- _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)