# Question IN CNN pytorch

I want to know if I use coefficients in deep learning using CNN to classify them it works or not??

@randino Can you reframe your problem statement. I am unable to understand it

@randino CNN should be used to classify coefficients if your features have spatial relationships. CNN uses filters to transform image like inputs.

If you feel there is spatial relationships or patterns, you can do that

what does mean “your features have spatial relationships” but the code of the CNN is

``````
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
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} %')
``````

first, you are using keras, not pytorch
second, what you provided is only a part of model, there is no layer responsible for classification

what you need for classification is some final layer that has 1 or N outputs for binary classification (True/False or class-wise distribution).

@my3bikaht @anantguptadbl I modified the code

@randino Your approach is correct. You can definitely use CNN to classify images. If your model is not converging, then add more conv layers