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_converted.py 1.7 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 mindspore.nn as nn
  17. import mindspore.ops.operations as P
  18. class TestLeNet(nn.Cell):
  19. """TestLeNet network."""
  20. def __init__(self):
  21. self.conv1 = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=5, pad_mode='pad', has_bias=True)
  22. self.conv2 = nn.Conv2d(in_channels=6, out_channels=16, kernel_size=5, pad_mode='pad', has_bias=True)
  23. self.fc1 = nn.Dense(in_channels=16 * 5 * 5, out_channels=120)
  24. self.fc2 = nn.Dense(in_channels=120, out_channels=84)
  25. self.fc3 = nn.Dense(in_channels=84, out_channels=10)
  26. def construct(self, input_x):
  27. """Callback method."""
  28. out = P.ReLU()(self.conv1(input_x))
  29. out = P.MaxPool(2, None, 'valid')(out)
  30. out = P.ReLU()(self.conv2(out))
  31. out = P.MaxPool(2, None, 'valid')(out)
  32. out = P.Reshape()(out, (P.Shape()(out)[0], -1,))
  33. out = P.ReLU()(self.fc1(out))
  34. out = P.ReLU()(self.fc2(out))
  35. out = self.fc3(out)
  36. return out