配置新的c++/python联合编程环境
因此我们需要重新配置一下环境。。
克隆环境
conda create -n pt17two --clone pt17
export failure: Exporting the operator silu to ONNX opset version 12 is not supported. Please open a bug to request ONNX export support for the missing operator.
如果有需要转onnx,遇到过一个bug,export failure: Exporting the operator silu to ONNX opset version 12 is not supported. Please open a bug to request ONNX export support for the missing operator. 这是因为onnx与pytorch一些方法不兼容导致的,onnx不支持silu,把**函数换一种写法即可。解决方式如下:
C:\ProgramData\Anaconda3\envs\pt17two\Lib\site-packages\torch\nn\modules
(这里路径因人而异,我是建的虚拟环境)找到该路径下的 activation.py 脚本,然后按照下面的方式进行修改即可。
class SiLU(Module):
r"""Applies the silu function, element-wise.
.. math::
\text{silu}(x) = x * \sigma(x), \text{where } \sigma(x) \text{ is the logistic sigmoid.}
.. note::
See `Gaussian Error Linear Units (GELUs) <https://arxiv.org/abs/1606.08415>`_
where the SiLU (Sigmoid Linear Unit) was originally coined, and see
`Sigmoid-Weighted Linear Units for Neural Network Function Approximation
in Reinforcement Learning <https://arxiv.org/abs/1702.03118>`_ and `Swish:
a Self-Gated Activation Function <https://arxiv.org/abs/1710.05941v1>`_
where the SiLU was experimented with later.
Shape:
- Input: :math:`(N, *)` where `*` means, any number of additional
dimensions
- Output: :math:`(N, *)`, same shape as the input
Examples::
>>> m = nn.SiLU()
>>> input = torch.randn(2)
>>> output = m(input)
"""
__constants__ = ['inplace']
inplace: bool
def __init__(self, inplace: bool = False):
super(SiLU, self).__init__()
self.inplace = inplace
def forward(self, input: Tensor) -> Tensor:
# ------------------------------------- #
# 把F.silu替换掉,修改后如下
return input * torch.sigmoid(input)
#原来的代码
return F.silu(input, inplace=self.inplace)
成功。。