<commit_before>import numpy as np
from keras.models import load_model
from keras.preprocessing.image import load_img, img_to_array
import argparse

img_rows, img_cols = 128, 128


def get_args():
    parser = argparse.ArgumentParser(description='Predict gender which the person\'s in the image is.')
    parser.add_argument('--input', '-i', type=str, required=True, help='path to input an image')
    return parser.parse_args()


args = get_args()
img_path = args.input

img = load_img(img_path, target_size=(img_rows, img_cols))
img_arr = img_to_array(img)
img_array = np.array([img_arr])


model = load_model('trained_model.h5')
model.summary()

print('********************')
print('*   0 for female   *')
print('*   1 for male     *')
print('********************')
results = model.predict(img_array, batch_size=img_array.shape[0])
for res in results:
    print('Result:')
    print('   Female:', res[0] * 100)
    print('   Male  :', res[1] * 100)
<commit_msg>Refactoring<commit_after>import numpy as np
import argparse
from keras.models import load_model
from keras.preprocessing.image import load_img, img_to_array
from keras.backend import tensorflow_backend

### Configuration
img_rows, img_cols = 128, 128
model_dir = 'trained_model.h5'


def get_args():
    parser = argparse.ArgumentParser(description='Predict gender which the person\'s in the image is.')
    parser.add_argument('--input', '-i', type=str, required=True, help='path to input an image')
    return parser.parse_args()


args = get_args()
img_path = args.input


print('')
print('### Loading img:', img_path)
img = load_img(img_path, target_size=(img_rows, img_cols))
img_arr = img_to_array(img)
img_array = np.array([img_arr])


print('')
print('### Loading model:', model_dir)
model = load_model(model_dir)
model.summary()


print('')
print('### Prediction')
print('********************')
print('*   0 for female   *')
print('*   1 for male     *')
print('********************')
results = model.predict(img_array, batch_size=img_array.shape[0])
for res in results:
    print('Result:')
    print('   Female:', res[0] * 100)
    print('   Male  :', res[1] * 100)
{'fraction_non_alphanumeric': 0.17765310892940628, 'fraction_numerical': 0.016830294530154277, 'mean_word_length': 5.131805157593123, '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': '4687562', 'n_tokens_mistral': 743, 'n_tokens_neox': 706, 'n_words': 186}