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.

mindspore.nn.SequentialCell.rst 1.7 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. mindspore.nn.SequentialCell
  2. ============================
  3. .. py:class:: mindspore.nn.SequentialCell(*args)
  4. 构造Cell顺序容器。
  5. Cell列表将按照它们在构造函数中传递的顺序添加到其中。
  6. 或者,也可以传入Cell的有序字典。
  7. **参数:**
  8. **args** (list, OrderedDict) - 仅包含Cell子类的列表或有序字典。
  9. **输入:**
  10. **x** (Tensor) - Tensor,其shape取决于序列中的第一个Cell。
  11. **输出:**
  12. Tensor,输出Tensor,其shape取决于输入 `x` 和定义的Cell序列。
  13. **异常:**
  14. **TypeError** - `args` 的类型不是列表或有序字典。
  15. **支持平台:**
  16. ``Ascend`` ``GPU`` ``CPU``
  17. **样例:**
  18. >>> conv = nn.Conv2d(3, 2, 3, pad_mode='valid', weight_init="ones")
  19. >>> relu = nn.ReLU()
  20. >>> seq = nn.SequentialCell([conv, relu])
  21. >>> x = Tensor(np.ones([1, 3, 4, 4]), dtype=mindspore.float32)
  22. >>> output = seq(x)
  23. >>> print(output)
  24. [[[[27. 27.]
  25. [27. 27.]]
  26. [[27. 27.]
  27. [27. 27.]]]]
  28. .. py:method:: append(cell)
  29. 在容器末尾添加一个cell。
  30. **参数:**
  31. **cell** (Cell) - 要添加的cell。
  32. **样例:**
  33. >>> conv = nn.Conv2d(3, 2, 3, pad_mode='valid', weight_init="ones")
  34. >>> bn = nn.BatchNorm2d(2)
  35. >>> relu = nn.ReLU()
  36. >>> seq = nn.SequentialCell([conv, bn])
  37. >>> seq.append(relu)
  38. >>> x = Tensor(np.ones([1, 3, 4, 4]), dtype=mindspore.float32)
  39. >>> output = seq(x)
  40. >>> print(output)
  41. [[[[26.999863 26.999863]
  42. [26.999863 26.999863]]
  43. [[26.999863 26.999863]
  44. [26.999863 26.999863]]]]