Search code examples
pythonpickle

How to convert n number of images (in jpg format) to .p (pickle) format?


I have a folder abc with images in .jpg format. I need to convert these images to single xyz.p (pickled) file. How to pickle these images?

I want to implement something like this:

> import pickle  
> training_file = "dataset/train.p"  
> with open(training_file, mode='rb') as f: 
>     train = pickle.load(f)  X_train, y_train = train['features'], train['labels']

Solution

  • please try this :

    file = open('data.pkl', 'wb') 
    pickle.dump(image, file)
    file.close()