<jupyter_start><jupyter_text>[Cats VS Dogs Convolutional Classifier](https://towardsdatascience.com/cats-vs-dogs-convolutional-classifier-44ec04c8eb7a)Creating and testing a simple model from scratch for 2D cnn binary classification.![Image of the cnn structure](https://miro.medium.com/max/700/1*7-lqUVzdHS5KDuQCOCJK3Q.png)<jupyter_code># Importing the dataset
!wget --no-check-certificate https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip

import torch, torchvision
from torch import nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()

        self.conv1 = nn.Conv2d(3, 16, kernel_size=3)
        self.conv2 = nn.Conv2d(16, 32, kernel_size=3)
        self.fc1 = nn.Linear(6272, 512)
        self.fc2= nn.Linear(512, 1)
    
    def forward(self, x):
        x = self.conv1(x)
        x = F.relu(x)
        x = F.max_pool2d(x,2)
    
        x = self.conv2(x)
        x = F.relu(x)
        x = F.max_pool2d(x,2)

        x = torch.flatten(x,1)
        x = self.fc1(x)
        x = F.relu(x)
        x = self.fc2(x)
        return torch.sigmoid(x)


# model = nn.Sequential(
#     nn.Conv2d(3, 16, kernel_size=3),
#     nn.ReLU(),
#     nn.MaxPool2d(2),
#     nn.Conv2d(16, 32, kernel_size=3),
#     nn.ReLU(),
#     nn.MaxPool2d(2),
#     nn.Conv2d(32, 64, kernel_size=3),
#     nn.ReLU(),
#     nn.MaxPool2d(2),
#     nn.Flatten(),
#     nn.Linear(64*3, 512),
#     nn.ReLU(),
#     nn.Linear(512, 1),
#     nn.Sigmoid()
# )

model = Model()
print(model)


input = torch.randn(1,3,64,64)
input.shape

output = model(input)
print(output)
optimizer = torch.optim.Adam(
    model.parameters(),
    lr=0.001
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15375722543352602, 'fraction_numerical': 0.05317919075144509, 'mean_word_length': 2.838137472283814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '530980', 'license': 'MIT', 'n_tokens_mistral': 759, 'n_tokens_neox': 696, 'n_words': 121, 'path': 'Cat vs Dog classifier.ipynb', 'repo_name': 'LucHayward/Masters-notebooks', 'size': '1730'}