【问题标题】:What is meant by sequential model in KerasKeras中的顺序模型是什么意思
【发布时间】:2020-01-05 03:57:15
【问题描述】:

我最近开始使用 Tensorflow 进行深度学习。我发现这个声明 model = tf.keras.models.Sequential() 有点不同。我无法理解它的实际含义,是否还有其他模型可用于深度学习? 我在 MatconvNet(卷积神经网络的 Matlab 库)上做了很多工作。从未见过任何顺序定义。

【问题讨论】:

    标签: python tensorflow keras tf.keras


    【解决方案1】:

    正如其他人已经提到的那样,“顺序模型是层的线性堆叠。

    Sequential 模型 API 是一种创建深度学习模型的方法,其中创建了 Sequential 类的实例,并创建了模型层并将其添加到其中。

    添加图层最常用的方法是分段

    import keras
    from keras.models import Sequential
    from keras.layers import Dense
    
    #initialising the classifier
    #defining sequential i.e sequense of layers
    
    
    classifier = Sequential()
    
    # Adding the input layer and the first hidden layer
    classifier.add(Dense(units = 6,activation = 'relu'))
    #units = 6 as no. of column in X_train = 11 and y_train =1 --> 11+1/2
    
    #Adding the second hidden lyer
    classifier.add(Dense(units = 6, activation='relu'))
    
    #adding the output layer
    classifier.add(Dense(units = 1, activation = 'sigmoid))
    

    【讨论】:

      【解决方案2】:

      构建 Keras 模型有两种方法:顺序和函数。

      顺序 API 允许您为大多数问题逐层创建模型。它的局限性在于它不允许您创建共享层或具有多个输入或输出的模型。

      另外,功能性 API 允许您创建具有更大灵活性的模型,因为您可以轻松定义模型,其中层连接到的不仅仅是上一层和下一层。事实上,您可以将层连接到(字面上)任何其他层。因此,创建孪生网络和残差网络等复杂网络成为可能。

      更多详情请访问:https://machinelearningmastery.com/keras-functional-api-deep-learning/

      【讨论】:

      • 谢谢。另外有没有最好的方法从数据类型 .mat 的文件夹中读取图像?
      【解决方案3】:

      Sequential 模型是层的线性堆叠。

      ConvNets 的常见架构是顺序架构。然而,一些架构不是线性堆栈。例如,孪生网络是两个具有一些共享层的并行神经网络。 More examples here.

      【讨论】:

        【解决方案4】:

        根据 Keras 文档的定义,Sequential 模型是层的线性堆栈。您可以通过将层实例列表传递给构造函数来创建 Sequential 模型:

        from keras.models import Sequential
        from keras.layers import Dense, Activation
        
        model = Sequential([
            Dense(32, input_shape=(784,)),
            Activation('relu'),
            Dense(10),
            Activation('softmax'),
        ])
        

        您也可以通过 .add() 方法简单地添加图层:

        model = Sequential()
        model.add(Dense(32, input_dim=784))
        model.add(Activation('relu'))
        

        更多详情请点击here

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-11-05
          • 2013-10-26
          • 1970-01-01
          • 2019-02-27
          • 1970-01-01
          • 2016-04-12
          • 2019-12-10
          • 2016-11-28
          相关资源
          最近更新 更多