Layer output of Keras pre-trained VGG19 model produces different outputs for same input












2














I'm extracting intermediate layer outputs from pretrained VGG19 ConvNet for a given image. I expect that if I give the same image twice, I should get the same output. But, I'm not getting the same output. Why is this happening and how to fix this?



Additional Details:
I'm following this paper. They use a VGG19 ConvNet and extract the features from some intermediate layer (VGG22 means 2nd layer before 2nd convolution) for Super-Resolved Image and Ground-Truth Image. Then they calculate the mean squared error between these 2 feature sets and use it as a loss parameter. Now, my expectation is that if I give Ground Truth Image only twice, the mean squared error should be zero. But it is not happening? I'm getting different feature values at different iteration, but with same image. Also I noticed that, when I run the program again afresh, I get the same set of values. Code below for reference:



import numpy
from keras import backend as K
from keras.applications.vgg19 import VGG19, preprocess_input
from keras.preprocessing.image import img_to_array, load_img


model = VGG19()
vgg22_layer_output = K.function([model.layers[0].input], [model.layers[5].output])

# image_matrix is a 224x224x3 matrix for an RGB-image.
hr_image_obj = load_img(hr_image_path)
hr_image_matrix = img_to_array(hr_image_obj)
cropped_hr_image = hr_image_matrix[0:224, 0:224, :]
expanded_image = numpy.expand_dims(cropped_hr_image, axis=0)
preprocessed_image = preprocess_input(expanded_image)
features1 = vgg22_layer_output ([preprocessed_image])[0]
features2 = vgg22_layer_output ([preprocessed_image])[0]


Here, my expectation is that features1 = features2, which isn't



Results:



features1:



