Cannot Obtain Similar DL Prediction Result in Pytorch C++ API Compared to Python Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsPython plot for confusion matrix similar to confusion wheel?Understanding ConfusionMatrix for Google Prediction APIPython svm classification, result vs amount of features not as expectedCannot get the prediction right using Stochastic Gradient Descent: Always predicts 1I do not understand the prediction result of the CNN modelAre view() in Pytorch and reshape() in Numpy similar?How to use Cross Entropy loss in pytorch for binary prediction?How to use Cross Entropy loss in pytorch for binary prediction?How standardizing and/or log transformation affect prediction result in machine learning models
What is /etc/mtab in Linux?
A strange hotel
What does a straight horizontal line above a few notes, after a changed tempo mean?
I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?
Why do games have consumables?
Is Electric Central Heating worth it if using Solar Panels?
How to keep bees out of canned beverages?
Drawing a german abacus as in the books of Adam Ries
Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?
How to not starve gigantic beasts
How would this chord from "Rocket Man" be analyzed?
A Paper Record is What I Hamper
Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?
A faster way to compute the largest prime factor
Which big number is bigger?
Approximating integral with small parameter
What makes accurate emulation of old systems a difficult task?
What is the ongoing value of the Kanban board to the developers as opposed to management
Putting Ant-Man on house arrest
Is there really no use for MD5 anymore?
Air bladders in bat-like skin wings for better lift?
Older movie/show about humans on derelict alien warship which refuels by passing through a star
Why did C use the -> operator instead of reusing the . operator?
How do I prove this combinatorial identity
Cannot Obtain Similar DL Prediction Result in Pytorch C++ API Compared to Python
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsPython plot for confusion matrix similar to confusion wheel?Understanding ConfusionMatrix for Google Prediction APIPython svm classification, result vs amount of features not as expectedCannot get the prediction right using Stochastic Gradient Descent: Always predicts 1I do not understand the prediction result of the CNN modelAre view() in Pytorch and reshape() in Numpy similar?How to use Cross Entropy loss in pytorch for binary prediction?How to use Cross Entropy loss in pytorch for binary prediction?How standardizing and/or log transformation affect prediction result in machine learning models
$begingroup$
I have trained a deep learning model using unet architecture in order to segment the nuclei in python and pytorch. I would like to load this pretrained model and make prediction in C++. For this reason, I obtained trace file(with pt extension). Then, I have run this code:
#include <iostream>
#include <torch/script.h> // One-stop header.
#include <iostream>
#include <memory>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, const char* argv[])
Mat image;
image = imread("C:/Users/Sercan/PycharmProjects/samplepyTorch/test_2.png", CV_LOAD_IMAGE_COLOR);
std::shared_ptr<torch::jit::script::Module> module = torch::jit::load("C:/Users/Sercan/PycharmProjects/samplepyTorch/epistroma_unet_best_model_trace.pt");
module->to(torch::kCUDA);
std::vector<int64_t> sizes = 1, 3, image.rows, image.cols ;
torch::TensorOptions options(torch::ScalarType::Byte);
torch::Tensor tensor_image = torch::from_blob(image.data, torch::IntList(sizes), options);
tensor_image = tensor_image.toType(torch::kFloat);
auto result = module->forward( tensor_image.to(at::kCUDA) ).toTensor();
result = result.squeeze().cpu();
result = at::sigmoid(result);
cv::Mat img_out(image.rows, image.cols, CV_32F, result.data<float>());
cv::imwrite("img_out.png", img_out);
Image outputs ( First image: test image, Second image: Python prediction result, Third image: C++ prediction result):
As you see, C++ prediction output is not similar to python prediction output. Could you offer a solution to fix this problem?
machine-learning deep-learning computer-vision pytorch
$endgroup$
add a comment |
$begingroup$
I have trained a deep learning model using unet architecture in order to segment the nuclei in python and pytorch. I would like to load this pretrained model and make prediction in C++. For this reason, I obtained trace file(with pt extension). Then, I have run this code:
#include <iostream>
#include <torch/script.h> // One-stop header.
#include <iostream>
#include <memory>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, const char* argv[])
Mat image;
image = imread("C:/Users/Sercan/PycharmProjects/samplepyTorch/test_2.png", CV_LOAD_IMAGE_COLOR);
std::shared_ptr<torch::jit::script::Module> module = torch::jit::load("C:/Users/Sercan/PycharmProjects/samplepyTorch/epistroma_unet_best_model_trace.pt");
module->to(torch::kCUDA);
std::vector<int64_t> sizes = 1, 3, image.rows, image.cols ;
torch::TensorOptions options(torch::ScalarType::Byte);
torch::Tensor tensor_image = torch::from_blob(image.data, torch::IntList(sizes), options);
tensor_image = tensor_image.toType(torch::kFloat);
auto result = module->forward( tensor_image.to(at::kCUDA) ).toTensor();
result = result.squeeze().cpu();
result = at::sigmoid(result);
cv::Mat img_out(image.rows, image.cols, CV_32F, result.data<float>());
cv::imwrite("img_out.png", img_out);
Image outputs ( First image: test image, Second image: Python prediction result, Third image: C++ prediction result):
As you see, C++ prediction output is not similar to python prediction output. Could you offer a solution to fix this problem?
machine-learning deep-learning computer-vision pytorch
$endgroup$
add a comment |
$begingroup$
I have trained a deep learning model using unet architecture in order to segment the nuclei in python and pytorch. I would like to load this pretrained model and make prediction in C++. For this reason, I obtained trace file(with pt extension). Then, I have run this code:
#include <iostream>
#include <torch/script.h> // One-stop header.
#include <iostream>
#include <memory>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, const char* argv[])
Mat image;
image = imread("C:/Users/Sercan/PycharmProjects/samplepyTorch/test_2.png", CV_LOAD_IMAGE_COLOR);
std::shared_ptr<torch::jit::script::Module> module = torch::jit::load("C:/Users/Sercan/PycharmProjects/samplepyTorch/epistroma_unet_best_model_trace.pt");
module->to(torch::kCUDA);
std::vector<int64_t> sizes = 1, 3, image.rows, image.cols ;
torch::TensorOptions options(torch::ScalarType::Byte);
torch::Tensor tensor_image = torch::from_blob(image.data, torch::IntList(sizes), options);
tensor_image = tensor_image.toType(torch::kFloat);
auto result = module->forward( tensor_image.to(at::kCUDA) ).toTensor();
result = result.squeeze().cpu();
result = at::sigmoid(result);
cv::Mat img_out(image.rows, image.cols, CV_32F, result.data<float>());
cv::imwrite("img_out.png", img_out);
Image outputs ( First image: test image, Second image: Python prediction result, Third image: C++ prediction result):
As you see, C++ prediction output is not similar to python prediction output. Could you offer a solution to fix this problem?
machine-learning deep-learning computer-vision pytorch
$endgroup$
I have trained a deep learning model using unet architecture in order to segment the nuclei in python and pytorch. I would like to load this pretrained model and make prediction in C++. For this reason, I obtained trace file(with pt extension). Then, I have run this code:
#include <iostream>
#include <torch/script.h> // One-stop header.
#include <iostream>
#include <memory>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, const char* argv[])
Mat image;
image = imread("C:/Users/Sercan/PycharmProjects/samplepyTorch/test_2.png", CV_LOAD_IMAGE_COLOR);
std::shared_ptr<torch::jit::script::Module> module = torch::jit::load("C:/Users/Sercan/PycharmProjects/samplepyTorch/epistroma_unet_best_model_trace.pt");
module->to(torch::kCUDA);
std::vector<int64_t> sizes = 1, 3, image.rows, image.cols ;
torch::TensorOptions options(torch::ScalarType::Byte);
torch::Tensor tensor_image = torch::from_blob(image.data, torch::IntList(sizes), options);
tensor_image = tensor_image.toType(torch::kFloat);
auto result = module->forward( tensor_image.to(at::kCUDA) ).toTensor();
result = result.squeeze().cpu();
result = at::sigmoid(result);
cv::Mat img_out(image.rows, image.cols, CV_32F, result.data<float>());
cv::imwrite("img_out.png", img_out);
Image outputs ( First image: test image, Second image: Python prediction result, Third image: C++ prediction result):
As you see, C++ prediction output is not similar to python prediction output. Could you offer a solution to fix this problem?
machine-learning deep-learning computer-vision pytorch
machine-learning deep-learning computer-vision pytorch
edited Apr 6 at 7:55
michael scolfield
asked Apr 6 at 7:20
michael scolfieldmichael scolfield
13
13
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48728%2fcannot-obtain-similar-dl-prediction-result-in-pytorch-c-api-compared-to-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48728%2fcannot-obtain-similar-dl-prediction-result-in-pytorch-c-api-compared-to-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown