Update README.md
Browse files
README.md
CHANGED
@@ -22,6 +22,55 @@ This model classifies animals among pandas, cats and dogs. It was trained using
|
|
22 |
- **License:** MIT
|
23 |
- **Contact:** [email protected]
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
### Project Structure
|
26 |
```bash
|
27 |
|
|
@@ -29,7 +78,8 @@ This model classifies animals among pandas, cats and dogs. It was trained using
|
|
29 |
| |---images(used for examples)
|
30 |
|
|
31 |
|---models
|
32 |
-
|
|
|
|
33 |
|---train(image dataset for training)
|
34 |
|
|
35 |
|---test(image dataset for testing)
|
|
|
22 |
- **License:** MIT
|
23 |
- **Contact:** [email protected]
|
24 |
|
25 |
+
### Data Preprocessing
|
26 |
+
The image dataset is preprocessed with the following portion:
|
27 |
+
```bash
|
28 |
+
transform = transforms.Compose([
|
29 |
+
transforms.Resize((224,224)),
|
30 |
+
transforms.ToTensor(),
|
31 |
+
transforms.Normalize((0.485,0.456,0.406),(0.229,0.224,0.225))
|
32 |
+
])
|
33 |
+
```
|
34 |
+
|
35 |
+
transforms.Resize((224,224)) resizes the input image to (224, 224) pixels.
|
36 |
+
transforms.ToTensor() converts the input image into a PyTorch tensor. Neural networks typically operate on tensors, so this transformation converts the image into a format suitable for further processing.
|
37 |
+
transforms.Normalize(()) normalizes the tensor image with mean and standard deviation. The values provided are mean and standard deviation values for each channel in the tensor.
|
38 |
+
|
39 |
+
### Model Architecture
|
40 |
+
|
41 |
+
The model was trained with custom CNN() model. this CNN architecture consists of two convolutional layers followed by two fully connected layers, and it is designed for a classification task with three classes.
|
42 |
+
|
43 |
+
```bash
|
44 |
+
class CNN(nn.Module):
|
45 |
+
def __init__(self):
|
46 |
+
super(CNN, self).__init__()
|
47 |
+
self.conv1 = nn.Conv2d(3, 6, 5)
|
48 |
+
self.conv2 = nn.Conv2d(6, 16, 5)
|
49 |
+
self.pool = nn.MaxPool2d(2, 2)
|
50 |
+
self.fc1 = nn.Linear(16 * 53 * 53, 120)
|
51 |
+
self.fc2 = nn.Linear(120, 84)
|
52 |
+
self.fc3 = nn.Linear(84, 3)
|
53 |
+
|
54 |
+
def forward(self, x):
|
55 |
+
x = self.conv1(x)
|
56 |
+
x = self.pool(x)
|
57 |
+
x = self.conv2(x)
|
58 |
+
x = self.pool(x)
|
59 |
+
x = x.view(-1, 16 * 53 * 53)
|
60 |
+
x = self.fc1(x)
|
61 |
+
x = self.fc2(x)
|
62 |
+
x = self.fc3(x)
|
63 |
+
return x
|
64 |
+
|
65 |
+
```
|
66 |
+
Then used batch_size = 8 and CrossEntropyLoss() for loss function. Then used Adam optimizer with a learning rate 0.001 for optimization process.
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
### Project Structure
|
75 |
```bash
|
76 |
|
|
|
|
78 |
| |---images(used for examples)
|
79 |
|
|
80 |
|---models
|
81 |
+
| |---cat_dog_cnn.pt
|
82 |
+
|
|
83 |
|---train(image dataset for training)
|
84 |
|
|
85 |
|---test(image dataset for testing)
|