image similarity model，The input sequence is inconsistent, resulting in inconsistent results
Hi **@yspyhp** ,

Sorry for the delay, 
Image Preprocessing:
Ensure that the images you are using for prediction are preprocessed in the same way as during training. This includes resizing to (224, 224) and applying the same preprocessing steps using preprocess input function.

Model Loading: 
Make sure that the model is loaded properly and the weights are correctly loaded. From the log output, it seems the model is loaded successfully.

Normalization: 
Ensure that the normalization applied during preprocessing is consistent between training and prediction. This includes mean subtraction and scaling.

Data Ordering: 
Check if the data ordering (channels-last or channels-first) is consistent between your training and prediction datasets. ResNet50 usually expects 'channels-last' ordering.
Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/63133">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/63133">No</a>

### Issue type

Support

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

2.11.0

### Custom code

Yes

### OS platform and distribution

_No response_

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

3 files
test.py ==》model definition
image_same_train.py ==> model train
image_same.py ==> model predict

[归档.zip](https://github.com/tensorflow/tensorflow/files/14509907/default.zip)


### Standalone code to reproduce the issue

```shell
import numpy as np
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.preprocessing import image
from tensorflow.keras import backend as K

from test import similarity_model


def preprocess_image(image_path):
    img = image.load_img(image_path, target_size=(224, 224))
    img_array = image.img_to_array(img)
    img_array = np.expand_dims(img_array, axis=0)
    img_array = preprocess_input(img_array)
    return img_array

def extract_features(model, img_array):
    features = model.predict(img_array)
    return features.flatten()


# 读取两个图像
# image_path1 = '/home/hr/projects/baidu/bpit-ateam/aib-service-paddlenlp/jietu-1709715631130.jpg'
# image_path1 = '/home/hr/projects/baidu/bpit-ateam/aib-service-paddlenlp/jietu-1709715631130.jpg'
image_path1 = '/home/hr/projects/baidu/bpit-ateam/aib-service-paddlenlp/jietu-1709643042777.jpg'
# image_path2 = '/home/hr/projects/baidu/bpit-ateam/aib-service-paddlenlp/1574821172023.jpg'
image_path2 = '/home/hr/projects/baidu/bpit-ateam/aib-service-paddlenlp/1574820198658.jpg'
K.set_learning_phase(0)
# 加载预训练的VGG16模型（包括权重）

similarity_model.load_weights('/home/hr/projects/baidu/bpit-ateam/aib-service-paddlenlp/weights.h5')
similarity_model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

print(similarity_model.summary())

# 预处理图像并提取特征
img_array1 = preprocess_image(image_path1)
img_array2 = preprocess_image(image_path2)

features1 = extract_features(similarity_model, [img_array1, img_array2])
features2 = extract_features(similarity_model, [img_array2, img_array1])
print(features1)
print(features2)

features1，features2 is not equal, please help！！
```


### Relevant log output

```shell
2024-03-06 20:27:00.970308: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F AVX512_VNNI FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-03-06 20:27:01.134346: I tensorflow/core/util/port.cc:104] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-03-06 20:27:01.890378: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/hr/python3/lib:/usr/local/cuda-11.2/lib64:/home/hr/python3/lib:/usr/local/cuda-11.2/lib64:
2024-03-06 20:27:01.890456: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/hr/python3/lib:/usr/local/cuda-11.2/lib64:/home/hr/python3/lib:/usr/local/cuda-11.2/lib64:
2024-03-06 20:27:01.890466: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
2024-03-06 20:27:03.184454: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F AVX512_VNNI FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-03-06 20:27:03.958843: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1613] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 18022 MB memory:  -> device: 0, name: Tesla V100-SXM2-32GB, pci bus id: 0000:41:00.0, compute capability: 7.0
/home/hr/python3/lib/python3.7/site-packages/keras/backend.py:452: UserWarning: `tf.keras.backend.set_learning_phase` is deprecated and will be removed after 2020-10-11. To update it, simply pass a True/False value to the `training` argument of the `__call__` method of your layer or model.
  "`tf.keras.backend.set_learning_phase` is deprecated and "
Model: "model"
__________________________________________________________________________________________________
 Layer (type)                   Output Shape         Param #     Connected to                     
==================================================================================================
 input_2 (InputLayer)           [(None, 224, 224, 3  0           []                               
                                )]                                                                
                                                                                                  
 input_3 (InputLayer)           [(None, 224, 224, 3  0           []                               
                                )]                                                                
                                                                                                  
 resnet50 (Functional)          (None, 7, 7, 2048)   23587712    ['input_2[0][0]',                
                                                                  'input_3[0][0]']                
                                                                                                  
 flatten (Flatten)              (None, 100352)       0           ['resnet50[0][0]']               
                                                                                                  
 flatten_1 (Flatten)            (None, 100352)       0           ['resnet50[1][0]']               
                                                                                                  
 dense (Dense)                  (None, 256)          25690368    ['flatten[0][0]']                
                                                                                                  
 dense_1 (Dense)                (None, 256)          25690368    ['flatten_1[0][0]']              
                                                                                                  
 dropout (Dropout)              (None, 256)          0           ['dense[0][0]']                  
                                                                                                  
 dropout_1 (Dropout)            (None, 256)          0           ['dense_1[0][0]']                
                                                                                                  
 lambda (Lambda)                (None, 1)            0           ['dropout[0][0]',                
                                                                  'dropout_1[0][0]']              
                                                                                                  
==================================================================================================
Total params: 74,968,448
Trainable params: 51,380,736
Non-trainable params: 23,587,712
__________________________________________________________________________________________________
None
2024-03-06 20:27:10.269453: I tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:428] Loaded cuDNN version 8101
1/1 [==============================] - 4s 4s/step
1/1 [==============================] - 0s 36ms/step
[0.00075252]
[1.]
```
