Package includes common used code in Keras
Project description
Simplier keras
Common used actions in keras
Table of contents
General info
This package is a set of common used actions in keras. At this moment includes:
- Fast train and validation generators creation
- Default callbacks
- Accuracy and Loss plot****
- Predictions with image plot
- Histogram with CDF and image plot
Libraries
- Keras - version 2.4.3
- Matplotlib - version 3.3.3
- NumPy - version 1.19.4
- OpenCV - version 4.4.0.46
- TensorFlow - version 2.4.0rc1
Setup
- Install from PyPi:
pip install simplier-keras
Documentation
Status: in progress
Generators
from keras.preprocessing.image import ImageDataGenerator
from simplier_keras.dir_flow_generators import get_train_val_generators
img_size = (48, 48)
img_datagen = ImageDataGenerator(rescale=1/255)
train_generator, validation_generator = get_train_val_generators(img_datagen, data_dir='../data/normal/',
color_mode='grayscale', target_size=img_size)
Signature:
def get_train_val_generators(img_datagen: ImageDataGenerator, data_dir='../data/', target_size=None, color_mode='rgb',
batch_size=128, class_mode='categorical')
Default callbacks
from simplier_keras.default_callbacks import get_default_callbacks
callbacks = get_default_callbacks('vgg16_calssifier')
hist = model.fit(train_features, train_labels, batch_size=128, epochs=100, validation_data=(val_features, val_labels),
callbacks=callbacks, verbose=2, steps_per_epoch=nr_of_train_imgs/train_batch_size)
Signature:
def get_default_callbacks(model_name):
return [
clb.ReduceLROnPlateau(monitor='val_acc', factor=0.5, min_lr=1e-6, patience=3, verbose=1),
clb.EarlyStopping(monitor='val_acc', patience=7, verbose=1),
clb.ModelCheckpoint(monitor='val_acc', filepath=f'../models/{model_name}.h5',
save_best_only=True, verbose=1)
]
Accuracy and Loss plot
from simplier_keras.plots.history_plots import plot_acc_and_loss
history = model.fit(train_generator,
steps_per_epoch=train_steps,
epochs=5,
validation_data=validation_generator,
validation_steps=valid_steps,
callbacks=callbacks
)
plot_acc_and_loss(history)
Result:
--add image--
Predictions with image plot
from keras.models import load_model
from keras.preprocessing.image import ImageDataGenerator
from simplier_keras.dir_flow_generators import get_train_val_generators
from simplier_keras.plots import plot_predictions_with_img
img_size = (48, 48)
img_datagen = ImageDataGenerator(rescale=1/255)
_, validation_generator = get_train_val_generators(img_datagen, data_dir='../data/normal/',
color_mode='grayscale', target_size=img_size)
model = load_model('../models/standard_model.h5')
batch, labels = validation_generator.next()
preds = model.predict(batch)
plot_predictions_with_img(1, preds, labels, batch)
Result:
--add image--
Histogram with CDF and image plot
import cv2
from simplier_keras.plots import plot_gray_img_with_histogram
img = cv2.imread(f'{src_train_path}/0/241.png', 0)
plot_gray_img_with_histogram(img)
img2 = stretch_histogram(img)
plot_gray_img_with_histogram(img2)
Result:
--add image--
PyPi
TODO
Development
Want to contribute? Great!
To fix a bug or enhance an existing module, follow these steps:
- Fork the repo
- Create a new branch (
git checkout -b improve-feature
) - Make the appropriate changes in the files
- Verify if they are correct
- Add changes to reflect the changes made
- Commit changes
- Push to the branch (
git push origin improve-feature
) - Create a Pull Request
Status
Library is: in progress
Contact
albert.lis.1996@gmail.com - feel free to contact me!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simplified_keras-0.0.1.tar.gz
(5.7 kB
view hashes)
Built Distribution
Close
Hashes for simplified_keras-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81b97c139c90d2414b8890313e7116fa6872ead0ee50d0b51986a296792ff78a |
|
MD5 | 1a5b7608cfa7170395e0f6945028bb24 |
|
BLAKE2b-256 | 9c690a55e08f8924ffcc293cbc68db0bdd8bfc892a263185d33c0b2ec16fe2f8 |