Skip to content

Add-on library for Keras to train on encrypted images for humans ๐Ÿ›ก๏ธ

License

Notifications You must be signed in to change notification settings

akshaybahadur21/keras-secure-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

28 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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)

About

Add-on library for Keras to train on encrypted images for humans ๐Ÿ›ก๏ธ

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages