<commit_before>from os import listdir
import numpy as np
from PIL import Image
from sklearn.svm import SVC
# from sklearn.metrics import precision_score, recall_score

class ImageItem(object):
    def __init__(self):
        pass


def test(im):
    # rgb to grey
    new_im = im.convert("L")

    # downsize
    new_size = (int(new_im.width / 4), int(new_im.height / 4))
    new_im = new_im.resize(new_size)

    image = np.array(new_im).reshape(new_im.width * new_im.height)
    return image


def readfiles(path, img_preprocess):
    all_files_name = listdir(path)[:1000]
    images = [0] * len(all_files_name)
    labels = [0] * len(all_files_name)

    for i, f_name in enumerate(all_files_name):
        im = Image.open(path + f_name)
        images[i] = img_preprocess(im)
        labels[i] = ord(f_name[0]) - ord('a')

    return images, labels


def main():
    # Setting
    num_class = 26


    # Read, Preprocess and Downsize Image
    images, labels = readfiles("training/", img_preprocess=test)
    test_images, test_labels = readfiles("test/", img_preprocess=test)

    # Feature Selection


    # Training
    tmp_label = [0] * len(labels)
    model = [SVC() for i in range(num_class - 1)]
    for i in range(num_class - 1):
        for j in range(len(labels)):
            tmp_label[j] = 1 if i == labels[j] else 0
        model[i].fit(images, tmp_label)

    # Testing

<commit_msg>rename img preprocessing method<commit_after>from os import listdir
import numpy as np
from PIL import Image
from sklearn.svm import SVC
# from sklearn.metrics import precision_score, recall_score

class ImageItem(object):
    def __init__(self):
        pass


def method_1(im):
    # rgb to grey
    new_im = im.convert("L")

    # downsize
    new_size = (int(new_im.width / 4), int(new_im.height / 4))
    new_im = new_im.resize(new_size)

    image = np.array(new_im).reshape(new_im.width * new_im.height)
    return image


def readfiles(path, img_preprocess):
    all_files_name = listdir(path)[:1000]
    images = [0] * len(all_files_name)
    labels = [0] * len(all_files_name)

    for i, f_name in enumerate(all_files_name):
        im = Image.open(path + f_name)
        images[i] = img_preprocess(im)
        labels[i] = ord(f_name[0]) - ord('a')

    return images, labels


def main():
    # Setting
    num_class = 26


    # Read, Preprocess and Downsize Image
    images, labels = readfiles("training/", img_preprocess=method_1)
    test_images, test_labels = readfiles("test/", img_preprocess=method_1)

    # Feature Selection


    # Training
    tmp_label = [0] * len(labels)
    model = [SVC() for i in range(num_class - 1)]
    for i in range(num_class - 1):
        for j in range(len(labels)):
            tmp_label[j] = 1 if i == labels[j] else 0
        model[i].fit(images, tmp_label)

    # Testing


{'fraction_non_alphanumeric': 0.11519434628975266, 'fraction_numerical': 0.012367491166077738, 'mean_word_length': 3.009915014164306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5542066', 'n_tokens_mistral': 1021, 'n_tokens_neox': 966, 'n_words': 249}