Python Forum

Full Version: How to save predictions made by an autoencoder
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been practicing with this template for image reconstruction using an autoencoder:

https://github.com/bnsreenu/python_for_m...le_V1.0.py

In the template, a prediction is created for only one image and the image is shown but not saved.

I've made some changes so predictions are created for all the images in the folder, rather than just a single image e.g.
#Original einstein image for prediction as monalisa
img3_data=[]
path3 = (r"('einstein_mona_lisa/")
files=os.listdir(path3)
for i in tqdm(files):
    img3=cv2.imread(path3+'/'+i,1)  #Change 0 to 1 for color images
    img3 = cv2.cvtColor(img3, cv2.COLOR_BGR2RGB)#Changing BGR to RGB to show images in true colors
    img3=cv2.resize(img3,(SIZE, SIZE))
    img3_data.append(img_to_array(img3))

img_array3 = np.reshape(img3_data, (len(img3_data), SIZE, SIZE, 3))
img_array3 = img_array3.astype('float32') / 255.
However, I don't know how to save copies of these images once they have been predicted. Can you suggest code to save the predictions please?

At the moment it just shows a solitary image and none of the predictions are saved automatically.
pred = model.predict(img_array3)

imshow(pred[0].reshape(SIZE,SIZE,3))
Any advice on the best way to save the various predictions generated would be much appreciated.

For info: I am using Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] in Spyder
Many thanks