<jupyter_start><jupyter_text>Loading and preprocessing the data from the problem: State Farm Distracted Driver Detection<jupyter_code>RESOLUTION = 150
BATCH_SIZE = 256

train_datagen = ImageDataGenerator(rescale=1./255, validation_split=0.15)
val_datagen = ImageDataGenerator(rescale=1./255, validation_split=0.15)

train_generator = train_datagen.flow_from_directory(
        '/content/drive/My Drive/deeplearning_cursoCienciaDados_Insight/notebooks/data/state-farm-distracted-driver-detection/',
        target_size=(RESOLUTION, RESOLUTION),
        class_mode='categorical', subset="training")

val_generator = val_datagen.flow_from_directory(
        '/content/drive/My Drive/deeplearning_cursoCienciaDados_Insight/notebooks/data/state-farm-distracted-driver-detection/',
        target_size=(RESOLUTION, RESOLUTION),
        class_mode='categorical', subset="validation")
train_generator.class_indices<jupyter_output><empty_output><jupyter_text>Traning a CNN model<jupyter_code>model = models.Sequential()
model.add(layers.Conv2D(filters= 100, kernel_size=(3, 3), activation='relu', input_shape=(150, 150, 3))) #(image_height, image_width, image_channels) (not including the batch dimension).
model.add(layers.Conv2D(filters = 100, kernel_size=(3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Flatten()) 
model.add(layers.Dense(units= 100, activation='relu'))
model.add(layers.Dense(units=10, activation='softmax'))
model.summary()
model.compile(optimizer='rmsprop',
    loss='binary_crossentropy',
    metrics=['acc'])

N_TRAIN = 7826
N_VAL = 1379

history = model.fit_generator(
    train_generator,
    steps_per_epoch=(N_TRAIN // BATCH_SIZE),
    epochs=5,
    validation_data=val_generator,
    validation_steps=(N_VAL // BATCH_SIZE) 
    )
acc = history.history['acc']
val_acc = history.history['val_acc']
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(1, len(acc) + 1)

plt.plot(epochs, acc, label='Training accuracy', marker='x')
plt.plot(epochs, val_acc, label='Validation accuracy', marker='o')
plt.title('Training and validation accuracy')
plt.legend()
plt.figure()

plt.plot(epochs, loss, label='Training loss', marker='x')
plt.plot(epochs, val_loss, label='Validation loss', marker='o')
plt.title('Training and validation loss')
plt.legend()

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13942712721145745, 'fraction_numerical': 0.02443133951137321, 'mean_word_length': 6.636655948553055, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '280315', 'license': 'MIT', 'n_tokens_mistral': 858, 'n_tokens_neox': 796, 'n_words': 133, 'path': '2019/09-Redes_Neurais_e_Aprendizado_Profundo/CNN.ipynb', 'repo_name': 'InsightLab/imersao-ciencia-de-dados-2019', 'size': '2374'}