embedding_vecor_length = 32
    model = Sequential()
    model.add(
        Embedding(max_features,
                  embeddings_dim,
                  input_length=max_sent_len,
                  mask_zero=False,
                  weights=[embedding_weights]))
    model.add(Dropout(dropout_prob[1]))
    model.add(LSTM(100))
    model.add(Dropout(dropout_prob[1]))
    if num_classes == 2:
        model.add(Dense(1, activation='sigmoid'))
    else:
        model.ad(Dense(num_classes, activation='sigmoid'))
    if num_classes == 2:
        model.compile(loss='binary_crossentropy',
                      optimizer='Adagrad',
                      metrics=['accuracy'])
    else:
        model.compile(loss='categorical_crossentropy',
                      optimizer='Adagrad',
                      metrics=['accuracy'])
    #   model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    print(model.summary())

    #    plot_model(model, to_file='C:\\Users\\paperspace\\Desktop\\Plots\\model_plot.png', show_shapes=True, show_layer_names=True)
    plot_model(
        model,
        to_file='C:\\Users\\paperspace\\Desktop\\Plots\\model_plot_LSTM_2.png',
Beispiel #2
0
#Initialising the CNN
classifier = Sequential()

#Step 1 - Convolution
classifier.add(
    Convolution2D(32, 3, 3, input_shape(64, 64, 3), activation='relu'))

#Step 2 - Pooling
classifier.add(MaxPooling2D(pool_size=(2, 2)))

#Step 3 - Flattening
classifier.add(Flatten())

#Step 3 - Full Connection
classifier.ad(Dense(units=128, activation='relu'))
classifier.ad(Dense(units=1, activation='sigmoid'))

#Compiling the CNN
classifier.compile(optimizer='adam',
                   loss='binary_crossentropy',
                   metrics=['accuracy'])

#Part 2 - Fitting the CNN to the images
from keras.preprocessing.image import ImageDataGenerated
train_datagen = ImageDataGenerator(rescale=1. / 255,
                                   shear_range=0.2,
                                   zoom_range=0.2,
                                   horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1. / 255)