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

additional_transforms.py 850 B

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
  1. # Copyright 2017-present, Facebook, Inc.
  2. # All rights reserved.
  3. #
  4. # This source code is licensed under the license found in the
  5. # LICENSE file in the root directory of this source tree.
  6. import torch
  7. from PIL import ImageEnhance
  8. transformtypedict=dict(Brightness=ImageEnhance.Brightness, Contrast=ImageEnhance.Contrast, Sharpness=ImageEnhance.Sharpness, Color=ImageEnhance.Color)
  9. class ImageJitter(object):
  10. def __init__(self, transformdict):
  11. self.transforms = [(transformtypedict[k], transformdict[k]) for k in transformdict]
  12. def __call__(self, img):
  13. out = img
  14. randtensor = torch.rand(len(self.transforms))
  15. for i, (transformer, alpha) in enumerate(self.transforms):
  16. r = alpha*(randtensor[i]*2.0 -1.0) + 1
  17. out = transformer(out).enhance(r).convert('RGB')
  18. return out
Tip!

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

Comments

Loading...