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.

test_quant.py 1.9 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. """ tests for quant """
  16. import mindspore.context as context
  17. from mindspore import nn
  18. context.set_context(mode=context.GRAPH_MODE, device_target="GPU")
  19. class LeNet5(nn.Cell):
  20. """
  21. Lenet network
  22. Args:
  23. num_class (int): Num classes. Default: 10.
  24. Returns:
  25. Tensor, output tensor
  26. Examples:
  27. >>> LeNet(num_class=10)
  28. """
  29. def __init__(self, num_class=10):
  30. super(LeNet5, self).__init__()
  31. self.num_class = num_class
  32. self.conv1 = nn.Conv2dBnAct(1, 6, kernel_size=5, batchnorm=True, activation='relu6')
  33. self.conv2 = nn.Conv2dBnAct(6, 16, kernel_size=5, activation='relu')
  34. self.fc1 = nn.DenseBnAct(16 * 5 * 5, 120, activation='relu')
  35. self.fc2 = nn.DenseBnAct(120, 84, activation='relu')
  36. self.fc3 = nn.DenseBnAct(84, self.num_class)
  37. self.max_pool2d = nn.MaxPool2d(kernel_size=2, stride=2)
  38. self.flattern = nn.Flatten()
  39. def construct(self, x):
  40. x = self.conv1(x)
  41. x = self.bn(x)
  42. x = self.relu(x)
  43. x = self.max_pool2d(x)
  44. x = self.conv2(x)
  45. x = self.max_pool2d(x)
  46. x = self.flattern(x)
  47. x = self.fc1(x)
  48. x = self.fc2(x)
  49. x = self.fc3(x)
  50. return x