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_dense.py 2.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 Dense """
  16. import numpy as np
  17. import mindspore.nn as nn
  18. from mindspore import Tensor
  19. from ..ut_filter import non_graph_engine
  20. class Net(nn.Cell):
  21. """Net definition"""
  22. def __init__(self,
  23. input_channels,
  24. output_channels,
  25. weight='normal',
  26. bias='zeros',
  27. has_bias=True):
  28. super(Net, self).__init__()
  29. self.fc = nn.Dense(input_channels,
  30. output_channels,
  31. weight,
  32. bias,
  33. has_bias)
  34. def construct(self, input_x):
  35. return self.fc(input_x)
  36. @non_graph_engine
  37. def test_compile():
  38. weight = Tensor(np.ones([12, 8], np.float32))
  39. bias = Tensor(np.ones([12], np.float32))
  40. net = Net(8, 12, weight=weight, bias=bias)
  41. input_data = Tensor(np.ones([1, 8], np.float32))
  42. # since simulator currently not support matMul
  43. output = net(input_data)
  44. print(output.asnumpy())
  45. @non_graph_engine
  46. def test_compile_nobias():
  47. weight = Tensor(np.ones([12, 8], np.float32))
  48. net = Net(8, 12, weight=weight, has_bias=False)
  49. input_data = Tensor(np.ones([1, 8], np.float32))
  50. # since simulator currently not support matMu
  51. # enable it when staging function is ready
  52. output = net(input_data)
  53. print(output.asnumpy())