python 无法引用 tensorflow.keras_python-TensorFlow到Keras Tensor

我的意思是,我无法知道什么是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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值