Keras:InputLayer和Input的区别 [英] Keras: difference of InputLayer and Input
本文介绍了Keras:InputLayer和Input的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用带有Tensorflow的Keras制作了模型.我在这些代码行中使用Inputlayer
:
I made a model using Keras with Tensorflow. I use Inputlayer
with these lines of code:
img1 = tf.placeholder(tf.float32, shape=(None, img_width, img_heigh, img_ch))
first_input = InputLayer(input_tensor=img1, input_shape=(img_width, img_heigh, img_ch))
first_dense = Conv2D(16, 3, 3, activation='relu', border_mode='same', name='1st_conv1')(first_input)
但是我得到这个错误:
ValueError: Layer 1st_conv1 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.engine.topology.InputLayer'>. Full input: [<keras.engine.topology.InputLayer object at 0x00000000112170F0>]. All inputs to the layer should be tensors.
当我这样使用Input
时,效果很好:
When I use Input
like this, it works fine:
first_input = Input(tensor=img1, shape=(224, 224, 3), name='1st_input')
first_dense = Conv2D(16, 3, 3, activation='relu', border_mode='same', name='1st_conv1')(first_input)
Inputlayer
和Input
有什么区别?
推荐答案
-
InputLayer
是一层. -
Input
是张量. InputLayer
is a layer.Input
is a tensor.
您只能调用将张量传递给它们的图层.
You can only call layers passing tensors to them.
想法是:
outputTensor = SomeLayer(inputTensor)
因此,只有Input
可以通过,因为它是张量.
So, only Input
can be passed because it's a tensor.
老实说,我不知道InputLayer
存在的原因.也许应该在内部使用.我从没使用过,而且似乎永远也不需要.
Honestly, I have no idea about the reason for the existence of InputLayer
. Maybe it's supposed to be used internally. I never used it, and it seems I'll never need it.
这篇关于Keras:InputLayer和Input的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文