Skip to content

Latest commit

Β 

History

History
71 lines (51 loc) Β· 2.8 KB

File metadata and controls

71 lines (51 loc) Β· 2.8 KB

Keras Secure Image πŸ›‘οΈ

Keras Secure Image logo

Description πŸ”

This is an add-on library for Keras. The main functionality is to encrypt the images in the dataset so they are secure. You can write your own generator and call the decrypt functionality at runtime. The decrypted images are not stored, they are stored in tuple by the generator ensuring the safety of your images.

Setup πŸ–₯️

pip install keras_secure_image

Usage πŸ”©

Encrypting the images πŸ“Ž

from keras_secure_image import encrypt_directory
encrypt_directory(src_dir="/path/to/src",
                                   dest_dir="/path/to/dest", image_x=100, image_y=100,
                                   password="<PASSWORD>)
												  
Original Image πŸ”“

Encrypted Image πŸ”’

Training on encrypted images βš”οΈ

from keras_secure_image import decrypt_img
def generator_from_encrypted_data(path_to_features, labels, batch_size):
 batch_features = np.zeros((batch_size, 64, 64, 3))
 batch_labels = np.zeros((batch_size,1))
 while True:
   for i in range(batch_size):
     # choose random index in path_to_features
     index= random.choice(len(path_to_features),1)
     img = decrypt_img(path_to_img=path_to_features[index], password="<PASSWORD>", image_x=100, image_y=100)
     batch_features[i] = img
     batch_labels[i] = labels[index]
   yield batch_features, batch_labels
   

Note : Check the line

img = decrypt_data(path_to_img=path_to_features[index], password="<PASSWORD>", image_x=100, image_y=100)

This decrypt_data function takes the path to the image and decrypts it. Make sure that the <PASSWORD> is the same for encryption.

Calling the fit_generator in Keras

model.fit_generator(generator_from_encrypted_data(path_to_features,labels, 32),
                    samples_per_epoch=20, nb_epoch=10,
                    validation_data=generator_from_encrypted_data(features,labels, 16),
                    validation_steps=5, callbacks=callbacks_list, shuffle=True,use_multiprocessing=True)