Skip to content

Commit c46e9cb

Browse files
committed
Style transfer C++ demo working completely with mosaic. Need to optimize performance.
1 parent 51b79ff commit c46e9cb

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

demos/video/include/cvtool.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,14 @@ cv::Mat to_mat(at::Tensor &tensor, cv::ColorConversionCodes color_conversion) {
223223
int height = tensor.size(2);
224224
int width = tensor.size(3);
225225
auto t = tensor
226-
.mul(255)
226+
.to(torch::kFloat32)
227+
.mul(255.0)
228+
.clamp(0.0, 255.0)
229+
.to(torch::kUInt8)
227230
.squeeze()
228231
.detach()
229232
.permute({1, 2, 0})
230233
.contiguous()
231-
.to(torch::kUInt8)
232234
// .clamp(0, 255)
233235
.clone()
234236
// .to(cvtool::get_default_device(), /*non_blocking=*/true, /*copy=*/true)

demos/video/style-transfer/style_transfer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ int run_webcam_model(torch::jit::Module& module, int cam_index, int max_fps, boo
225225

226226

227227
// // // works
228-
auto processed_input = run_model(module,prepped_input.to(torch::kFloat16)) / 255.0;
229-
auto out_processed_input = processed_input; // processed_input.to(torch::kCPU,true);
230-
output_bgr = to_mat(out_processed_input, cv::COLOR_RGB2BGR);
228+
auto input = input_tensor.to(device,true).to(torch::kFloat16) / 255.0;
229+
auto model_output = run_model(module,input) / 255.0;
230+
output_bgr = to_mat(model_output, cv::COLOR_RGB2BGR);
231231

232232
// // works
233233
// auto processed_input = prepped_input;

0 commit comments

Comments
 (0)