<p dir="auto">struct Net : torch::nn::Module {<br>
Net()<br>
: conv1(torch::nn::Conv2dOptions(1, 20, /<em>kernel_size=</em>/5).stride(1)),<br>
conv2(torch::nn::Conv2dOptions(20, 40, /<em>kernel_size=</em>/5)),<br>
fc1(640, 120),<br>
fc2(120, 10) {<br>
register_module("conv1", conv1);<br>
register_module("conv2", conv2);<br>
register_module("conv2_drop", conv2_drop);<br>
register_module("fc1", fc1);<br>
register_module("fc2", fc2);<br>
}<br>
torch::Tensor forward(torch::Tensor x) {<br>
x = torch::relu(torch::max_pool2d(conv1-&gt;forward(x), 2));//(28-5)+1=24,12 x 12 x 10<br>
x = torch::relu(torch::max_pool2d(conv2_drop-&gt;forward(conv2-&gt;forward(x)), 2));//(12-5)+1=8,4 x 4 x 20<br>
//x = torch::relu(torch::avg_pool2d(conv2_drop-&gt;forward(conv2-&gt;forward(x)), 2));//(12-5)+1=8,4 x 4 x 20</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="	x = x.view({ -1, 640 });
	x = torch::relu(fc1-&gt;forward(x));
	x = torch::dropout(x, /*p=*/0.5, /*training=*/is_training());
	x = fc2-&gt;forward(x);
	return torch::log_softmax(x, /*dim=*/1);
}
torch::nn::Conv2d conv1;
torch::nn::Conv2d conv2;
torch::nn::Dropout2d conv2_drop;
torch::nn::Linear fc1;
torch::nn::Linear fc2;"><pre class="notranslate"><code class="notranslate">	x = x.view({ -1, 640 });
	x = torch::relu(fc1-&gt;forward(x));
	x = torch::dropout(x, /*p=*/0.5, /*training=*/is_training());
	x = fc2-&gt;forward(x);
	return torch::log_softmax(x, /*dim=*/1);
}
torch::nn::Conv2d conv1;
torch::nn::Conv2d conv2;
torch::nn::Dropout2d conv2_drop;
torch::nn::Linear fc1;
torch::nn::Linear fc2;
</code></pre></div>
<p dir="auto">};</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/yf225/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/yf225">@yf225</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/houseroad/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/houseroad">@houseroad</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/spandantiwari/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/spandantiwari">@spandantiwari</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/lara-hdr/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/lara-hdr">@lara-hdr</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/BowenBao/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/BowenBao">@BowenBao</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/neginraoof/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/neginraoof">@neginraoof</a></p>
<h2 dir="auto"><g-emoji class="g-emoji" alias="rocket" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f680.png">🚀</g-emoji> Feature</h2>
<p dir="auto">Having torch onnx feature available through the C++ API.</p>
<h2 dir="auto">Motivation</h2>
<p dir="auto">I have some C++ frontend trained models, and I want to export them in onnx format in order to use them in external inference engines.</p>
<h2 dir="auto">Pitch</h2>
<p dir="auto">Same API as the python's <code class="notranslate">torch.onnx.export</code> would be enough.</p>
<h2 dir="auto">Alternatives</h2>
<p dir="auto">An alternative would be to have easy C++ frontend model import in the python side, but I think this is more related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="403207737" data-permission-text="Title is private" data-url="https://github.com/pytorch/pytorch/issues/16367" data-hovercard-type="issue" data-hovercard-url="/pytorch/pytorch/issues/16367/hovercard" href="https://github.com/pytorch/pytorch/issues/16367">#16367</a></p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/BowenBao/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/BowenBao">@BowenBao</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/neginraoof/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/neginraoof">@neginraoof</a></p>