title: tensorflow2 problem of loading pb file to predict
body: <p>Currently, I'm using tf2.3 and windows 10 for learning siamese network. The training processing had no problem. I saved the model in pb format by using the <strong>model.fit</strong> and <strong>model.save</strong>.</p>
  <p>Then, I used <strong>tf.keras.models.load_model(&quot;model_pb&quot;,custom_objects={'tf': tf})</strong> to load model and followed by <strong>model.predict</strong>.</p>
  <p>The <strong>model.summary()</strong> information can be printed out, but with the message:<strong>UserWarning: model is not loaded, but a Lambda layer uses it. It may cause errors.</strong> The prediction only shows 0.5 as the result even with different pairs of images, maybe this is caused by unsuccessful model loading (I guess).</p>
  <p>So,could you please tell me how to load the pb model correctly with the lambda layer? or maybe I did something else wrong?</p>
  <p>Thanks in advance.</p>
  <p>Here is my model saving code</p>
  <pre><code>    '''training and validation code end here'''
  model.fit(get_batch(batch_size),
                validation_data = nway_one_shot(model, n_way, n_val),
                epochs = epochs
          )
  
  
  model.save(&quot;/face_recognizer/model_pb&quot;)
  </code></pre>
  <p>Here is my simple_onepair_test.py code</p>
  <pre><code>import tensorflow as tf
  import tensorflow.keras
  
  new_model = tf.keras.models.load_model(&quot;model_pb&quot;,custom_objects={'tf': tf})
  new_model.summary()
  
  
  
  imagepath1 = &quot;/face_recognizer/train/s3/1.jpg&quot;
  imagepath2 = &quot;/face_recognizer/train/s3/2.jpg&quot;
  imagepath = &quot;/face_recognizer/train/s44&quot;
  
  '''
  turn the input1 image into tensor
  '''
  image1 = tf.io.read_file(imagepath1)
  image_tensor1 = tf.image.decode_jpeg(image1,3)
  image_tensor1 = tf.image.resize(image_tensor1,[100,100])
  image_tensor1= image_tensor1/255
  image_tensor1 = tf.cast(image_tensor1,dtype = tf.float32)
  
  '''
  #turn the input2 image into tensor
  '''
  image2 = tf.io.read_file(imagepath2)
  image_tensor2 = tf.image.decode_jpeg(image2,3)
  image_tensor2 = tf.image.resize(image_tensor2,[100,100])
  image_tensor2 = image_tensor2/255
  image_tensor2 = tf.cast(image_tensor2,dtype = tf.float32)
  
  '''
  #expand dims for inputs
  '''
  image1=tf.expand_dims(image_tensor1,axis=0)
  image2 = tf.expand_dims(image_tensor2,axis=0)
  temp=[]
  temp.append(image1)
  temp.append(image2)
  '''
  #predict the image
  '''
  result = new_model.predict(temp, verbose=1)
  print(result)
  </code></pre>
  <p>Here is the printed information</p>
  <pre><code>UserWarning: model is not loaded, but a Lambda layer uses it. It may cause errors.
   
  
   , UserWarning)
  Model: &quot;functional_1&quot;
  __________________________________________________________________________________________________
  Layer (type)                    Output Shape         Param #     Connected to
  ==================================================================================================
  input_1 (InputLayer)            [(None, 100, 100, 3) 0
  __________________________________________________________________________________________________
  input_2 (InputLayer)            [(None, 100, 100, 3) 0
  __________________________________________________________________________________________________
  sequential (Sequential)         (None, 512)          17349824    input_1[0][0]
                                                                   input_2[0][0]
  __________________________________________________________________________________________________
  lambda (Lambda)                 (None, 512)          0           sequential[0][0]
                                                                   sequential[1][0]
  __________________________________________________________________________________________________
  dense_2 (Dense)                 (None, 2048)         1050624     lambda[0][0]
  __________________________________________________________________________________________________
  dense_3 (Dense)                 (None, 1024)         2098176     dense_2[0][0]
  __________________________________________________________________________________________________
  dense_4 (Dense)                 (None, 512)          524800      dense_3[0][0]
  __________________________________________________________________________________________________
  dense_5 (Dense)                 (None, 1)            513         dense_4[0][0]
  ==================================================================================================
  Total params: 21,023,937
  Trainable params: 21,015,489
  Non-trainable params: 8,448
  __________________________________________________________________________________________________
  
  1/1 [==============================] - 0s 2ms/step
  [[0.5]]
  </code></pre>