當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。