<jupyter_start><jupyter_text>Convolutional Neural Network<jupyter_code>from keras.models import Sequential
from keras.layers import Convolution2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense<jupyter_output>Using TensorFlow backend.<jupyter_text>CNN<jupyter_code># Initialize CNN
classifier = Sequential()

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

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

# Flattening
classifier.add(Flatten())

# Full connection
classifier.add(Dense(output_dim=128, activation='relu'))
classifier.add(Dense(output_dim=1, activation='sigmoid'))

# Compile CNN
classifier.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])<jupyter_output>C:\ProgramData\Anaconda3\envs\py36\lib\site-packages\ipykernel_launcher.py:5: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(32, (3, 3), input_shape=(64, 64, 3..., activation="relu")`
  """
C:\ProgramData\Anaconda3\envs\py36\lib\site-packages\ipykernel_launcher.py:14: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(activation="relu", units=128)`
  
C:\ProgramData\Anaconda3\envs\py36\lib\site-packages\ipykernel_launcher.py:15: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(activation="sigmoid", units=1)`
  from ipykernel import kernelapp as app<jupyter_text>Fit model<jupyter_code>from keras.preprocessing.image import ImageDataGenerator
from IPython.display import display
from PIL import Image

# Training data
train_datagen = ImageDataGenerator(
    rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True
)
training_set = train_datagen.flow_from_directory(
    './dataset/training_set',
    target_size=(64, 64),
    batch_size=32,
    class_mode='binary'
)

# Test data
test_datagen = ImageDataGenerator(rescale=1./255)
test_set = test_datagen.flow_from_directory(
    './dataset/test_set',
    target_size=(64, 64),
    batch_size=32,
    class_mode='binary'
)

# Fit training set
classifier.fit_generator(
    training_set,
    samples_per_epoch=8000,
    nb_epoch=25,
    validation_data=test_set,
    nb_val_samples=2000
)<jupyter_output>Found 8000 images belonging to 2 classes.
Found 2000 images belonging to 2 classes.
{'fraction_non_alphanumeric': 0.11607910576096303, 'fraction_numerical': 0.040842648323301804, 'mean_word_length': 6.182098765432099, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '368286', 'license': 'Unlicense', 'n_tokens_mistral': 884, 'n_tokens_neox': 818, 'n_words': 162, 'path': 'z_Miscellaneous/ML2/DeepLearning/CNN.ipynb', 'repo_name': 'dangkhoa1992/Advanced-Machine-Learning-Specialization', 'size': '2326'}