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.

lenet_script.py 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Test network script of LeNet for ST test case data."""
  16. import torch.nn as nn
  17. import torch.nn.functional as F
  18. class TestLeNet(nn.Module):
  19. """TestLeNet network."""
  20. def __init__(self):
  21. self.conv1 = nn.Conv2d(3, 6, 5)
  22. self.conv2 = nn.Conv2d(6, 16, 5)
  23. self.fc1 = nn.Linear(16 * 5 * 5, 120)
  24. self.fc2 = nn.Linear(120, 84)
  25. self.fc3 = nn.Linear(84, 10)
  26. def forward(self, input_x):
  27. """Callback method."""
  28. out = F.relu(self.conv1(input_x))
  29. out = F.max_pool2d(out, 2)
  30. out = F.relu(self.conv2(out))
  31. out = F.max_pool2d(out, 2)
  32. out = out.view(out.size(0), -1)
  33. out = F.relu(self.fc1(out))
  34. out = F.relu(self.fc2(out))
  35. out = self.fc3(out)
  36. return out