本文共 590 字,大约阅读时间需要 1 分钟。
深度学习中图片处理经常用到的预处理代码:
…… 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)
转载地址:http://jarti.baihongyu.com/