Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

presets.py 1.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  1. import torch
  2. from torchvision.transforms import transforms
  3. from transforms import ConvertBCHWtoCBHW
  4. class VideoClassificationPresetTrain:
  5. def __init__(
  6. self,
  7. *,
  8. crop_size,
  9. resize_size,
  10. mean=(0.43216, 0.394666, 0.37645),
  11. std=(0.22803, 0.22145, 0.216989),
  12. hflip_prob=0.5,
  13. ):
  14. trans = [
  15. transforms.ConvertImageDtype(torch.float32),
  16. # We hard-code antialias=False to preserve results after we changed
  17. # its default from None to True (see
  18. # https://github.com/pytorch/vision/pull/7160)
  19. # TODO: we could re-train the video models with antialias=True?
  20. transforms.Resize(resize_size, antialias=False),
  21. ]
  22. if hflip_prob > 0:
  23. trans.append(transforms.RandomHorizontalFlip(hflip_prob))
  24. trans.extend([transforms.Normalize(mean=mean, std=std), transforms.RandomCrop(crop_size), ConvertBCHWtoCBHW()])
  25. self.transforms = transforms.Compose(trans)
  26. def __call__(self, x):
  27. return self.transforms(x)
  28. class VideoClassificationPresetEval:
  29. def __init__(self, *, crop_size, resize_size, mean=(0.43216, 0.394666, 0.37645), std=(0.22803, 0.22145, 0.216989)):
  30. self.transforms = transforms.Compose(
  31. [
  32. transforms.ConvertImageDtype(torch.float32),
  33. # We hard-code antialias=False to preserve results after we changed
  34. # its default from None to True (see
  35. # https://github.com/pytorch/vision/pull/7160)
  36. # TODO: we could re-train the video models with antialias=True?
  37. transforms.Resize(resize_size, antialias=False),
  38. transforms.Normalize(mean=mean, std=std),
  39. transforms.CenterCrop(crop_size),
  40. ConvertBCHWtoCBHW(),
  41. ]
  42. )
  43. def __call__(self, x):
  44. return self.transforms(x)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...