我的意思是,我不知道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)