当前位置: 首页>>代码示例>>Python>>正文


Python Dense.get_shape方法代码示例

本文整理汇总了Python中keras.layers.Dense.get_shape方法的典型用法代码示例。如果您正苦于以下问题:Python Dense.get_shape方法的具体用法?Python Dense.get_shape怎么用?Python Dense.get_shape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keras.layers.Dense的用法示例。


在下文中一共展示了Dense.get_shape方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __build_network

# 需要导入模块: from keras.layers import Dense [as 别名]
# 或者: from keras.layers.Dense import get_shape [as 别名]
    def __build_network(self):
        embedding_layer = Embedding(
            self.corpus_size,
            EMBEDDING_DIM,
            weights=[self.embedding_matrix],
            input_length=MAX_TITLE_LENGTH,
            trainable=False)
        # train a 1D convnet with global maxpooling
        sequence_input = Input(shape=(MAX_TITLE_LENGTH, ), dtype='int32')
        embedded_sequences = embedding_layer(sequence_input)
        x = LSTM(
            128,
            dropout_W=0.2,
            dropout_U=0.2,
            W_regularizer=regularizers.l2(0.01),
            b_regularizer=regularizers.l2(0.01))(embedded_sequences)
        x = Dropout(0.5)(x)
        preds = Dense(self.class_num, activation='softmax')(x)
        print preds.get_shape()
        if self.optimizer == 'adam':
            self.optimizer = Adam(lr=self.lr)
        if self.optimizer == 'rmsprop':
            self.optimizer = RMSprop(lr=self.lr)

        # rmsprop = RMSprop(lr=self.lr)
        self.model = Model(sequence_input, preds)
        self.model.compile(
            loss='categorical_crossentropy',
            optimizer=self.optimizer,
            metrics=['acc'])
开发者ID:SiyuanWei,项目名称:tensorflow-101,代码行数:32,代码来源:lstm_text_classifier.py

示例2: __build_network

# 需要导入模块: from keras.layers import Dense [as 别名]
# 或者: from keras.layers.Dense import get_shape [as 别名]
    def __build_network(self):
        embedding_layer = Embedding(self.corpus_size,
                            EMBEDDING_DIM,
                            weights=[self.embedding_matrix],
                            input_length=MAX_SEQUENCE_LENGTH,
                            trainable=False)
        # train a 1D convnet with global maxpooling
        sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
        embedded_sequences = embedding_layer(sequence_input)
        # sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
        # embedded_sequences = embedding_layer(sequence_input)
        x = Convolution1D(128, 5)(embedded_sequences)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        x = MaxPooling1D(5)(x)
        x = Convolution1D(128, 5)(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        x = MaxPooling1D(5)(x)
        print "before 256", x.get_shape()
        x = Convolution1D(128, 5)(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        print "before 35 ", x.get_shape()
        x = MaxPooling1D(35)(x)
        x = Flatten()(x)
        # print x.shape()

        x = Dense(128, activation='relu')(x)
        print x.get_shape()
        x = Dropout(0.5)(x)
        print x.get_shape()
        preds = Dense(self.class_num, activation='softmax')(x)
        print preds.get_shape()
        # conv_blocks = []
        # for sz in self.filter_sizes:
        #     conv = Convolution1D(filters=self.num_filters, kernel_size=sz, activation="relu", padding='valid', strides=1)(embedded_sequences)
        #     conv = MaxPooling1D(pool_size=2)(conv)
        #     conv = Flatten()(conv)
        #     conv_blocks.append(conv)
        # z = Concatenate()(conv_blocks) if len(conv_blocks) > 1 else conv_blocks[0]
        # z = Dropout(rate=0.5)(z)
        # z = Dense(units=self.hidden_dims, activation="relu")(z)
        # preds = Dense(self.class_num, activation="softmax")(z)
        rmsprop = RMSprop(lr=0.001)
        self.model = Model(sequence_input, preds)
        self.model.compile(loss='categorical_crossentropy', optimizer=rmsprop, metrics=['acc'])
开发者ID:SiyuanWei,项目名称:tensorflow-101,代码行数:49,代码来源:cnn_text_classifier.py

示例3: __build_network

# 需要导入模块: from keras.layers import Dense [as 别名]
# 或者: from keras.layers.Dense import get_shape [as 别名]
 def __build_network(self):
     embedding_layer = Embedding(self.corpus_size,
                         EMBEDDING_DIM,
                         weights=[self.embedding_matrix],
                         input_length=MAX_SEQUENCE_LENGTH,
                         trainable=False)
     # train a 1D convnet with global maxpooling
     sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
     embedded_sequences = embedding_layer(sequence_input)
     x = Convolution1D(self.num_filters, 5, activation="relu")(embedded_sequences)
     x = MaxPooling1D(5)(x)
     x = Convolution1D(self.num_filters, 5, activation="relu")(x)
     x = MaxPooling1D(5)(x)
     x = LSTM(64, dropout_W=0.2, dropout_U=0.2)(x)
     preds = Dense(self.class_num, activation='softmax')(x)
     print preds.get_shape()
     rmsprop = RMSprop(lr=0.01)
     self.model = Model(sequence_input, preds)
     self.model.compile(loss='categorical_crossentropy', optimizer=rmsprop, metrics=['acc'])
开发者ID:SiyuanWei,项目名称:tensorflow-101,代码行数:21,代码来源:cnn_lstm_text_classifier.py

示例4: get_ResNet_classifier

# 需要导入模块: from keras.layers import Dense [as 别名]
# 或者: from keras.layers.Dense import get_shape [as 别名]
def get_ResNet_classifier():
    inputs = Input((CLASSIFY_INPUT_WIDTH, CLASSIFY_INPUT_HEIGHT, CLASSIFY_INPUT_DEPTH, CLASSIFY_INPUT_CHANNEL))

    x = conv_bn_relu(inputs, RESNET_INITIAL_FILTERS)

    print('base')
    print(x.get_shape())

    for i in range(RESNET_BLOCKS):
        x = bottleneck(x, shrinkage=(i % RESNET_SHRINKAGE_STEPS == 0))

    print('top')
    x = GlobalMaxPooling3D()(x)
    print(x.get_shape())

    x = Dense(2, activation='softmax')(x)
    print(x.get_shape())

    model = Model(inputs=inputs, outputs=x)
    model.compile(optimizer=Adam(lr=TRAIN_CLASSIFY_LEARNING_RATE), loss='binary_crossentropy', metrics=['accuracy'])

    return model
开发者ID:csyyyyyyy,项目名称:Tianchi-Medical-LungTumorDetect,代码行数:24,代码来源:model_ResNet.py


注:本文中的keras.layers.Dense.get_shape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。