cls_transforms.py 23 KB

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