Please, look at the code and give me some advice

21fa417e3fb06e56040c: <p>I’m making maskrcnn use libtorch and the result is different from Python.<br>
Can you see the code together? thanks…<br>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicon.ico" class="site-icon" width="32" height="32">
      <a href="https://github.com/kerry-Cho/maskrcnn-libtorch" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars0.githubusercontent.com/u/20694053?s=400&amp;v=4" class="thumbnail onebox-avatar" width="400" height="400">

<h3><a href="https://github.com/kerry-Cho/maskrcnn-libtorch" target="_blank" rel="nofollow noopener">kerry-Cho/maskrcnn-libtorch</a></h3>

<p>Contribute to kerry-Cho/maskrcnn-libtorch development by creating an account on GitHub.</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
<a class="mention" href="/u/lsrk">@lsrk</a></p>

lsrk: <p>Hello !<br>
I didnt see your code deeply, but i found a severe bug.<br>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/kerry-Cho/maskrcnn-libtorch/blob/ad2ba81a556671d3e939386c0431dcb48434edd3/maskrcnn-libtorch/maskrcnn-libtorch.cpp#L34" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/kerry-Cho/maskrcnn-libtorch/blob/ad2ba81a556671d3e939386c0431dcb48434edd3/maskrcnn-libtorch/maskrcnn-libtorch.cpp#L34" target="_blank" rel="nofollow noopener">kerry-Cho/maskrcnn-libtorch/blob/ad2ba81a556671d3e939386c0431dcb48434edd3/maskrcnn-libtorch/maskrcnn-libtorch.cpp#L34</a></h4>
<pre class="onebox"><code class="lang-cpp"><ol class="start lines" start="24" style="counter-reset: li-counter 23 ;">
<li>		//</li>
<li>		//for (auto param : model-&gt;named_parameters())</li>
<li>		//{</li>
<li>		//	std::cout &lt;&lt; param.key() &lt;&lt; "\n";</li>
<li>		//}</li>
<li>
</li>
<li>
</li>
<li>		cv::Mat image = cv::imread("maskrcnn.jpg", cv::IMREAD_COLOR);</li>
<li>		cv::Mat img(480, 640, CV_8UC3);</li>
<li>		cv::resize(image, img, img.size(), 0, 0, cv::INTER_AREA);</li>
<li class="selected">		auto input_ = torch::tensor(at::ArrayRef&lt;uint8_t&gt;(img.data, img.rows * img.cols * 3)).view({ 3, img.rows, img.cols });</li>
<li>		</li>
<li>		//cv::Mat rgb[3];</li>
<li>		//cv::split(image, rgb);</li>
<li>		//// Concatenate channels</li>
<li>		//cv::Mat rgbConcat;</li>
<li>		//cv::vconcat(rgb[0], rgb[1], rgbConcat);</li>
<li>		//cv::vconcat(rgbConcat, rgb[2], rgbConcat);</li>
<li>		//</li>
<li>		//// Convert Mat image to tensor C x H x W</li>
<li>		//at::Tensor tensor_image = torch::from_blob(rgbConcat.data, { image.channels(), image.rows, image.cols }, at::kByte);</li>
</ol></code></pre>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
in this part, code should be</p>
<pre><code class="lang-auto">torch::tensor(at::ArrayRef&lt;uint8_t&gt;(img.data, img.rows * img.cols * 3)).view({ img.rows, img.cols, 3 }).permute({2, 0, 1}).contiguous();
</code></pre>
<p>img axis order is row col channel. so, reshaping to channel row col is destroying image structure.<br>
Permute and reshape is just what you want.</p>