我的意思是,我无法知道什么是predict_flow2.我将假设它是Keras张量,但如果不是,则可以概括我的答案.
模型由不完全是功能的图层组成.要使用这样的TF函数(或任何函数),您需要将它们包装在Lambda层周围:
import numpy as np
import tensorflow as tf
from keras import Input, Model
from keras.layers import Lambda
x = Input((224, 224, 3))
h, w = 299, 299
y = Lambda(lambda inputs: tf.image.resize_bilinear(inputs,
tf.stack([h, w]),
align_corners=True))(x)
model = Model(inputs=x, output=y)
model.summary()
p = model.predict(np.random.randn(1, 224, 224, 3))
print('shape:', p.shape)
将输出:
Using TensorFlow backend.
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) (None, 224, 224, 3) 0
_________________________________________________________________
lambda_1 (Lambda) (None, 299, 299, 3) 0
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
_________________________________________________________________
shape: (1, 299, 299, 3)