当前位置:网站首页>transforms. ColorJitter(0.3, 0, 0, 0)

transforms. ColorJitter(0.3, 0, 0, 0)

2022-06-13 08:55:00 Human high quality Algorithm Engineer

pytorch and onnx The output is a little different , It should be strictly aligned

 Insert picture description here
 Insert picture description here

Carefully aligned the model pretreatment , Finally, locating the difference is one of the color jitters

transform = transforms.Compose([
    transforms.ColorJitter(0.3, 0, 0, 0),
    transforms.ToTensor(),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])

Click to see the source code implementation , stay transform.py in

 if brightness is not None:
     brightness_factor = random.uniform(brightness[0], brightness[1])
     transforms.append(Lambda(lambda img: F.adjust_brightness(img, brightness_factor)))

Finally, it was found that PIL In the library ImageEnhance To enhance the brightness

enhancer = ImageEnhance.Brightness(img)
img = enhancer.enhance(brightness_factor)
return img
#-*- coding: UTF-8 -*- 
 
from PIL import Image
from PIL import ImageEnhance
 
# original image 
image = Image.open('lena.jpg')
image.show()
 
# Brightness enhancement 
enh_bri = ImageEnhance.Brightness(image)
brightness = 1.5
image_brightened = enh_bri.enhance(brightness)
image_brightened.show()
 
# Chroma enhancement 
enh_col = ImageEnhance.Color(image)
color = 1.5
image_colored = enh_col.enhance(color)
image_colored.show()
 
# Contrast enhancement 
enh_con = ImageEnhance.Contrast(image)
contrast = 1.5
image_contrasted = enh_con.enhance(contrast)
image_contrasted.show()
 
# Sharpness enhancement 
enh_sha = ImageEnhance.Sharpness(image)
sharpness = 3.0
image_sharped = enh_sha.enhance(sharpness)
image_sharped.show()

原网站

版权声明
本文为[Human high quality Algorithm Engineer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270536289066.html