Question IN CNN pytorch

username: randino
cooked: <p>I want to know if I use coefficients in deep learning using CNN to classify them it works or not??</p>

username: anantguptadbl
cooked: <p><a class="mention" href="/u/randino">@randino</a> Can you reframe your problem statement. I am unable to understand it</p>

username: anantguptadbl
cooked: <p><a class="mention" href="/u/randino">@randino</a> CNN should be used to classify coefficients if your features have spatial relationships. CNN uses filters to transform image like inputs.</p>
<p>If you feel there is spatial relationships or patterns, you can do that</p>

username: randino
cooked: <p>what does mean  “your features have spatial relationships” but the code of the CNN is</p>
<pre><code class="lang-auto">
class Net(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(3, 6, 5)
        self.pool = nn.MaxPool2d(2, 2)
        self.conv2 = nn.Conv2d(6, 16, 5)
        self.fc1 = nn.Linear(16 * 5 * 5, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)

    def forward(self, x):
        x = self.pool(F.relu(self.conv1(x)))
        x = self.pool(F.relu(self.conv2(x)))
        x = torch.flatten(x, 1) # flatten all dimensions except batch
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x
# prepare to count predictions for each class
correct_pred = {classname: 0 for classname in classes}
total_pred = {classname: 0 for classname in classes}

# again no gradients needed
with torch.no_grad():
    for data in testloader:
        images, labels = data
        outputs = net(images)
        _, predictions = torch.max(outputs, 1)
        # collect the correct predictions for each class
        for label, prediction in zip(labels, predictions):
            if label == prediction:
                correct_pred[classes[label]] += 1
            total_pred[classes[label]] += 1


# print accuracy for each class
for classname, correct_count in correct_pred.items():
    accuracy = 100 * float(correct_count) / total_pred[classname]
    print(f'Accuracy for class: {classname:5s} is {accuracy:.1f} %')
</code></pre>

username: my3bikaht
cooked: <aside class="quote no-group quote-modified" data-username="randino" data-post="5" data-topic="142786">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/r/ecd19e/48.png" class="avatar"> randino:</div>
<blockquote>
<p><code>model.add(layers.</code></p>
</blockquote>
</aside>
<p>first, you are using keras, not pytorch<br>
second, what you provided is only a part of model, there is no layer responsible for classification</p>
<p>what you need for classification is some final layer that has 1 or N outputs for binary classification (True/False or class-wise distribution).</p>

username: randino
cooked: <p><a class="mention" href="/u/my3bikaht">@my3bikaht</a> <a class="mention" href="/u/anantguptadbl">@anantguptadbl</a>  I  modified the code</p>

username: anantguptadbl
cooked: <p><a class="mention" href="/u/randino">@randino</a> Your approach is correct. You can definitely use CNN to classify images. If your model is not converging, then add more conv layers</p>

username: randino
cooked: <p><a class="mention" href="/u/anantguptadbl">@anantguptadbl</a>  thank you</p>