简体   繁体   English

keras.Sequential()的“ input_shape”格式是什么?

[英]What is the format of “input_shape” is keras.Sequential()?

Following this tensorflow tutorial, under the Build the model section, the first layer of keras.Sequential() is given parameter vocab_size=10000 . 这个 tensorflow教程之后,在Build the model部分下,keras.Sequential()的第一层被赋予参数vocab_size=10000 What does it mean? 这是什么意思?

After looking at the documentation I figured out that, the Sequential model needs to know the shape of the input tensor(tensor to the input layer), and input_shape attribute defines it. 在查看了文档之后,我发现,顺序模型需要知道输入张量的形状(输入层的张量),而input_shape属性定义了它。 But input_shape should be like (30, 50, 50, 3) (for 30, 50x50 RGB images). 但是input_shape应该像( input_shape )(对于30,50x50 RGB图像)。 The value in the tutorial is 10000. 本教程中的值为10000。

For the first part of your question: 对于问题的第一部分:

The example uses an embedding layer. 该示例使用嵌入层。 Think of embedding layer as a lookup matrix. 将嵌入层视为查找矩阵。 Each row will represent a word vector. 每行将代表一个单词向量。 The vocab_size is identifying the size of this matrix (or in other words number of words represented in in this matrix - which is essentially the number of rows of the matrix). vocab_size标识此矩阵的大小(或换句话说,此矩阵中表示的单词数-本质上是矩阵的行数)。

Now to represent an input string, each word will be represented by an integer - which corresponds to the row of the embedding matrix. 现在代表输入字符串,每个单词将由一个整数表示-对应于嵌入矩阵的行。

For second part, I am not sure which example you are referring or what you are trying to do. 对于第二部分,我不确定您要引用哪个示例或您要尝试执行的操作。 However, you might want to know that the number of samples in the batch will not be a part of input_shape. 但是,您可能想知道批次中的样本数量将不是input_shape的一部分。 So the input_shape to pass a batch of 30 samples of 50*50 RGB images will be (50,50,3) 因此,要传递一批30个50 * 50 RGB图像样本的input_shape将为(50,50,3)

Sequential is just a way to define the model, a sort of wrapper, if you want. 顺序式只是定义模型的一种方法,如果需要的话,可以是一种包装器。

It wraps a sequence of layers. 它包装了一系列的层。 The first layer needs an input size. 第一层需要输入大小。

the input shape will be different for each element you are studying: you are correct that the input shape for an image could be (50, 50, 3). 输入的形状对于您正在研究的每个元素都会有所不同:您正确地认为图像的输入形状可能是(50,50,3)。

In the example you provided, the first layer handles word embeddings: the embedding shape is defined by the function that creates the data (lower in your example page there is imdb.load_data() ) 在您提供的示例中,第一层处理单词嵌入:嵌入形状是由创建数据的函数定义的(在示例页面的下面是imdb.load_data()

the vocab_size is not the full shape, but how many "rows" of embeddings you are going to treat as a single input. vocab_size并不是完整的形状,而是您要将多少个“行”的嵌入视为单个输入。

You can see a clearer example here: https://keras.io/layers/embeddings/ 您可以在此处看到更清晰的示例: https//keras.io/layers/embeddings/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM