You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import torch
  2. from torch import nn
  3. class SymbolNet(nn.Module):
  4. def __init__(self, num_classes=4, image_size=(28, 28, 1)):
  5. super(SymbolNet, self).__init__()
  6. self.conv1 = nn.Sequential(
  7. nn.Conv2d(1, 32, 5, stride=1),
  8. nn.ReLU(),
  9. nn.MaxPool2d(kernel_size=2, stride=2),
  10. nn.BatchNorm2d(32, momentum=0.99, eps=0.001),
  11. )
  12. self.conv2 = nn.Sequential(
  13. nn.Conv2d(32, 64, 5, padding=2, stride=1),
  14. nn.ReLU(),
  15. nn.MaxPool2d(kernel_size=2, stride=2),
  16. nn.BatchNorm2d(64, momentum=0.99, eps=0.001),
  17. )
  18. num_features = 64 * (image_size[0] // 4 - 1) * (image_size[1] // 4 - 1)
  19. self.fc1 = nn.Sequential(nn.Linear(num_features, 120), nn.ReLU())
  20. self.fc2 = nn.Sequential(nn.Linear(120, 84), nn.ReLU())
  21. self.fc3 = nn.Sequential(nn.Linear(84, num_classes))
  22. def forward(self, x):
  23. x = self.conv1(x)
  24. x = self.conv2(x)
  25. x = torch.flatten(x, 1)
  26. x = self.fc1(x)
  27. x = self.fc2(x)
  28. x = self.fc3(x)
  29. return x
  30. class SymbolNetAutoencoder(nn.Module):
  31. def __init__(self, num_classes=4, image_size=(28, 28, 1)):
  32. super(SymbolNetAutoencoder, self).__init__()
  33. self.base_model = SymbolNet(num_classes, image_size)
  34. self.softmax = nn.Softmax(dim=1)
  35. self.fc1 = nn.Sequential(nn.Linear(num_classes, 100), nn.ReLU())
  36. self.fc2 = nn.Sequential(nn.Linear(100, image_size[0] * image_size[1]), nn.ReLU())
  37. def forward(self, x):
  38. x = self.base_model(x)
  39. # x = self.softmax(x)
  40. x = self.fc1(x)
  41. x = self.fc2(x)
  42. return x

An efficient Python toolkit for Abductive Learning (ABL), a novel paradigm that integrates machine learning and logical reasoning in a unified framework.