<jupyter_start><jupyter_text>Reshaping images from 3d to 2d<jupyter_code>import cv2 as cv 
import numpy as np 
import glob 

image_location = "/home/syedjafer/Documents/Handwriting_recognition_svm/images/a/"

# to get list of files in the current directory
files = glob.glob(image_location+"*.png")
image_x = []
image_y = []

for file in files:
    image = cv.imread(file)
    image = np.array(image)
    new_img = image.reshape((image.shape[0]*image.shape[1]), image.shape[2])
    print (new_img.shape)
    image_x.append(new_img.flatten())
    image_y.append("a")<jupyter_output>(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)
(10000, 3)<jupyter_text>svm training<jupyter_code>x_train = np.array(image_x , dtype="float")
y_train = np.array(image_y)
print (x_train.shape)
print (y_train.shape)
from sklearn import svm
clf = svm.SVC()
clf.fit(x_train, y_train)<jupyter_output>(22, 30000)
(22,)<jupyter_text>Extending model to all images<jupyter_code>import cv2 as cv 
import numpy as np 
import glob 

image_location = "/home/syedjafer/Documents/Handwriting_recognition_svm/images/"
folder_depth = 8 

image_x = []
image_y = []
files = []

# to get list of files in the current directory
for level in range(folder_depth):
    folder = chr(ord("a")+level)
    print (image_location+folder+"/")
    label_len = len(glob.glob(image_location+folder+"/"+"*.png"))
    files = files + glob.glob(image_location+folder+"/"+"*.png")
    print(files)
    image_y = image_y + [folder] * (label_len)

# label
print (image_y)

# # shaping images to 100 * 100 
# for file in files:
#     image = cv.imread(file)
#     gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
#     resized_image = cv.resize(gray, (100, 100))
#     filename = file
#     cv.imwrite(file, resized_image)

# for file in files:
#     image = cv.imread(file)
#     image = np.array(image)
#     new_img = image.reshape((image.shape[0]*image.shape[1]), image.shape[2])
#     print (new_img.shape)
#     image_x.append(new_img.flatten())
# #     image_y.append("a")
    
# x_train = np.array(image_x , dtype="float")
# y_train = np.array(image_y)
# print (x_train.shape)
# print (y_train.shape)
# from sklearn import svm
# clf = svm.SVC()
# clf.fit(x_train, y_train)


len(image_y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15671031096563012, 'fraction_numerical': 0.06751227495908348, 'mean_word_length': 4.397350993377484, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '100193', 'license': 'MIT', 'n_tokens_mistral': 1113, 'n_tokens_neox': 971, 'n_words': 212, 'path': 'test1/images/a/.ipynb_checkpoints/Untitled1-checkpoint.ipynb', 'repo_name': 'swapnilmarathe007/Handwriting-Recognition', 'size': '2444'}