Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.2k views
in Technique[技术] by (71.8m points)

python - Issues saving the autoencoder predicted image to a new directory

I trained an autoencoder model in Keras to generate denoised images given noisy images. The predicted images are stored in the "result" directory, with the individual filenames appended with the "denoised" tag. When I run the code, nothing is stored in the "result" folder. When I ran for an individual image, the final cv2.imwrite throws this error: "TypeError: Expected Ptr<cv::UMat> for argument 'img'". Is there a different way to write the predicted files to the destination folder without using openCV in this case?

import glob
from keras.preprocessing import image

test = glob.glob("data/test1/*.png") #all test data that needs to be denoised
test.sort()
result = "data/result" #the folder that contains predicted denoised images
#load model
model = load_model('autoencoder_model.h5')
model.summary()
#compile the model
model.compile(loss='mean_squared_error', optimizer = RMSprop())

for f in test:
    img = image.load_img(f,grayscale=True,target_size=(128,128),interpolation="nearest")
    img_name = f.split(os.sep)[-1]
    #preprocess the image
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)
    x /= 255 
    #predict on the image
    preds = model.predict(x)
    pred_norm = 255 * (preds - preds.min()) / (preds.max() - preds.min())
    pred_normed = np.array(pred_norm, np.int)    
    cv2.imwrite(os.path.join(result,f[:-4]+'_removed.png'), pred_normed)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...