<jupyter_start><jupyter_text>Redes Neuronales Convolucionales**Instalar Theano*** pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git**Instalar Tensorflow y Keras*** conda install -c conda-forge keras  Part 1 - Building the CNN<jupyter_code># Importing the Keras libraries and packages
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
# Initialising the CNN
classifier = Sequential()<jupyter_output><empty_output><jupyter_text>--- Step 1 - Convolution<jupyter_code>classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu'))<jupyter_output><empty_output><jupyter_text>--- Step 2 - Pooling<jupyter_code>classifier.add(MaxPooling2D(pool_size = (2, 2)))
# Adding a second convolutional layer
classifier.add(Conv2D(32, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))<jupyter_output><empty_output><jupyter_text>--- Step 3 - Flattening<jupyter_code>classifier.add(Flatten())<jupyter_output><empty_output><jupyter_text>--- Step 4 - Full connection<jupyter_code>classifier.add(Dense(units = 128, activation = 'relu'))
classifier.add(Dense(units = 1, activation = 'sigmoid'))
# Compiling the CNN
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])<jupyter_output><empty_output><jupyter_text>Part 2 - Fitting the CNN to the images<jupyter_code>from keras.preprocessing.image import ImageDataGenerator

train_datagen = ImageDataGenerator(rescale = 1./255,
                                   shear_range = 0.2,
                                   zoom_range = 0.2,
                                   horizontal_flip = True)

test_datagen = ImageDataGenerator(rescale = 1./255)

training_set = train_datagen.flow_from_directory('dataset/training_set',
                                                 target_size = (64, 64),
                                                 batch_size = 32,
                                                 class_mode = 'binary')

test_set = test_datagen.flow_from_directory('dataset/test_set',
                                            target_size = (64, 64),
                                            batch_size = 32,
                                            class_mode = 'binary')

classifier.fit_generator(training_set,
                         steps_per_epoch =100,
                         epochs = 5,
                         validation_data = test_set,
                         validation_steps = 2000)<jupyter_output>Found 8000 images belonging to 2 classes.
Found 2000 images belonging to 2 classes.
Epoch 1/5
100/100 [==============================] - 288s 3s/step - loss: 0.6926 - accuracy: 0.5159 - val_loss: 0.6792 - val_accuracy: 0.5096
Epoch 2/5
100/100 [==============================] - 260s 3s/step - loss: 0.6655 - accuracy: 0.5900 - val_loss: 0.6712 - val_accuracy: 0.6464
Epoch 3/5
100/100 [==============================] - 259s 3s/step - loss: 0.6212 - accuracy: 0.6578 - val_loss: 0.6960 - val_accuracy: 0.6366
Epoch 4/5
100/100 [==============================] - 251s 3s/step - loss: 0.5867 - accuracy: 0.6875 - val_loss: 0.4437 - val_accuracy: 0.7204
Epoch 5/5
100/100 [==============================] - 254s 3s/step - loss: 0.5685 - accuracy: 0.7022 - val_loss: 0.4350 - val_accuracy: 0.7123<jupyter_text>Part 3 - Making new predictions<jupyter_code>import numpy as np
from keras.preprocessing import image
test_image = image.load_img('dataset/single_prediction/cat_or_dog_1.jpg', target_size = (64, 64))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = classifier.predict(test_image)
training_set.class_indices
if result[0][0] == 1:
    prediction = 'dog'
else:
    prediction = 'cat'<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14463452566096424, 'fraction_numerical': 0.06350440642820114, 'mean_word_length': 2.970164609053498, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '520320', 'license': 'CC0-1.0', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1198, 'n_words': 265, 'path': 'datasets/Part_2_Convolutional_Neural_Networks_CNN/cnn_homework_solution.ipynb', 'repo_name': 'dasafo/deeplearning-az', 'size': '3858'}