<jupyter_start><jupyter_text>some codes U may need in moving datasets<jupyter_code># import shutil 
# os.chdir('data_sets')
# os.mkdir('fr_datas')
# os.mkdir('fr_datas/train')
# os.mkdir('fr_datas/test')

# ls = [ 'Vazir', 'Farisi', 'Elham']
# for l in ls:
#   a = os.listdir('font_Segments/'+l)
#   os.mkdir('fr_datas/train/'+l)
#   os.mkdir('fr_datas/test/'+l) 
#   for i in range(5000):
#     shutil.copyfile('font_Segments/'+l+'/'+ a[i], 'fr_datas/train/'+l+'/'+ a[i] )
#     print(i)

#   for i in range(1000):
#     shutil.copyfile('font_Segments/'+l+'/'+ a[i+5000], 'fr_datas/test/'+l+'/'+ a[i+5000])
#     print(i)

# os.chdir('..')
# os.chdir('My Drive')
# os.remove('images')
# ! rm -r Vazir (1)
os.listdir('.')
! pwd
! ls
from keras.models import Model
from keras.layers import Input, Dense, Conv2D, MaxPool2D, Flatten, Dropout
input_img = Input(shape=(32,32,3))
x = Conv2D(64, (3,3), activation= 'relu')(input_img)
x = MaxPool2D(pool_size= (2,2))(x)
x = Conv2D(64, (3,3), activation= 'relu')(x)
x = MaxPool2D(pool_size= (2,2))(x)
x = Conv2D(64, (3,3), activation= 'relu')(x)
x = MaxPool2D(pool_size= (2,2))(x)
x = Flatten()(x)
x = Dense(output_dim= 64, activation='sigmoid')(x)
x = Dense(output_dim= 64, activation='sigmoid')(x)
x = Dense(output_dim= 3, activation='sigmoid')(x)
FR_model = Model(input_img, x)
FR_model.compile(optimizer = 'adam' , loss = 'categorical_crossentropy' , metrics = ['accuracy'])
from keras.preprocessing.image import ImageDataGenerator
train_date_gen = ImageDataGenerator(rescale= 1./255,
                                    shear_range= .2)

test_date_gen = ImageDataGenerator(rescale= 1./255)

train_set= train_date_gen.flow_from_directory('data_sets/fr_datas/train',
                                              target_size= (32,32),
                                              batch_size= 32,
                                              class_mode= 'categorical')

test_set= test_date_gen.flow_from_directory('data_sets/fr_datas/test',
                                              target_size= (32,32),
                                              batch_size= 32,
                                              class_mode= 'categorical')
FR_model.fit_generator(train_set, 
                       samples_per_epoch = 5000,
                       epochs= 20,
                       validation_data = test_set, 
                       nb_val_samples = 1000)
import numpy as np
from keras.preprocessing import image
example_dir = 'data_sets/font_Segments/Farisi'
a = os.listdir(example_dir)
rand = np.random.randint(low = 0 , high = len(a)-1)
img = image.load_img(example_dir + '/' + a[rand], target_size= (32,32))
img
test_img = image.img_to_array(img)
test_img = np.expand_dims(test_img , axis=0)
test_img.shape
result = FR_model.predict(test_img)
result
train_set.class_indices
FR_model.save_weights('my_git/Arabic_Farsi_Font_Recognition/model.h5')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1523224043715847, 'fraction_numerical': 0.031420765027322405, 'mean_word_length': 2.8590250329380766, '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': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '274902', 'license': 'MIT', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1054, 'n_words': 188, 'path': 'Test.ipynb', 'repo_name': 'ZeinabTaghavi/Arabic_Farsi_Font_Recognition', 'size': '2928'}