<commit_before>from __future__ import division

import random
import numpy as np
from PIL import Image

from lib import iproc
from lib.data_augmentation import random_half
from lib.data_augmentation import random_flip
from lib.data_augmentation import random_shift_1px
from lib.data_augmentation import random_unsharp_mask


def _noise(src, level, chroma):
    sampling_factor = '1x1,1x1,1x1'
    quality0 = random.randint(85, 100)
    quality1 = random.randint(65, 90)
    quality2 = random.randint(45, 70)
    quality3 = random.randint(25, 50)
    if np.random.uniform() < chroma:
        sampling_factor = '2x1,1x1,1x1'
    if level == 0:
        dst = iproc.jpeg(src, sampling_factor, quality0)
    elif level == 1:
        dst = iproc.jpeg(src, sampling_factor, quality1)
    elif level == 2:
        if np.random.uniform() > 0.5:
            src = iproc.jpeg(src, sampling_factor, quality1)
        dst = iproc.jpeg(src, sampling_factor, quality2)<commit_msg>Fix JPEG chroma subsampling<commit_after>from __future__ import division

import random
import numpy as np
from PIL import Image

from lib import iproc
from lib.data_augmentation import random_half
from lib.data_augmentation import random_flip
from lib.data_augmentation import random_shift_1px
from lib.data_augmentation import random_unsharp_mask


def _noise(src, level, chroma):
    # YUV 444
    sampling_factor = '1x1,1x1,1x1'
    quality0 = random.randint(85, 100)
    quality1 = random.randint(65, 90)
    quality2 = random.randint(45, 70)
    quality3 = random.randint(25, 50)
    if np.random.uniform() < chroma:
        # YUV 420
        sampling_factor = '2x2,1x1,1x1'
    if level == 0:
        dst = iproc.jpeg(src, sampling_factor, quality0)
    elif level == 1:
        dst = iproc.jpeg(src, sampling_factor, quality1)
    elif level == 2:
        if np.random.uniform() > 0.5:
            src = iproc.jpeg(src, sampling_factor, quality1)
        dst = iproc.jpeg(src, sampling_factor, quality2)
{'fraction_non_alphanumeric': 0.09008097165991903, 'fraction_numerical': 0.0465587044534413, 'mean_word_length': 3.5136986301369864, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2100702', 'n_tokens_mistral': 718, 'n_tokens_neox': 652, 'n_words': 176}