0

I have designed an autoencoder to read an (256*256) RGB image which gives an output as an array of float32 elements with dimensions (256,256,3) with some of the elements as shown in the figure.

img = Image.open('C:\\Users\\ece\\Desktop\\validation\\validate\\small_0002_7.jpg')
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
images = np.vstack([x])
classes = autoencoder.predict(images)

As I observed the output array values are in the range < 1. Now I want to to depict the output array classes as an image by expanding the values to the range of 256. What would be the best way to display the image?output values

mrin9san
  • 305
  • 1
  • 2
  • 12

1 Answers1

0

The auto encoder should match the output amplitude to the input amplitude, so you probably have a preprocessing in your layer or your cost function also has a scaling factor.

To save your image, multiply the result by 255, cast it as np.uint8, then save it with something like spicy.misc.imsave.

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
  • Hi I used the following code lines before to reconstruct the image ---classes1=np.reshape(classes,(256,256,3)) img = Image.fromarray(classes1, 'RGB') img.save('my.jpg') img.show() ----All it gives is a noisy image. – mrin9san Oct 26 '18 at 10:19
  • Are you sure you have a valid output image? – Matthieu Brucher Oct 26 '18 at 10:23
  • The autoencoder takes an input as (1,256,256,3). I have an output- "classes" which is float32 array with dimensions (1,256,256,3). The model is ok.. now the first issue arises as to how to pass the input validation image to the model. For this I have given the code line as shown in my post. And secondly, how to save--for which I used above mentioned code lines in my comment to your answer. Now I am not sure as to the source of error -whether I am wrongly passing the input image, or the representation of the output is wrong. – mrin9san Oct 26 '18 at 10:32
  • I meant to say, how do you check that the output image (before saving) is not noisy? – Matthieu Brucher Oct 26 '18 at 10:34
  • I have done something similar at https://github.com/luispedro/BuildingMachineLearningSystemsWithPython/tree/third_edition/ch05. Making sure that the range is OK is not always intuitive. – Matthieu Brucher Oct 26 '18 at 10:38
  • Output will be noisy as it tries to reconstruct from a lesser dimensions. May be way too noisy too as there are less number of layers in the model. I suspect the noisy unrecognizable image is coming due to wrong casting of the ''classes'' array to ''img'' array which is only (256,256) in dimension : So issue is as to how to reconstruct an output array (1,256,256,3) as an (256,256,3) RGB image. I am now checking the link you provided. – mrin9san Oct 26 '18 at 10:53
  • If you start from a random state, then nothing will be recognized. But once the auto encoder is optimized (and you see that the loss function has reached a minimum), you should be able to recognize the object with the code I gave you. – Matthieu Brucher Oct 26 '18 at 10:54