TypeError: ufunc ‘true_divide‘ output (typecode ‘d‘) could not be coerced to provided outp
图片预处理经常用到的一句代码:……if mode == 'tf':x /= 127.5x -= 1.if x.ndim == 3:x = np.expand_dims(x, 0)return xif mode == 'custom':x /= 255if x.ndim == 3:x = np.expand_dims(x
·
深度学习中图片处理经常用到的预处理代码:
……
if mode == 'tf':
x /= 127.5
x -= 1.
if x.ndim == 3:
x = np.expand_dims(x, 0)
return x
if mode == 'custom':
x /= 255
if x.ndim == 3:
x = np.expand_dims(x, 0)
return x
if mode == 'torch':
x /= 255.
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
在之前要加一句类型转换,否则会报错:TypeError: ufunc ‘true_divide’ output (typecode ‘d’) could not be coerced to provided output parameter (typecode ‘B’) according to the casting rule ‘‘same_kind’’
x = x.astype(np.float32)
更多推荐
所有评论(0)