cls_transforms.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from .ops import *
  15. from .imgaug_support import execute_imgaug
  16. import random
  17. import os.path as osp
  18. import numpy as np
  19. from PIL import Image, ImageEnhance
  20. import paddlex.utils.logging as logging
  21. class ClsTransform:
  22. """分类Transform的基类
  23. """
  24. def __init__(self):
  25. pass
  26. class Compose(ClsTransform):
  27. """根据数据预处理/增强算子对输入数据进行操作。
  28. 所有操作的输入图像流形状均是[H, W, C],其中H为图像高,W为图像宽,C为图像通道数。
  29. Args:
  30. transforms (list): 数据预处理/增强算子。
  31. Raises:
  32. TypeError: 形参数据类型不满足需求。
  33. ValueError: 数据长度不匹配。
  34. """
  35. def __init__(self, transforms):
  36. if not isinstance(transforms, list):
  37. raise TypeError('The transforms must be a list!')
  38. if len(transforms) < 1:
  39. raise ValueError('The length of transforms ' + \
  40. 'must be equal or larger than 1!')
  41. self.transforms = transforms
  42. self.batch_transforms = None
  43. self.data_type = np.uint8
  44. self.to_rgb = True
  45. # 检查transforms里面的操作,目前支持PaddleX定义的或者是imgaug操作
  46. for op in self.transforms:
  47. if not isinstance(op, ClsTransform):
  48. import imgaug.augmenters as iaa
  49. if not isinstance(op, iaa.Augmenter):
  50. raise Exception(
  51. "Elements in transforms should be defined in 'paddlex.cls.transforms' or class of imgaug.augmenters.Augmenter, see docs here: https://paddlex.readthedocs.io/zh_CN/latest/apis/transforms/"
  52. )
  53. def __call__(self, im_file, label=None):
  54. """
  55. Args:
  56. im (str/np.ndarray): 图像路径/图像np.ndarray数据。
  57. label (int): 每张图像所对应的类别序号。
  58. Returns:
  59. tuple: 根据网络所需字段所组成的tuple;
  60. 字段由transforms中的最后一个数据预处理操作决定。
  61. """
  62. input_channel = getattr(self, 'input_channel', 3)
  63. if isinstance(im_file, np.ndarray):
  64. if len(im_file.shape) != 3:
  65. raise Exception(
  66. "im should be 3-dimension, but now is {}-dimensions".
  67. format(len(im_file.shape)))
  68. else:
  69. try:
  70. if input_channel == 3:
  71. im = cv2.imread(im_file, cv2.IMREAD_ANYDEPTH |
  72. cv2.IMREAD_ANYCOLOR | cv2.IMREAD_COLOR)
  73. else:
  74. im = cv2.imread(im_file, cv2.IMREAD_ANYDEPTH |
  75. cv2.IMREAD_ANYCOLOR)
  76. if im.ndim < 3:
  77. im = np.expand_dims(im, axis=-1)
  78. except:
  79. raise TypeError('Can\'t read The image file {}!'.format(
  80. im_file))
  81. self.data_type = im.dtype
  82. im = im.astype('float32')
  83. if input_channel == 3 and self.to_rgb:
  84. im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
  85. for op in self.transforms:
  86. if isinstance(op, ClsTransform):
  87. if op.__class__.__name__ == 'RandomDistort':
  88. op.to_rgb = self.to_rgb
  89. op.data_type = self.data_type
  90. outputs = op(im, label)
  91. im = outputs[0]
  92. if len(outputs) == 2:
  93. label = outputs[1]
  94. else:
  95. import imgaug.augmenters as iaa
  96. if im.shape[-1] != 3:
  97. raise Exception(
  98. "Only the 3-channel RGB image is supported in the imgaug operator, but recieved image channel is {}".
  99. format(im.shape[-1]))
  100. if isinstance(op, iaa.Augmenter):
  101. im = execute_imgaug(op, im)
  102. outputs = (im, )
  103. if label is not None:
  104. outputs = (im, label)
  105. return outputs
  106. def add_augmenters(self, augmenters):
  107. if not isinstance(augmenters, list):
  108. raise Exception(
  109. "augmenters should be list type in func add_augmenters()")
  110. transform_names = [type(x).__name__ for x in self.transforms]
  111. for aug in augmenters:
  112. if type(aug).__name__ in transform_names:
  113. logging.error(
  114. "{} is already in ComposedTransforms, need to remove it from add_augmenters().".
  115. format(type(aug).__name__))
  116. self.transforms = augmenters + self.transforms
  117. class RandomCrop(ClsTransform):
  118. """对图像进行随机剪裁,模型训练时的数据增强操作。
  119. 1. 根据lower_scale、lower_ratio、upper_ratio计算随机剪裁的高、宽。
  120. 2. 根据随机剪裁的高、宽随机选取剪裁的起始点。
  121. 3. 剪裁图像。
  122. 4. 调整剪裁后的图像的大小到crop_size*crop_size。
  123. Args:
  124. crop_size (int): 随机裁剪后重新调整的目标边长。默认为224。
  125. lower_scale (float): 裁剪面积相对原面积比例的最小限制。默认为0.08。
  126. lower_ratio (float): 宽变换比例的最小限制。默认为3. / 4。
  127. upper_ratio (float): 宽变换比例的最大限制。默认为4. / 3。
  128. """
  129. def __init__(self,
  130. crop_size=224,
  131. lower_scale=0.08,
  132. lower_ratio=3. / 4,
  133. upper_ratio=4. / 3):
  134. self.crop_size = crop_size
  135. self.lower_scale = lower_scale
  136. self.lower_ratio = lower_ratio
  137. self.upper_ratio = upper_ratio
  138. def __call__(self, im, label=None):
  139. """
  140. Args:
  141. im (np.ndarray): 图像np.ndarray数据。
  142. label (int): 每张图像所对应的类别序号。
  143. Returns:
  144. tuple: 当label为空时,返回的tuple为(im, ),对应图像np.ndarray数据;
  145. 当label不为空时,返回的tuple为(im, label),分别对应图像np.ndarray数据、图像类别id。
  146. """
  147. im = random_crop(im, self.crop_size, self.lower_scale,
  148. self.lower_ratio, self.upper_ratio)
  149. if label is None:
  150. return (im, )
  151. else:
  152. return (im, label)
  153. class RandomHorizontalFlip(ClsTransform):
  154. """以一定的概率对图像进行随机水平翻转,模型训练时的数据增强操作。
  155. Args:
  156. prob (float): 随机水平翻转的概率。默认为0.5。
  157. """
  158. def __init__(self, prob=0.5):
  159. self.prob = prob
  160. def __call__(self, im, label=None):
  161. """
  162. Args:
  163. im (np.ndarray): 图像np.ndarray数据。
  164. label (int): 每张图像所对应的类别序号。
  165. Returns:
  166. tuple: 当label为空时,返回的tuple为(im, ),对应图像np.ndarray数据;
  167. 当label不为空时,返回的tuple为(im, label),分别对应图像np.ndarray数据、图像类别id。
  168. """
  169. if random.random() < self.prob:
  170. im = horizontal_flip(im)
  171. if label is None:
  172. return (im, )
  173. else:
  174. return (im, label)
  175. class RandomVerticalFlip(ClsTransform):
  176. """以一定的概率对图像进行随机垂直翻转,模型训练时的数据增强操作。
  177. Args:
  178. prob (float): 随机垂直翻转的概率。默认为0.5。
  179. """
  180. def __init__(self, prob=0.5):
  181. self.prob = prob
  182. def __call__(self, im, label=None):
  183. """
  184. Args:
  185. im (np.ndarray): 图像np.ndarray数据。
  186. label (int): 每张图像所对应的类别序号。
  187. Returns:
  188. tuple: 当label为空时,返回的tuple为(im, ),对应图像np.ndarray数据;
  189. 当label不为空时,返回的tuple为(im, label),分别对应图像np.ndarray数据、图像类别id。
  190. """
  191. if random.random() < self.prob:
  192. im = vertical_flip(im)
  193. if label is None:
  194. return (im, )
  195. else:
  196. return (im, label)
  197. class Normalize(ClsTransform):
  198. """对图像进行标准化。
  199. 1.像素值减去min_val
  200. 2.像素值除以(max_val-min_val)
  201. 3.对图像进行减均值除以标准差操作。
  202. Args:
  203. mean (list): 图像数据集的均值。默认值[0.5, 0.5, 0.5]。
  204. std (list): 图像数据集的标准差。默认值[0.5, 0.5, 0.5]。
  205. min_val (list): 图像数据集的最小值。默认值[0, 0, 0]。
  206. max_val (list): 图像数据集的最大值。默认值[255.0, 255.0, 255.0]。
  207. Raises:
  208. ValueError: mean或std不是list对象。std包含0。
  209. """
  210. def __init__(self,
  211. mean=[0.485, 0.456, 0.406],
  212. std=[0.229, 0.224, 0.225],
  213. min_val=[0, 0, 0],
  214. max_val=[255.0, 255.0, 255.0]):
  215. self.mean = mean
  216. self.std = std
  217. self.min_val = min_val
  218. self.max_val = max_val
  219. if not (isinstance(self.mean, list) and isinstance(self.std, list)):
  220. raise ValueError("{}: input type is invalid.".format(self))
  221. if not (isinstance(self.min_val, list) and isinstance(self.max_val,
  222. list)):
  223. raise ValueError("{}: input type is invalid.".format(self))
  224. from functools import reduce
  225. if reduce(lambda x, y: x * y, self.std) == 0:
  226. raise ValueError('{}: std is invalid!'.format(self))
  227. def __call__(self, im, label=None):
  228. """
  229. Args:
  230. im (np.ndarray): 图像np.ndarray数据。
  231. label (int): 每张图像所对应的类别序号。
  232. Returns:
  233. tuple: 当label为空时,返回的tuple为(im, ),对应图像np.ndarray数据;
  234. 当label不为空时,返回的tuple为(im, label),分别对应图像np.ndarray数据、图像类别id。
  235. """
  236. mean = np.array(self.mean)[np.newaxis, np.newaxis, :]
  237. std = np.array(self.std)[np.newaxis, np.newaxis, :]
  238. im = normalize(im, mean, std, self.min_val, self.max_val)
  239. if label is None:
  240. return (im, )
  241. else:
  242. return (im, label)
  243. class ResizeByShort(ClsTransform):
  244. """根据图像短边对图像重新调整大小(resize)。
  245. 1. 获取图像的长边和短边长度。
  246. 2. 根据短边与short_size的比例,计算长边的目标长度,
  247. 此时高、宽的resize比例为short_size/原图短边长度。
  248. 3. 如果max_size>0,调整resize比例:
  249. 如果长边的目标长度>max_size,则高、宽的resize比例为max_size/原图长边长度;
  250. 4. 根据调整大小的比例对图像进行resize。
  251. Args:
  252. short_size (int): 调整大小后的图像目标短边长度。默认为256。
  253. max_size (int): 长边目标长度的最大限制。默认为-1。
  254. """
  255. def __init__(self, short_size=256, max_size=-1):
  256. self.short_size = short_size
  257. self.max_size = max_size
  258. def __call__(self, im, label=None):
  259. """
  260. Args:
  261. im (np.ndarray): 图像np.ndarray数据。
  262. label (int): 每张图像所对应的类别序号。
  263. Returns:
  264. tuple: 当label为空时,返回的tuple为(im, ),对应图像np.ndarray数据;
  265. 当label不为空时,返回的tuple为(im, label),分别对应图像np.ndarray数据、图像类别id。
  266. """
  267. im_short_size = min(im.shape[0], im.shape[1])
  268. im_long_size = max(im.shape[0], im.shape[1])
  269. scale = float(self.short_size) / im_short_size
  270. if self.max_size > 0 and np.round(scale *
  271. im_long_size) > self.max_size:
  272. scale = float(self.max_size) / float(im_long_size)
  273. resized_width = int(round(im.shape[1] * scale))
  274. resized_height = int(round(im.shape[0] * scale))
  275. im = cv2.resize(
  276. im, (resized_width, resized_height),
  277. interpolation=cv2.INTER_LINEAR)
  278. if label is None:
  279. return (im, )
  280. else:
  281. return (im, label)
  282. class CenterCrop(ClsTransform):
  283. """以图像中心点扩散裁剪长宽为`crop_size`的正方形
  284. 1. 计算剪裁的起始点。
  285. 2. 剪裁图像。
  286. Args:
  287. crop_size (int): 裁剪的目标边长。默认为224。
  288. """
  289. def __init__(self, crop_size=224):
  290. self.crop_size = crop_size
  291. def __call__(self, im, label=None):
  292. """
  293. Args:
  294. im (np.ndarray): 图像np.ndarray数据。
  295. label (int): 每张图像所对应的类别序号。
  296. Returns:
  297. tuple: 当label为空时,返回的tuple为(im, ),对应图像np.ndarray数据;
  298. 当label不为空时,返回的tuple为(im, label),分别对应图像np.ndarray数据、图像类别id。
  299. """
  300. im = center_crop(im, self.crop_size)
  301. if label is None:
  302. return (im, )
  303. else:
  304. return (im, label)
  305. class RandomRotate(ClsTransform):
  306. def __init__(self, rotate_range=30, prob=0.5):
  307. """以一定的概率对图像在[-rotate_range, rotaterange]角度范围内进行旋转,模型训练时的数据增强操作。
  308. Args:
  309. rotate_range (int): 旋转度数的范围。默认为30。
  310. prob (float): 随机旋转的概率。默认为0.5。
  311. """
  312. self.rotate_range = rotate_range
  313. self.prob = prob
  314. def __call__(self, im, label=None):
  315. """
  316. Args:
  317. im (np.ndarray): 图像np.ndarray数据。
  318. label (int): 每张图像所对应的类别序号。
  319. Returns:
  320. tuple: 当label为空时,返回的tuple为(im, ),对应图像np.ndarray数据;
  321. 当label不为空时,返回的tuple为(im, label),分别对应图像np.ndarray数据、图像类别id。
  322. """
  323. rotate_lower = -self.rotate_range
  324. rotate_upper = self.rotate_range
  325. im = im.astype('uint8')
  326. im = Image.fromarray(im)
  327. if np.random.uniform(0, 1) < self.prob:
  328. im = rotate(im, rotate_lower, rotate_upper)
  329. im = np.asarray(im).astype('float32')
  330. if label is None:
  331. return (im, )
  332. else:
  333. return (im, label)
  334. class RandomDistort(ClsTransform):
  335. """以一定的概率对图像进行随机像素内容变换,模型训练时的数据增强操作
  336. 1. 对变换的操作顺序进行随机化操作。
  337. 2. 按照1中的顺序以一定的概率对图像进行随机像素内容变换。
  338. 【注意】如果输入是uint8/uint16的RGB图像,该数据增强必须在数据增强Normalize之前使用。
  339. Args:
  340. brightness_range (float): 明亮度的缩放系数范围。
  341. 从[1-`brightness_range`, 1+`brightness_range`]中随机取值作为明亮度缩放因子`scale`,
  342. 按照公式`image = image * scale`调整图像明亮度。默认值为0.9。
  343. brightness_prob (float): 随机调整明亮度的概率。默认为0.5。
  344. contrast_range (float): 对比度的缩放系数范围。
  345. 从[1-`contrast_range`, 1+`contrast_range`]中随机取值作为对比度缩放因子`scale`,
  346. 按照公式`image = image * scale + (image_mean + 0.5) * (1 - scale)`调整图像对比度。默认为0.9。
  347. contrast_prob (float): 随机调整对比度的概率。默认为0.5。
  348. saturation_range (float): 饱和度的缩放系数范围。
  349. 从[1-`saturation_range`, 1+`saturation_range`]中随机取值作为饱和度缩放因子`scale`,
  350. 按照公式`image = gray * (1 - scale) + image * scale`,
  351. 其中`gray = R * 299/1000 + G * 587/1000+ B * 114/1000`。默认为0.9。
  352. saturation_prob (float): 随机调整饱和度的概率。默认为0.5。
  353. hue_range (int): 调整色相角度的差值取值范围。
  354. 从[-`hue_range`, `hue_range`]中随机取值作为色相角度调整差值`delta`,
  355. 按照公式`hue = hue + delta`调整色相角度 。默认为18,取值范围[0, 360]。
  356. hue_prob (float): 随机调整色调的概率。默认为0.5。
  357. """
  358. def __init__(self,
  359. brightness_range=0.9,
  360. brightness_prob=0.5,
  361. contrast_range=0.9,
  362. contrast_prob=0.5,
  363. saturation_range=0.9,
  364. saturation_prob=0.5,
  365. hue_range=18,
  366. hue_prob=0.5):
  367. self.brightness_range = brightness_range
  368. self.brightness_prob = brightness_prob
  369. self.contrast_range = contrast_range
  370. self.contrast_prob = contrast_prob
  371. self.saturation_range = saturation_range
  372. self.saturation_prob = saturation_prob
  373. self.hue_range = hue_range
  374. self.hue_prob = hue_prob
  375. def __call__(self, im, label=None):
  376. """
  377. Args:
  378. im (np.ndarray): 图像np.ndarray数据。
  379. label (int): 每张图像所对应的类别序号。
  380. Returns:
  381. tuple: 当label为空时,返回的tuple为(im, ),对应图像np.ndarray数据;
  382. 当label不为空时,返回的tuple为(im, label),分别对应图像np.ndarray数据、图像类别id。
  383. """
  384. if im.shape[-1] != 3:
  385. raise Exception(
  386. "Only the 3-channel RGB image is supported in the RandomDistort operator, but recieved image channel is {}".
  387. format(im.shape[-1]))
  388. if self.data_type not in [np.uint8, np.uint16, np.float32]:
  389. raise Exception(
  390. "Only the uint8/uint16/float32 RGB image is supported in the RandomDistort operator, but recieved image data type is {}".
  391. format(self.data_type))
  392. brightness_lower = 1 - self.brightness_range
  393. brightness_upper = 1 + self.brightness_range
  394. contrast_lower = 1 - self.contrast_range
  395. contrast_upper = 1 + self.contrast_range
  396. saturation_lower = 1 - self.saturation_range
  397. saturation_upper = 1 + self.saturation_range
  398. hue_lower = -self.hue_range
  399. hue_upper = self.hue_range
  400. ops = [brightness, contrast, saturation, hue]
  401. random.shuffle(ops)
  402. params_dict = {
  403. 'brightness': {
  404. 'brightness_lower': brightness_lower,
  405. 'brightness_upper': brightness_upper,
  406. },
  407. 'contrast': {
  408. 'contrast_lower': contrast_lower,
  409. 'contrast_upper': contrast_upper,
  410. },
  411. 'saturation': {
  412. 'saturation_lower': saturation_lower,
  413. 'saturation_upper': saturation_upper,
  414. 'is_rgb': self.to_rgb,
  415. },
  416. 'hue': {
  417. 'hue_lower': hue_lower,
  418. 'hue_upper': hue_upper,
  419. 'is_rgb': self.to_rgb,
  420. }
  421. }
  422. prob_dict = {
  423. 'brightness': self.brightness_prob,
  424. 'contrast': self.contrast_prob,
  425. 'saturation': self.saturation_prob,
  426. 'hue': self.hue_prob,
  427. }
  428. for id in range(len(ops)):
  429. params = params_dict[ops[id].__name__]
  430. prob = prob_dict[ops[id].__name__]
  431. params['im'] = im
  432. if np.random.uniform(0, 1) < prob:
  433. im = ops[id](**params)
  434. im = im.astype('float32')
  435. if label is None:
  436. return (im, )
  437. else:
  438. return (im, label)
  439. class ArrangeClassifier(ClsTransform):
  440. """获取训练/验证/预测所需信息。注意:此操作不需用户自己显示调用
  441. Args:
  442. mode (str): 指定数据用于何种用途,取值范围为['train', 'eval', 'test', 'quant']。
  443. Raises:
  444. ValueError: mode的取值不在['train', 'eval', 'test', 'quant']之内。
  445. """
  446. def __init__(self, mode=None):
  447. if mode not in ['train', 'eval', 'test', 'quant']:
  448. raise ValueError(
  449. "mode must be in ['train', 'eval', 'test', 'quant']!")
  450. self.mode = mode
  451. def __call__(self, im, label=None):
  452. """
  453. Args:
  454. im (np.ndarray): 图像np.ndarray数据。
  455. label (int): 每张图像所对应的类别序号。
  456. Returns:
  457. tuple: 当mode为'train'或'eval'时,返回(im, label),分别对应图像np.ndarray数据、
  458. 图像类别id;当mode为'test'或'quant'时,返回(im, ),对应图像np.ndarray数据。
  459. """
  460. im = permute(im, False).astype('float32')
  461. if self.mode == 'train' or self.mode == 'eval':
  462. outputs = (im, label)
  463. else:
  464. outputs = (im, )
  465. return outputs
  466. class ComposedClsTransforms(Compose):
  467. """ 分类模型的基础Transforms流程,具体如下
  468. 训练阶段:
  469. 1. 随机从图像中crop一块子图,并resize成crop_size大小
  470. 2. 将1的输出按0.5的概率随机进行水平翻转
  471. 3. 将图像进行归一化
  472. 验证/预测阶段:
  473. 1. 将图像按比例Resize,使得最小边长度为crop_size[0] * 1.14
  474. 2. 从图像中心crop出一个大小为crop_size的图像
  475. 3. 将图像进行归一化
  476. Args:
  477. mode(str): 图像处理流程所处阶段,训练/验证/预测,分别对应'train', 'eval', 'test'
  478. crop_size(int|list): 输入模型里的图像大小
  479. mean(list): 图像均值
  480. std(list): 图像方差
  481. random_horizontal_flip(bool): 是否以0.5的概率使用随机水平翻转增强,该仅在mode为`train`时生效,默认为True
  482. """
  483. def __init__(self,
  484. mode,
  485. crop_size=[224, 224],
  486. mean=[0.485, 0.456, 0.406],
  487. std=[0.229, 0.224, 0.225],
  488. random_horizontal_flip=True):
  489. width = crop_size
  490. if isinstance(crop_size, list):
  491. if crop_size[0] != crop_size[1]:
  492. raise Exception(
  493. "In classifier model, width and height should be equal, please modify your parameter `crop_size`"
  494. )
  495. width = crop_size[0]
  496. if width % 32 != 0:
  497. raise Exception(
  498. "In classifier model, width and height should be multiple of 32, e.g 224、256、320...., please modify your parameter `crop_size`"
  499. )
  500. if mode == 'train':
  501. # 训练时的transforms,包含数据增强
  502. transforms = [
  503. RandomCrop(crop_size=width), Normalize(
  504. mean=mean, std=std)
  505. ]
  506. if random_horizontal_flip:
  507. transforms.insert(0, RandomHorizontalFlip())
  508. else:
  509. # 验证/预测时的transforms
  510. transforms = [
  511. ResizeByShort(short_size=int(width * 1.14)),
  512. CenterCrop(crop_size=width), Normalize(
  513. mean=mean, std=std)
  514. ]
  515. super(ComposedClsTransforms, self).__init__(transforms)