array([[[[2.15184002e+01, 1.81470230e+02, 0.00000000e+00, ...,
0.00000000e+00, 1.98130661e+02, 0.00000000e+00],
[2.27056488e+02, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[1.54923904e+02, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
...,
[2.29082489e+02, 2.58140778e+02, 0.00000000e+00, ...,
3.18900665e+02, 0.00000000e+00, 0.00000000e+00],
[1.58660873e+02, 1.24280603e+03, 0.00000000e+00, ...,
2.76672821e+02, 0.00000000e+00, 0.00000000e+00],
[2.66982513e+02, 4.27661194e+02, 0.00000000e+00, ...,
4.57434418e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.71959274e+02, ...,
0.00000000e+00, 1.25863232e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.51934662e+02, 4.45714081e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.73108368e+02, 7.51479004e+02, 0.00000000e+00],
...,
[0.00000000e+00, 3.06031370e+00, 0.00000000e+00, ...,
3.09630096e+02, 2.15055069e+02, 1.91232590e+02],
[0.00000000e+00, 1.33151245e+03, 0.00000000e+00, ...,
2.78728699e+02, 2.91452618e+01, 4.12124878e+02],
[1.13750778e+02, 3.04266022e+02, 0.00000000e+00, ...,
4.93073273e+02, 0.00000000e+00, 1.25463562e+02]],
[[0.00000000e+00, 2.36886551e+02, 1.87017990e+02, ...,
0.00000000e+00, 5.56484497e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.29744125e+02, 5.47009888e+02, 0.00000000e+00],
[2.10977726e+01, 0.00000000e+00, 5.83388855e+02, ...,
3.78568268e+02, 1.76858459e+03, 0.00000000e+00],
...,
[0.00000000e+00, 2.26063950e+02, 0.00000000e+00, ...,
1.74201874e+02, 1.10421577e+02, 2.92625153e+02],
[0.00000000e+00, 1.49054639e+03, 1.73763367e+02, ...,
3.43214760e+01, 1.41045761e+02, 5.26752502e+02],
[1.79130356e+02, 4.18553101e+02, 1.12429085e+02, ...,
2.08473053e+02, 0.00000000e+00, 1.46159897e+02]],
...,
[[0.00000000e+00, 0.00000000e+00, 6.14884460e+02, ...,
4.48683044e+02, 2.60172217e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.05306360e+03, 5.45696045e+02, 0.00000000e+00],
[5.33453941e+01, 0.00000000e+00, 6.09368164e+02, ...,
7.00016541e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
2.49793106e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.44778638e+03, ...,
1.97339310e+02, 0.00000000e+00, 0.00000000e+00],
[1.27069351e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.85339737e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 4.90521271e+02, ...,
4.68645844e+02, 3.26934399e+03, 0.00000000e+00],
[2.26508102e+01, 0.00000000e+00, 7.08834915e+01, ...,
1.11953967e+03, 1.10590857e+03, 0.00000000e+00],
[1.11061287e+02, 0.00000000e+00, 8.05527405e+02, ...,
8.03228516e+02, 2.84233459e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.10313757e+03, ...,
5.78258667e+02, 1.47924316e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 1.59146082e+03, ...,
7.10267578e+02, 6.43671143e+02, 0.00000000e+00],
[3.27744568e+02, 0.00000000e+00, 0.00000000e+00, ...,
4.53388458e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.12306348e+03, ...,
1.63393646e+02, 3.52517969e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 6.36935806e+01, ...,
4.52494598e+02, 1.94326257e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
2.83666046e+02, 4.89346985e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.02328314e+03, ...,
2.65413391e+02, 2.64639990e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
4.30894745e+02, 1.33343530e+03, 0.00000000e+00],
[7.57115707e+01, 0.00000000e+00, 0.00000000e+00, ...,
2.14354630e+02, 0.00000000e+00, 0.00000000e+00]]]],
dtype=float32)


features2:



array([[[[2.44103737e+01, 3.35516052e+02, 0.00000000e+00, ...,
0.00000000e+00, 2.06830643e+02, 0.00000000e+00],
[4.71717712e+02, 0.00000000e+00, 0.00000000e+00, ...,
2.63770996e+02, 0.00000000e+00, 0.00000000e+00],
[3.93549591e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.77212814e+02, 0.00000000e+00, 0.00000000e+00],
...,
[5.33919487e+01, 0.00000000e+00, 0.00000000e+00, ...,
1.85940536e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 2.96363708e+02, 0.00000000e+00, ...,
1.09057648e+02, 0.00000000e+00, 0.00000000e+00],
[2.27105503e+01, 8.29022141e+01, 0.00000000e+00, ...,
1.38949188e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 2.47062546e+02, ...,
0.00000000e+00, 1.66465466e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
6.74320862e+02, 4.15592712e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
8.65957825e+02, 8.59399170e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.66129944e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 2.76259674e+02, 0.00000000e+00, ...,
8.00474930e+01, 0.00000000e+00, 1.08291901e+02],
[0.00000000e+00, 2.20606117e+01, 0.00000000e+00, ...,
1.28005768e+02, 0.00000000e+00, 3.49725151e+01]],
[[0.00000000e+00, 2.14503006e+02, 8.82690811e+01, ...,
0.00000000e+00, 5.60968628e+02, 0.00000000e+00],
[3.28399010e+01, 0.00000000e+00, 0.00000000e+00, ...,
3.34213745e+02, 2.90819824e+02, 0.00000000e+00],
[8.66472626e+01, 0.00000000e+00, 1.10250635e+03, ...,
6.37486572e+02, 1.67822144e+03, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
5.90463066e+01, 0.00000000e+00, 9.77452278e+00],
[0.00000000e+00, 3.39350586e+02, 4.62688398e+00, ...,
1.32679808e+00, 0.00000000e+00, 1.65987671e+02],
[2.47563610e+01, 7.48269196e+01, 1.33592939e+01, ...,
6.36582108e+01, 0.00000000e+00, 5.70933228e+01]],
...,
[[0.00000000e+00, 0.00000000e+00, 6.27470215e+02, ...,
2.55267532e+02, 2.27369629e+03, 0.00000000e+00],
[1.52827530e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.20087329e+03, 0.00000000e+00, 0.00000000e+00],
[1.33066071e+02, 0.00000000e+00, 5.95311890e+02, ...,
7.66817871e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
4.81101898e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.99484155e+03, ...,
5.40802429e+02, 0.00000000e+00, 0.00000000e+00],
[1.93494095e+02, 0.00000000e+00, 1.16481377e+02, ...,
3.75594208e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 5.08203369e+02, ...,
3.65947357e+02, 2.66369580e+03, 0.00000000e+00],
[2.29821182e+02, 0.00000000e+00, 3.83578918e+02, ...,
1.37410413e+03, 1.28806320e+02, 0.00000000e+00],
[1.89210968e+02, 0.00000000e+00, 9.40994324e+02, ...,
8.16117615e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.34960962e+03, ...,
1.03916003e+03, 6.58975891e+02, 0.00000000e+00],
[6.77491531e+01, 0.00000000e+00, 2.07465186e+03, ...,
1.13461414e+03, 0.00000000e+00, 0.00000000e+00],
[2.96653259e+02, 0.00000000e+00, 0.00000000e+00, ...,
6.33178528e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.20268628e+03, ...,
6.86023560e+01, 2.83282886e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.50556335e+02, ...,
8.04942566e+02, 7.94925537e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.74615967e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.17975757e+03, ...,
6.35223450e+02, 1.62643567e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
9.20189697e+02, 4.05781097e+02, 0.00000000e+00],
[1.26037315e+02, 0.00000000e+00, 0.00000000e+00, ...,
4.17285614e+02, 0.00000000e+00, 0.00000000e+00]]]],
dtype=float32)


The image is taken from here. Path: v1.3/Code/Ours/Images_GroundTruth/BSD200/335094.png



Edit 1: Added additional code and results










share|improve this question
























  • The code you included doesn't show the problem, please add more detail and actual results you get.
    – Matias Valdenegro
    Nov 22 at 20:59










  • I've added more detail and results. Please let me know if you need more info and what exactly you want. Thanks!
    – Nagabhushan S N
    Nov 23 at 1:52






  • 1




    I have run the code you provided with that specific image and got equal features1 and features2 (numpy.array_equal(features1, features2) was True). So, the problem probably lies somewhere else.
    – Kilian Batzner
    Nov 23 at 13:36










  • Oh! Might be then. Thanks for checking. Currently, I am using another method to get the features as given here: keras.io/getting-started/faq/… (1st method). It is giving same values. I'll investigate later what was going wrong. Thanks again!
    – Nagabhushan S N
    Nov 23 at 15:22










  • I have narrowed down the error. The hr_image_matrix i.e. the image read using keras' load_img and img_to_array functions was somehow giving negative values for the image matrix. Very strange. So, I replaced that with cv2.imread(hr_image_path, cv2.IMREAD_COLOR) and then its working as expected.
    – Nagabhushan S N
    Nov 23 at 16:28
















2














I'm extracting intermediate layer outputs from pretrained VGG19 ConvNet for a given image. I expect that if I give the same image twice, I should get the same output. But, I'm not getting the same output. Why is this happening and how to fix this?



Additional Details:
I'm following this paper. They use a VGG19 ConvNet and extract the features from some intermediate layer (VGG22 means 2nd layer before 2nd convolution) for Super-Resolved Image and Ground-Truth Image. Then they calculate the mean squared error between these 2 feature sets and use it as a loss parameter. Now, my expectation is that if I give Ground Truth Image only twice, the mean squared error should be zero. But it is not happening? I'm getting different feature values at different iteration, but with same image. Also I noticed that, when I run the program again afresh, I get the same set of values. Code below for reference:



import numpy
from keras import backend as K
from keras.applications.vgg19 import VGG19, preprocess_input
from keras.preprocessing.image import img_to_array, load_img


model = VGG19()
vgg22_layer_output = K.function([model.layers[0].input], [model.layers[5].output])

# image_matrix is a 224x224x3 matrix for an RGB-image.
hr_image_obj = load_img(hr_image_path)
hr_image_matrix = img_to_array(hr_image_obj)
cropped_hr_image = hr_image_matrix[0:224, 0:224, :]
expanded_image = numpy.expand_dims(cropped_hr_image, axis=0)
preprocessed_image = preprocess_input(expanded_image)
features1 = vgg22_layer_output ([preprocessed_image])[0]
features2 = vgg22_layer_output ([preprocessed_image])[0]


Here, my expectation is that features1 = features2, which isn't



Results:



features1:



array([[[[2.15184002e+01, 1.81470230e+02, 0.00000000e+00, ...,
0.00000000e+00, 1.98130661e+02, 0.00000000e+00],
[2.27056488e+02, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[1.54923904e+02, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
...,
[2.29082489e+02, 2.58140778e+02, 0.00000000e+00, ...,
3.18900665e+02, 0.00000000e+00, 0.00000000e+00],
[1.58660873e+02, 1.24280603e+03, 0.00000000e+00, ...,
2.76672821e+02, 0.00000000e+00, 0.00000000e+00],
[2.66982513e+02, 4.27661194e+02, 0.00000000e+00, ...,
4.57434418e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.71959274e+02, ...,
0.00000000e+00, 1.25863232e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.51934662e+02, 4.45714081e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.73108368e+02, 7.51479004e+02, 0.00000000e+00],
...,
[0.00000000e+00, 3.06031370e+00, 0.00000000e+00, ...,
3.09630096e+02, 2.15055069e+02, 1.91232590e+02],
[0.00000000e+00, 1.33151245e+03, 0.00000000e+00, ...,
2.78728699e+02, 2.91452618e+01, 4.12124878e+02],
[1.13750778e+02, 3.04266022e+02, 0.00000000e+00, ...,
4.93073273e+02, 0.00000000e+00, 1.25463562e+02]],
[[0.00000000e+00, 2.36886551e+02, 1.87017990e+02, ...,
0.00000000e+00, 5.56484497e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.29744125e+02, 5.47009888e+02, 0.00000000e+00],
[2.10977726e+01, 0.00000000e+00, 5.83388855e+02, ...,
3.78568268e+02, 1.76858459e+03, 0.00000000e+00],
...,
[0.00000000e+00, 2.26063950e+02, 0.00000000e+00, ...,
1.74201874e+02, 1.10421577e+02, 2.92625153e+02],
[0.00000000e+00, 1.49054639e+03, 1.73763367e+02, ...,
3.43214760e+01, 1.41045761e+02, 5.26752502e+02],
[1.79130356e+02, 4.18553101e+02, 1.12429085e+02, ...,
2.08473053e+02, 0.00000000e+00, 1.46159897e+02]],
...,
[[0.00000000e+00, 0.00000000e+00, 6.14884460e+02, ...,
4.48683044e+02, 2.60172217e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.05306360e+03, 5.45696045e+02, 0.00000000e+00],
[5.33453941e+01, 0.00000000e+00, 6.09368164e+02, ...,
7.00016541e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
2.49793106e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.44778638e+03, ...,
1.97339310e+02, 0.00000000e+00, 0.00000000e+00],
[1.27069351e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.85339737e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 4.90521271e+02, ...,
4.68645844e+02, 3.26934399e+03, 0.00000000e+00],
[2.26508102e+01, 0.00000000e+00, 7.08834915e+01, ...,
1.11953967e+03, 1.10590857e+03, 0.00000000e+00],
[1.11061287e+02, 0.00000000e+00, 8.05527405e+02, ...,
8.03228516e+02, 2.84233459e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.10313757e+03, ...,
5.78258667e+02, 1.47924316e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 1.59146082e+03, ...,
7.10267578e+02, 6.43671143e+02, 0.00000000e+00],
[3.27744568e+02, 0.00000000e+00, 0.00000000e+00, ...,
4.53388458e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.12306348e+03, ...,
1.63393646e+02, 3.52517969e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 6.36935806e+01, ...,
4.52494598e+02, 1.94326257e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
2.83666046e+02, 4.89346985e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.02328314e+03, ...,
2.65413391e+02, 2.64639990e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
4.30894745e+02, 1.33343530e+03, 0.00000000e+00],
[7.57115707e+01, 0.00000000e+00, 0.00000000e+00, ...,
2.14354630e+02, 0.00000000e+00, 0.00000000e+00]]]],
dtype=float32)


features2:



array([[[[2.44103737e+01, 3.35516052e+02, 0.00000000e+00, ...,
0.00000000e+00, 2.06830643e+02, 0.00000000e+00],
[4.71717712e+02, 0.00000000e+00, 0.00000000e+00, ...,
2.63770996e+02, 0.00000000e+00, 0.00000000e+00],
[3.93549591e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.77212814e+02, 0.00000000e+00, 0.00000000e+00],
...,
[5.33919487e+01, 0.00000000e+00, 0.00000000e+00, ...,
1.85940536e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 2.96363708e+02, 0.00000000e+00, ...,
1.09057648e+02, 0.00000000e+00, 0.00000000e+00],
[2.27105503e+01, 8.29022141e+01, 0.00000000e+00, ...,
1.38949188e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 2.47062546e+02, ...,
0.00000000e+00, 1.66465466e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
6.74320862e+02, 4.15592712e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
8.65957825e+02, 8.59399170e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.66129944e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 2.76259674e+02, 0.00000000e+00, ...,
8.00474930e+01, 0.00000000e+00, 1.08291901e+02],
[0.00000000e+00, 2.20606117e+01, 0.00000000e+00, ...,
1.28005768e+02, 0.00000000e+00, 3.49725151e+01]],
[[0.00000000e+00, 2.14503006e+02, 8.82690811e+01, ...,
0.00000000e+00, 5.60968628e+02, 0.00000000e+00],
[3.28399010e+01, 0.00000000e+00, 0.00000000e+00, ...,
3.34213745e+02, 2.90819824e+02, 0.00000000e+00],
[8.66472626e+01, 0.00000000e+00, 1.10250635e+03, ...,
6.37486572e+02, 1.67822144e+03, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
5.90463066e+01, 0.00000000e+00, 9.77452278e+00],
[0.00000000e+00, 3.39350586e+02, 4.62688398e+00, ...,
1.32679808e+00, 0.00000000e+00, 1.65987671e+02],
[2.47563610e+01, 7.48269196e+01, 1.33592939e+01, ...,
6.36582108e+01, 0.00000000e+00, 5.70933228e+01]],
...,
[[0.00000000e+00, 0.00000000e+00, 6.27470215e+02, ...,
2.55267532e+02, 2.27369629e+03, 0.00000000e+00],
[1.52827530e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.20087329e+03, 0.00000000e+00, 0.00000000e+00],
[1.33066071e+02, 0.00000000e+00, 5.95311890e+02, ...,
7.66817871e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
4.81101898e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.99484155e+03, ...,
5.40802429e+02, 0.00000000e+00, 0.00000000e+00],
[1.93494095e+02, 0.00000000e+00, 1.16481377e+02, ...,
3.75594208e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 5.08203369e+02, ...,
3.65947357e+02, 2.66369580e+03, 0.00000000e+00],
[2.29821182e+02, 0.00000000e+00, 3.83578918e+02, ...,
1.37410413e+03, 1.28806320e+02, 0.00000000e+00],
[1.89210968e+02, 0.00000000e+00, 9.40994324e+02, ...,
8.16117615e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.34960962e+03, ...,
1.03916003e+03, 6.58975891e+02, 0.00000000e+00],
[6.77491531e+01, 0.00000000e+00, 2.07465186e+03, ...,
1.13461414e+03, 0.00000000e+00, 0.00000000e+00],
[2.96653259e+02, 0.00000000e+00, 0.00000000e+00, ...,
6.33178528e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.20268628e+03, ...,
6.86023560e+01, 2.83282886e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.50556335e+02, ...,
8.04942566e+02, 7.94925537e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.74615967e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.17975757e+03, ...,
6.35223450e+02, 1.62643567e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
9.20189697e+02, 4.05781097e+02, 0.00000000e+00],
[1.26037315e+02, 0.00000000e+00, 0.00000000e+00, ...,
4.17285614e+02, 0.00000000e+00, 0.00000000e+00]]]],
dtype=float32)


The image is taken from here. Path: v1.3/Code/Ours/Images_GroundTruth/BSD200/335094.png



Edit 1: Added additional code and results










share|improve this question
























  • The code you included doesn't show the problem, please add more detail and actual results you get.
    – Matias Valdenegro
    Nov 22 at 20:59










  • I've added more detail and results. Please let me know if you need more info and what exactly you want. Thanks!
    – Nagabhushan S N
    Nov 23 at 1:52






  • 1




    I have run the code you provided with that specific image and got equal features1 and features2 (numpy.array_equal(features1, features2) was True). So, the problem probably lies somewhere else.
    – Kilian Batzner
    Nov 23 at 13:36










  • Oh! Might be then. Thanks for checking. Currently, I am using another method to get the features as given here: keras.io/getting-started/faq/… (1st method). It is giving same values. I'll investigate later what was going wrong. Thanks again!
    – Nagabhushan S N
    Nov 23 at 15:22










  • I have narrowed down the error. The hr_image_matrix i.e. the image read using keras' load_img and img_to_array functions was somehow giving negative values for the image matrix. Very strange. So, I replaced that with cv2.imread(hr_image_path, cv2.IMREAD_COLOR) and then its working as expected.
    – Nagabhushan S N
    Nov 23 at 16:28














2












2








2







I'm extracting intermediate layer outputs from pretrained VGG19 ConvNet for a given image. I expect that if I give the same image twice, I should get the same output. But, I'm not getting the same output. Why is this happening and how to fix this?



Additional Details:
I'm following this paper. They use a VGG19 ConvNet and extract the features from some intermediate layer (VGG22 means 2nd layer before 2nd convolution) for Super-Resolved Image and Ground-Truth Image. Then they calculate the mean squared error between these 2 feature sets and use it as a loss parameter. Now, my expectation is that if I give Ground Truth Image only twice, the mean squared error should be zero. But it is not happening? I'm getting different feature values at different iteration, but with same image. Also I noticed that, when I run the program again afresh, I get the same set of values. Code below for reference:



import numpy
from keras import backend as K
from keras.applications.vgg19 import VGG19, preprocess_input
from keras.preprocessing.image import img_to_array, load_img


model = VGG19()
vgg22_layer_output = K.function([model.layers[0].input], [model.layers[5].output])

# image_matrix is a 224x224x3 matrix for an RGB-image.
hr_image_obj = load_img(hr_image_path)
hr_image_matrix = img_to_array(hr_image_obj)
cropped_hr_image = hr_image_matrix[0:224, 0:224, :]
expanded_image = numpy.expand_dims(cropped_hr_image, axis=0)
preprocessed_image = preprocess_input(expanded_image)
features1 = vgg22_layer_output ([preprocessed_image])[0]
features2 = vgg22_layer_output ([preprocessed_image])[0]


Here, my expectation is that features1 = features2, which isn't



Results:



features1:



array([[[[2.15184002e+01, 1.81470230e+02, 0.00000000e+00, ...,
0.00000000e+00, 1.98130661e+02, 0.00000000e+00],
[2.27056488e+02, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[1.54923904e+02, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
...,
[2.29082489e+02, 2.58140778e+02, 0.00000000e+00, ...,
3.18900665e+02, 0.00000000e+00, 0.00000000e+00],
[1.58660873e+02, 1.24280603e+03, 0.00000000e+00, ...,
2.76672821e+02, 0.00000000e+00, 0.00000000e+00],
[2.66982513e+02, 4.27661194e+02, 0.00000000e+00, ...,
4.57434418e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.71959274e+02, ...,
0.00000000e+00, 1.25863232e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.51934662e+02, 4.45714081e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.73108368e+02, 7.51479004e+02, 0.00000000e+00],
...,
[0.00000000e+00, 3.06031370e+00, 0.00000000e+00, ...,
3.09630096e+02, 2.15055069e+02, 1.91232590e+02],
[0.00000000e+00, 1.33151245e+03, 0.00000000e+00, ...,
2.78728699e+02, 2.91452618e+01, 4.12124878e+02],
[1.13750778e+02, 3.04266022e+02, 0.00000000e+00, ...,
4.93073273e+02, 0.00000000e+00, 1.25463562e+02]],
[[0.00000000e+00, 2.36886551e+02, 1.87017990e+02, ...,
0.00000000e+00, 5.56484497e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.29744125e+02, 5.47009888e+02, 0.00000000e+00],
[2.10977726e+01, 0.00000000e+00, 5.83388855e+02, ...,
3.78568268e+02, 1.76858459e+03, 0.00000000e+00],
...,
[0.00000000e+00, 2.26063950e+02, 0.00000000e+00, ...,
1.74201874e+02, 1.10421577e+02, 2.92625153e+02],
[0.00000000e+00, 1.49054639e+03, 1.73763367e+02, ...,
3.43214760e+01, 1.41045761e+02, 5.26752502e+02],
[1.79130356e+02, 4.18553101e+02, 1.12429085e+02, ...,
2.08473053e+02, 0.00000000e+00, 1.46159897e+02]],
...,
[[0.00000000e+00, 0.00000000e+00, 6.14884460e+02, ...,
4.48683044e+02, 2.60172217e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.05306360e+03, 5.45696045e+02, 0.00000000e+00],
[5.33453941e+01, 0.00000000e+00, 6.09368164e+02, ...,
7.00016541e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
2.49793106e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.44778638e+03, ...,
1.97339310e+02, 0.00000000e+00, 0.00000000e+00],
[1.27069351e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.85339737e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 4.90521271e+02, ...,
4.68645844e+02, 3.26934399e+03, 0.00000000e+00],
[2.26508102e+01, 0.00000000e+00, 7.08834915e+01, ...,
1.11953967e+03, 1.10590857e+03, 0.00000000e+00],
[1.11061287e+02, 0.00000000e+00, 8.05527405e+02, ...,
8.03228516e+02, 2.84233459e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.10313757e+03, ...,
5.78258667e+02, 1.47924316e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 1.59146082e+03, ...,
7.10267578e+02, 6.43671143e+02, 0.00000000e+00],
[3.27744568e+02, 0.00000000e+00, 0.00000000e+00, ...,
4.53388458e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.12306348e+03, ...,
1.63393646e+02, 3.52517969e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 6.36935806e+01, ...,
4.52494598e+02, 1.94326257e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
2.83666046e+02, 4.89346985e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.02328314e+03, ...,
2.65413391e+02, 2.64639990e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
4.30894745e+02, 1.33343530e+03, 0.00000000e+00],
[7.57115707e+01, 0.00000000e+00, 0.00000000e+00, ...,
2.14354630e+02, 0.00000000e+00, 0.00000000e+00]]]],
dtype=float32)


features2:



array([[[[2.44103737e+01, 3.35516052e+02, 0.00000000e+00, ...,
0.00000000e+00, 2.06830643e+02, 0.00000000e+00],
[4.71717712e+02, 0.00000000e+00, 0.00000000e+00, ...,
2.63770996e+02, 0.00000000e+00, 0.00000000e+00],
[3.93549591e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.77212814e+02, 0.00000000e+00, 0.00000000e+00],
...,
[5.33919487e+01, 0.00000000e+00, 0.00000000e+00, ...,
1.85940536e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 2.96363708e+02, 0.00000000e+00, ...,
1.09057648e+02, 0.00000000e+00, 0.00000000e+00],
[2.27105503e+01, 8.29022141e+01, 0.00000000e+00, ...,
1.38949188e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 2.47062546e+02, ...,
0.00000000e+00, 1.66465466e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
6.74320862e+02, 4.15592712e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
8.65957825e+02, 8.59399170e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.66129944e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 2.76259674e+02, 0.00000000e+00, ...,
8.00474930e+01, 0.00000000e+00, 1.08291901e+02],
[0.00000000e+00, 2.20606117e+01, 0.00000000e+00, ...,
1.28005768e+02, 0.00000000e+00, 3.49725151e+01]],
[[0.00000000e+00, 2.14503006e+02, 8.82690811e+01, ...,
0.00000000e+00, 5.60968628e+02, 0.00000000e+00],
[3.28399010e+01, 0.00000000e+00, 0.00000000e+00, ...,
3.34213745e+02, 2.90819824e+02, 0.00000000e+00],
[8.66472626e+01, 0.00000000e+00, 1.10250635e+03, ...,
6.37486572e+02, 1.67822144e+03, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
5.90463066e+01, 0.00000000e+00, 9.77452278e+00],
[0.00000000e+00, 3.39350586e+02, 4.62688398e+00, ...,
1.32679808e+00, 0.00000000e+00, 1.65987671e+02],
[2.47563610e+01, 7.48269196e+01, 1.33592939e+01, ...,
6.36582108e+01, 0.00000000e+00, 5.70933228e+01]],
...,
[[0.00000000e+00, 0.00000000e+00, 6.27470215e+02, ...,
2.55267532e+02, 2.27369629e+03, 0.00000000e+00],
[1.52827530e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.20087329e+03, 0.00000000e+00, 0.00000000e+00],
[1.33066071e+02, 0.00000000e+00, 5.95311890e+02, ...,
7.66817871e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
4.81101898e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.99484155e+03, ...,
5.40802429e+02, 0.00000000e+00, 0.00000000e+00],
[1.93494095e+02, 0.00000000e+00, 1.16481377e+02, ...,
3.75594208e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 5.08203369e+02, ...,
3.65947357e+02, 2.66369580e+03, 0.00000000e+00],
[2.29821182e+02, 0.00000000e+00, 3.83578918e+02, ...,
1.37410413e+03, 1.28806320e+02, 0.00000000e+00],
[1.89210968e+02, 0.00000000e+00, 9.40994324e+02, ...,
8.16117615e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.34960962e+03, ...,
1.03916003e+03, 6.58975891e+02, 0.00000000e+00],
[6.77491531e+01, 0.00000000e+00, 2.07465186e+03, ...,
1.13461414e+03, 0.00000000e+00, 0.00000000e+00],
[2.96653259e+02, 0.00000000e+00, 0.00000000e+00, ...,
6.33178528e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.20268628e+03, ...,
6.86023560e+01, 2.83282886e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.50556335e+02, ...,
8.04942566e+02, 7.94925537e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.74615967e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.17975757e+03, ...,
6.35223450e+02, 1.62643567e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
9.20189697e+02, 4.05781097e+02, 0.00000000e+00],
[1.26037315e+02, 0.00000000e+00, 0.00000000e+00, ...,
4.17285614e+02, 0.00000000e+00, 0.00000000e+00]]]],
dtype=float32)


The image is taken from here. Path: v1.3/Code/Ours/Images_GroundTruth/BSD200/335094.png



Edit 1: Added additional code and results










share|improve this question















I'm extracting intermediate layer outputs from pretrained VGG19 ConvNet for a given image. I expect that if I give the same image twice, I should get the same output. But, I'm not getting the same output. Why is this happening and how to fix this?



Additional Details:
I'm following this paper. They use a VGG19 ConvNet and extract the features from some intermediate layer (VGG22 means 2nd layer before 2nd convolution) for Super-Resolved Image and Ground-Truth Image. Then they calculate the mean squared error between these 2 feature sets and use it as a loss parameter. Now, my expectation is that if I give Ground Truth Image only twice, the mean squared error should be zero. But it is not happening? I'm getting different feature values at different iteration, but with same image. Also I noticed that, when I run the program again afresh, I get the same set of values. Code below for reference:



import numpy
from keras import backend as K
from keras.applications.vgg19 import VGG19, preprocess_input
from keras.preprocessing.image import img_to_array, load_img


model = VGG19()
vgg22_layer_output = K.function([model.layers[0].input], [model.layers[5].output])

# image_matrix is a 224x224x3 matrix for an RGB-image.
hr_image_obj = load_img(hr_image_path)
hr_image_matrix = img_to_array(hr_image_obj)
cropped_hr_image = hr_image_matrix[0:224, 0:224, :]
expanded_image = numpy.expand_dims(cropped_hr_image, axis=0)
preprocessed_image = preprocess_input(expanded_image)
features1 = vgg22_layer_output ([preprocessed_image])[0]
features2 = vgg22_layer_output ([preprocessed_image])[0]


Here, my expectation is that features1 = features2, which isn't



Results:



features1:



array([[[[2.15184002e+01, 1.81470230e+02, 0.00000000e+00, ...,
0.00000000e+00, 1.98130661e+02, 0.00000000e+00],
[2.27056488e+02, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[1.54923904e+02, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
...,
[2.29082489e+02, 2.58140778e+02, 0.00000000e+00, ...,
3.18900665e+02, 0.00000000e+00, 0.00000000e+00],
[1.58660873e+02, 1.24280603e+03, 0.00000000e+00, ...,
2.76672821e+02, 0.00000000e+00, 0.00000000e+00],
[2.66982513e+02, 4.27661194e+02, 0.00000000e+00, ...,
4.57434418e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.71959274e+02, ...,
0.00000000e+00, 1.25863232e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.51934662e+02, 4.45714081e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.73108368e+02, 7.51479004e+02, 0.00000000e+00],
...,
[0.00000000e+00, 3.06031370e+00, 0.00000000e+00, ...,
3.09630096e+02, 2.15055069e+02, 1.91232590e+02],
[0.00000000e+00, 1.33151245e+03, 0.00000000e+00, ...,
2.78728699e+02, 2.91452618e+01, 4.12124878e+02],
[1.13750778e+02, 3.04266022e+02, 0.00000000e+00, ...,
4.93073273e+02, 0.00000000e+00, 1.25463562e+02]],
[[0.00000000e+00, 2.36886551e+02, 1.87017990e+02, ...,
0.00000000e+00, 5.56484497e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.29744125e+02, 5.47009888e+02, 0.00000000e+00],
[2.10977726e+01, 0.00000000e+00, 5.83388855e+02, ...,
3.78568268e+02, 1.76858459e+03, 0.00000000e+00],
...,
[0.00000000e+00, 2.26063950e+02, 0.00000000e+00, ...,
1.74201874e+02, 1.10421577e+02, 2.92625153e+02],
[0.00000000e+00, 1.49054639e+03, 1.73763367e+02, ...,
3.43214760e+01, 1.41045761e+02, 5.26752502e+02],
[1.79130356e+02, 4.18553101e+02, 1.12429085e+02, ...,
2.08473053e+02, 0.00000000e+00, 1.46159897e+02]],
...,
[[0.00000000e+00, 0.00000000e+00, 6.14884460e+02, ...,
4.48683044e+02, 2.60172217e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.05306360e+03, 5.45696045e+02, 0.00000000e+00],
[5.33453941e+01, 0.00000000e+00, 6.09368164e+02, ...,
7.00016541e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
2.49793106e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.44778638e+03, ...,
1.97339310e+02, 0.00000000e+00, 0.00000000e+00],
[1.27069351e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.85339737e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 4.90521271e+02, ...,
4.68645844e+02, 3.26934399e+03, 0.00000000e+00],
[2.26508102e+01, 0.00000000e+00, 7.08834915e+01, ...,
1.11953967e+03, 1.10590857e+03, 0.00000000e+00],
[1.11061287e+02, 0.00000000e+00, 8.05527405e+02, ...,
8.03228516e+02, 2.84233459e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.10313757e+03, ...,
5.78258667e+02, 1.47924316e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 1.59146082e+03, ...,
7.10267578e+02, 6.43671143e+02, 0.00000000e+00],
[3.27744568e+02, 0.00000000e+00, 0.00000000e+00, ...,
4.53388458e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.12306348e+03, ...,
1.63393646e+02, 3.52517969e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 6.36935806e+01, ...,
4.52494598e+02, 1.94326257e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
2.83666046e+02, 4.89346985e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.02328314e+03, ...,
2.65413391e+02, 2.64639990e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
4.30894745e+02, 1.33343530e+03, 0.00000000e+00],
[7.57115707e+01, 0.00000000e+00, 0.00000000e+00, ...,
2.14354630e+02, 0.00000000e+00, 0.00000000e+00]]]],
dtype=float32)


features2:



array([[[[2.44103737e+01, 3.35516052e+02, 0.00000000e+00, ...,
0.00000000e+00, 2.06830643e+02, 0.00000000e+00],
[4.71717712e+02, 0.00000000e+00, 0.00000000e+00, ...,
2.63770996e+02, 0.00000000e+00, 0.00000000e+00],
[3.93549591e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.77212814e+02, 0.00000000e+00, 0.00000000e+00],
...,
[5.33919487e+01, 0.00000000e+00, 0.00000000e+00, ...,
1.85940536e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 2.96363708e+02, 0.00000000e+00, ...,
1.09057648e+02, 0.00000000e+00, 0.00000000e+00],
[2.27105503e+01, 8.29022141e+01, 0.00000000e+00, ...,
1.38949188e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 2.47062546e+02, ...,
0.00000000e+00, 1.66465466e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
6.74320862e+02, 4.15592712e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
8.65957825e+02, 8.59399170e+02, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
1.66129944e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 2.76259674e+02, 0.00000000e+00, ...,
8.00474930e+01, 0.00000000e+00, 1.08291901e+02],
[0.00000000e+00, 2.20606117e+01, 0.00000000e+00, ...,
1.28005768e+02, 0.00000000e+00, 3.49725151e+01]],
[[0.00000000e+00, 2.14503006e+02, 8.82690811e+01, ...,
0.00000000e+00, 5.60968628e+02, 0.00000000e+00],
[3.28399010e+01, 0.00000000e+00, 0.00000000e+00, ...,
3.34213745e+02, 2.90819824e+02, 0.00000000e+00],
[8.66472626e+01, 0.00000000e+00, 1.10250635e+03, ...,
6.37486572e+02, 1.67822144e+03, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
5.90463066e+01, 0.00000000e+00, 9.77452278e+00],
[0.00000000e+00, 3.39350586e+02, 4.62688398e+00, ...,
1.32679808e+00, 0.00000000e+00, 1.65987671e+02],
[2.47563610e+01, 7.48269196e+01, 1.33592939e+01, ...,
6.36582108e+01, 0.00000000e+00, 5.70933228e+01]],
...,
[[0.00000000e+00, 0.00000000e+00, 6.27470215e+02, ...,
2.55267532e+02, 2.27369629e+03, 0.00000000e+00],
[1.52827530e+02, 0.00000000e+00, 0.00000000e+00, ...,
1.20087329e+03, 0.00000000e+00, 0.00000000e+00],
[1.33066071e+02, 0.00000000e+00, 5.95311890e+02, ...,
7.66817871e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
4.81101898e+02, 0.00000000e+00, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.99484155e+03, ...,
5.40802429e+02, 0.00000000e+00, 0.00000000e+00],
[1.93494095e+02, 0.00000000e+00, 1.16481377e+02, ...,
3.75594208e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 5.08203369e+02, ...,
3.65947357e+02, 2.66369580e+03, 0.00000000e+00],
[2.29821182e+02, 0.00000000e+00, 3.83578918e+02, ...,
1.37410413e+03, 1.28806320e+02, 0.00000000e+00],
[1.89210968e+02, 0.00000000e+00, 9.40994324e+02, ...,
8.16117615e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.34960962e+03, ...,
1.03916003e+03, 6.58975891e+02, 0.00000000e+00],
[6.77491531e+01, 0.00000000e+00, 2.07465186e+03, ...,
1.13461414e+03, 0.00000000e+00, 0.00000000e+00],
[2.96653259e+02, 0.00000000e+00, 0.00000000e+00, ...,
6.33178528e+02, 0.00000000e+00, 0.00000000e+00]],
[[0.00000000e+00, 0.00000000e+00, 1.20268628e+03, ...,
6.86023560e+01, 2.83282886e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 3.50556335e+02, ...,
8.04942566e+02, 7.94925537e+02, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.74615967e+02, 0.00000000e+00, 0.00000000e+00],
...,
[0.00000000e+00, 0.00000000e+00, 1.17975757e+03, ...,
6.35223450e+02, 1.62643567e+03, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
9.20189697e+02, 4.05781097e+02, 0.00000000e+00],
[1.26037315e+02, 0.00000000e+00, 0.00000000e+00, ...,
4.17285614e+02, 0.00000000e+00, 0.00000000e+00]]]],
dtype=float32)


The image is taken from here. Path: v1.3/Code/Ours/Images_GroundTruth/BSD200/335094.png



Edit 1: Added additional code and results







python tensorflow image-processing keras vgg-net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 1:47

























asked Nov 22 at 18:54









Nagabhushan S N

403413




403413












  • The code you included doesn't show the problem, please add more detail and actual results you get.
    – Matias Valdenegro
    Nov 22 at 20:59










  • I've added more detail and results. Please let me know if you need more info and what exactly you want. Thanks!
    – Nagabhushan S N
    Nov 23 at 1:52






  • 1




    I have run the code you provided with that specific image and got equal features1 and features2 (numpy.array_equal(features1, features2) was True). So, the problem probably lies somewhere else.
    – Kilian Batzner
    Nov 23 at 13:36










  • Oh! Might be then. Thanks for checking. Currently, I am using another method to get the features as given here: keras.io/getting-started/faq/… (1st method). It is giving same values. I'll investigate later what was going wrong. Thanks again!
    – Nagabhushan S N
    Nov 23 at 15:22










  • I have narrowed down the error. The hr_image_matrix i.e. the image read using keras' load_img and img_to_array functions was somehow giving negative values for the image matrix. Very strange. So, I replaced that with cv2.imread(hr_image_path, cv2.IMREAD_COLOR) and then its working as expected.
    – Nagabhushan S N
    Nov 23 at 16:28


















  • The code you included doesn't show the problem, please add more detail and actual results you get.
    – Matias Valdenegro
    Nov 22 at 20:59










  • I've added more detail and results. Please let me know if you need more info and what exactly you want. Thanks!
    – Nagabhushan S N
    Nov 23 at 1:52






  • 1




    I have run the code you provided with that specific image and got equal features1 and features2 (numpy.array_equal(features1, features2) was True). So, the problem probably lies somewhere else.
    – Kilian Batzner
    Nov 23 at 13:36










  • Oh! Might be then. Thanks for checking. Currently, I am using another method to get the features as given here: keras.io/getting-started/faq/… (1st method). It is giving same values. I'll investigate later what was going wrong. Thanks again!
    – Nagabhushan S N
    Nov 23 at 15:22










  • I have narrowed down the error. The hr_image_matrix i.e. the image read using keras' load_img and img_to_array functions was somehow giving negative values for the image matrix. Very strange. So, I replaced that with cv2.imread(hr_image_path, cv2.IMREAD_COLOR) and then its working as expected.
    – Nagabhushan S N
    Nov 23 at 16:28
















The code you included doesn't show the problem, please add more detail and actual results you get.
– Matias Valdenegro
Nov 22 at 20:59




The code you included doesn't show the problem, please add more detail and actual results you get.
– Matias Valdenegro
Nov 22 at 20:59












I've added more detail and results. Please let me know if you need more info and what exactly you want. Thanks!
– Nagabhushan S N
Nov 23 at 1:52




I've added more detail and results. Please let me know if you need more info and what exactly you want. Thanks!
– Nagabhushan S N
Nov 23 at 1:52




1




1




I have run the code you provided with that specific image and got equal features1 and features2 (numpy.array_equal(features1, features2) was True). So, the problem probably lies somewhere else.
– Kilian Batzner
Nov 23 at 13:36




I have run the code you provided with that specific image and got equal features1 and features2 (numpy.array_equal(features1, features2) was True). So, the problem probably lies somewhere else.
– Kilian Batzner
Nov 23 at 13:36












Oh! Might be then. Thanks for checking. Currently, I am using another method to get the features as given here: keras.io/getting-started/faq/… (1st method). It is giving same values. I'll investigate later what was going wrong. Thanks again!
– Nagabhushan S N
Nov 23 at 15:22




Oh! Might be then. Thanks for checking. Currently, I am using another method to get the features as given here: keras.io/getting-started/faq/… (1st method). It is giving same values. I'll investigate later what was going wrong. Thanks again!
– Nagabhushan S N
Nov 23 at 15:22












I have narrowed down the error. The hr_image_matrix i.e. the image read using keras' load_img and img_to_array functions was somehow giving negative values for the image matrix. Very strange. So, I replaced that with cv2.imread(hr_image_path, cv2.IMREAD_COLOR) and then its working as expected.
– Nagabhushan S N
Nov 23 at 16:28




I have narrowed down the error. The hr_image_matrix i.e. the image read using keras' load_img and img_to_array functions was somehow giving negative values for the image matrix. Very strange. So, I replaced that with cv2.imread(hr_image_path, cv2.IMREAD_COLOR) and then its working as expected.
– Nagabhushan S N
Nov 23 at 16:28

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436736%2flayer-output-of-keras-pre-trained-vgg19-model-produces-different-outputs-for-sam%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436736%2flayer-output-of-keras-pre-trained-vgg19-model-produces-different-outputs-for-sam%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks