Kauf mir einen Kaffee☕
ColorJitter() kann die Helligkeit, den Kontrast, die Sättigung und den Farbton von null oder mehr Bildern ändern, wie unten gezeigt:
*Memos:
from torchvision.datasets import OxfordIIITPet from torchvision.transforms.v2 import ColorJitter colorjitter = ColorJitter() colorjitter = ColorJitter(brightness=0, contrast=0, saturation=0, hue=0) colorjitter = ColorJitter(brightness=(1.0, 2.0), contrast=(1.0, 1.0), saturation=(1.0, 1.0), hue=(0.0, 0.0)) colorjitter # ColorJitter() print(colorjitter.brightness) # None print(colorjitter.contrast) # None print(colorjitter.saturation) # None print(colorjitter.hue) # None origin_data = OxfordIIITPet( root="data", transform=None # transform=ColorJitter() # colorjitter = ColorJitter(brightness=0, # contrast=0, # saturation=0, # hue=0) # transform=ColorJitter(brightness=(1.0, 1.0), # contrast=(1.0, 1.0), # saturation=(1.0, 1.0), # hue=(0.0, 0.0)) ) p2bright_data = OxfordIIITPet( # `p` is plus. root="data", transform=ColorJitter(brightness=2.0) # transform=ColorJitter(brightness=(0.0, 3.0)) ) p2p2bright_data = OxfordIIITPet( root="data", transform=ColorJitter(brightness=(2.0, 2.0)) ) p05p05bright_data = OxfordIIITPet( root="data", transform=ColorJitter(brightness=(0.5, 0.5)) ) p2contra_data = OxfordIIITPet( root="data", transform=ColorJitter(contrast=2.0) # transform=ColorJitter(contrast=(0.0, 3.0)) ) p2p2contra_data = OxfordIIITPet( root="data", transform=ColorJitter(contrast=(2.0, 2.0)) ) p05p05contra_data = OxfordIIITPet( root="data", transform=ColorJitter(contrast=(0.5, 0.5)) ) p2satura_data = OxfordIIITPet( root="data", transform=ColorJitter(saturation=2.0) # transform=ColorJitter(saturation=(0.0, 3.0)) ) p2p2satura_data = OxfordIIITPet( root="data", transform=ColorJitter(saturation=(2.0, 2.0)) ) p05p05satura_data = OxfordIIITPet( root="data", transform=ColorJitter(saturation=(0.5, 0.5)) ) p05hue_data = OxfordIIITPet( root="data", transform=ColorJitter(hue=0.5) # transform=ColorJitter(hue=(-0.5, 0.5)) ) p025p025hue_data = OxfordIIITPet( root="data", transform=ColorJitter(hue=(0.25, 0.25)) ) m025m025hue_data = OxfordIIITPet( # `m` is minus. root="data", transform=ColorJitter(hue=(-0.25, -0.25)) ) import matplotlib.pyplot as plt def show_images(data, main_title=None): plt.figure(figsize=(10, 5)) plt.suptitle(t=main_title, y=0.8, fontsize=14) for i, (im, _) in zip(range(1, 6), data): plt.subplot(1, 5, i) plt.imshow(X=im) plt.xticks(ticks=[]) plt.yticks(ticks=[]) plt.tight_layout() plt.show() show_images(data=origin_data, main_title="origin_data") show_images(data=p2bright_data, main_title="p2bright_data") show_images(data=p2p2bright_data, main_title="p2p2bright_data") show_images(data=p05p05bright_data, main_title="p05p05bright_data") show_images(data=origin_data, main_title="origin_data") show_images(data=p2contra_data, main_title="p2contra_data") show_images(data=p2p2contra_data, main_title="p2p2contra_data") show_images(data=p05p05contra_data, main_title="p05p05contra_data") show_images(data=origin_data, main_title="origin_data") show_images(data=p2satura_data, main_title="p2satura_data") show_images(data=p2p2satura_data, main_title="p2p2satura_data") show_images(data=p05p05satura_data, main_title="p05p05satura_data") show_images(data=origin_data, main_title="origin_data") show_images(data=p05hue_data, main_title="p05hue_data") show_images(data=p025p025hue_data, main_title="p025p025hue_data") show_images(data=m025m025hue_data, main_title="m025m025hue_data")
from torchvision.datasets import OxfordIIITPet from torchvision.transforms.v2 import ColorJitter colorjitter = ColorJitter() colorjitter = ColorJitter(brightness=0, contrast=0, saturation=0, hue=0) colorjitter = ColorJitter(brightness=(1.0, 2.0), contrast=(1.0, 1.0), saturation=(1.0, 1.0), hue=(0.0, 0.0)) colorjitter # ColorJitter() print(colorjitter.brightness) # None print(colorjitter.contrast) # None print(colorjitter.saturation) # None print(colorjitter.hue) # None origin_data = OxfordIIITPet( root="data", transform=None # transform=ColorJitter() # colorjitter = ColorJitter(brightness=0, # contrast=0, # saturation=0, # hue=0) # transform=ColorJitter(brightness=(1.0, 1.0), # contrast=(1.0, 1.0), # saturation=(1.0, 1.0), # hue=(0.0, 0.0)) ) p2bright_data = OxfordIIITPet( # `p` is plus. root="data", transform=ColorJitter(brightness=2.0) # transform=ColorJitter(brightness=(0.0, 3.0)) ) p2p2bright_data = OxfordIIITPet( root="data", transform=ColorJitter(brightness=(2.0, 2.0)) ) p05p05bright_data = OxfordIIITPet( root="data", transform=ColorJitter(brightness=(0.5, 0.5)) ) p2contra_data = OxfordIIITPet( root="data", transform=ColorJitter(contrast=2.0) # transform=ColorJitter(contrast=(0.0, 3.0)) ) p2p2contra_data = OxfordIIITPet( root="data", transform=ColorJitter(contrast=(2.0, 2.0)) ) p05p05contra_data = OxfordIIITPet( root="data", transform=ColorJitter(contrast=(0.5, 0.5)) ) p2satura_data = OxfordIIITPet( root="data", transform=ColorJitter(saturation=2.0) # transform=ColorJitter(saturation=(0.0, 3.0)) ) p2p2satura_data = OxfordIIITPet( root="data", transform=ColorJitter(saturation=(2.0, 2.0)) ) p05p05satura_data = OxfordIIITPet( root="data", transform=ColorJitter(saturation=(0.5, 0.5)) ) p05hue_data = OxfordIIITPet( root="data", transform=ColorJitter(hue=0.5) # transform=ColorJitter(hue=(-0.5, 0.5)) ) p025p025hue_data = OxfordIIITPet( root="data", transform=ColorJitter(hue=(0.25, 0.25)) ) m025m025hue_data = OxfordIIITPet( # `m` is minus. root="data", transform=ColorJitter(hue=(-0.25, -0.25)) ) import matplotlib.pyplot as plt def show_images(data, main_title=None): plt.figure(figsize=(10, 5)) plt.suptitle(t=main_title, y=0.8, fontsize=14) for i, (im, _) in zip(range(1, 6), data): plt.subplot(1, 5, i) plt.imshow(X=im) plt.xticks(ticks=[]) plt.yticks(ticks=[]) plt.tight_layout() plt.show() show_images(data=origin_data, main_title="origin_data") show_images(data=p2bright_data, main_title="p2bright_data") show_images(data=p2p2bright_data, main_title="p2p2bright_data") show_images(data=p05p05bright_data, main_title="p05p05bright_data") show_images(data=origin_data, main_title="origin_data") show_images(data=p2contra_data, main_title="p2contra_data") show_images(data=p2p2contra_data, main_title="p2p2contra_data") show_images(data=p05p05contra_data, main_title="p05p05contra_data") show_images(data=origin_data, main_title="origin_data") show_images(data=p2satura_data, main_title="p2satura_data") show_images(data=p2p2satura_data, main_title="p2p2satura_data") show_images(data=p05p05satura_data, main_title="p05p05satura_data") show_images(data=origin_data, main_title="origin_data") show_images(data=p05hue_data, main_title="p05hue_data") show_images(data=p025p025hue_data, main_title="p025p025hue_data") show_images(data=m025m025hue_data, main_title="m025m025hue_data")
Das obige ist der detaillierte Inhalt vonColorJitter in PyTorch. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!