Questions tagged [libtorch]

libtorch is the PyTorch's C++ frontend providing a high-level interaction for the machine learning research and production use.

Filter by
Sorted by
Tagged with
0votes
0answers
18views

Is it possible to perform inference given preallocated input and output tensors in GPU memory?

I'd like to perform inference completely in GPU. Is it possible to place a completely trained neural network in GPU memory, place some neural network input data in GPU memory, preallocate GPU memory ...
user avatar
0votes
0answers
18views

add class to torch module list

I am using libtorch to create a model. In that, I have a class named Layer1. I need to add it to the moduleList. class Layer1 : torch::nn::Module { public: Layer1(int input_dim, int ...
user avatar
  • 155
0votes
0answers
24views

How can I convert float * to Eigen::ArrayXXf

I get a tensor from forward().toTensor in libtorch, how can I covert the data to Eigen::ArrayXXf? like this at::Tensor tsr = module.forward(inputs).toTuple()->elements()[0].toTensor(); float* ...
user avatar
  • 421
0votes
0answers
46views

PyTorch causing problems with CUDA on Colab

I am trying to implement a face extraction model using Colab. For that, I am removing Colab's CUDA to install 10-2 and I'm also installing Anaconda. This is the entirety: import condacolab, torch, sys,...
user avatar
  • 2,474
2votes
0answers
65views

Debugging C++ in VSCode - gdb attach fails to read the values inside custom class objects

I am working on a project that uses both Python and C++. Here is the launch.json file: { "logging": { "engineLogging": true }, "configurations": [ ...
user avatar
  • 1,411
1vote
1answer
63views

libtorch c++ undefined reference: DSO missing from command line

I'm trying to include libtorch in a c++ project to use a neural network I previously trained in python. But when I try to compile and link I get an error with an undefined reference issue and also '...
user avatar
0votes
1answer
15views

How to repeat tensor in libtorch

I am using libtorch to inference, I have read data from txt file to vector and convert to tensor, I want to repeat a tensor three times then change it to 3D, I tried this std::vector<std::vector<...
user avatar
  • 421
0votes
1answer
29views

How to modify a 2d tensor to 3d in libtorch?

I have a 2d array vector<vector>, I have coverted it to tensor, but how to modify the dimension of the tensor, I want to modify the dimension from 2d to 3d? std::vector<std::vector<float&...
user avatar
  • 421
0votes
1answer
25views

PyTorch C++ Frontend: Registering New Modules and using them during Forward

I am creating a model that is empty like so: struct TestNet : torch::nn::Module { TestNet() { } torch::Tensor Forward(torch::Tensor x) { return x; } }; I then register ...
user avatar
  • 71
0votes
0answers
13views

OpenCV C++ - Grabbing or selecting a specific tile or part of an image

I'm cutting my image into tiles in order to transform them into a torch::Tensor and apply neural net inference. However, I had completely wrong predictions when using the first approach (method 1). I'...
user avatar
0votes
0answers
25views

How to load the MNIST dataset from the datasets in torch C++

I'm new to torch and c++ i want to create a basic simple network that does hand digit recognition this is my Net struct. struct Net:torch::nn::Module { Net() { fc1 = register_module("...
user avatar
  • 4,246
0votes
1answer
100views

undefined symbol error when importing libtorch function via pybind11

I am attempting to write a C++ function in libtorch, compile it with pybind11 and then import the .so file in a python file. The build seems to work fine (no errors are emitted) but, when I try to ...
user avatar
  • 1,411
0votes
0answers
14views

libtorch) I want to use torch:module:linear, but a memory error occurs in WrapFunctioninto.h

I'm very, very sorry. It's a translator. OTL....... enter image description here https://www.kaggle.com/jongbeompark/house-prices-with-pytorch/notebook I'd like to pytorch the pytorch code here to ...
user avatar
0votes
1answer
28views

LibTorch sizeof tensor

I would like to know how I can get the size in bytes of the data type of a torch::Tensor. I saw somewhere online that sizeof(tensor.dtype()) should work, but for my float32 tensor it prints out 1.
user avatar
  • 1,065
0votes
1answer
59views

Load TorchScript model exported by Python in LibTorch via std::istream

I have exported a standard pretrained PyTorch model in Python with the following code: import torch import torchvision model = torchvision.models.resnext50_32x4d(pretrained=True) model.eval() example ...
user avatar
  • 1,065
1vote
1answer
37views

std::vector, how does it store values with libtorch tensors?

When I was collecting trainable parameters as vector<torch::tensor>, I've realized that it is type cast to torch::autograd::VariableList. With this structure, how does the vector access its ...
user avatar
0votes
0answers
31views

libtorch softmax analytic gradients

I'm running small validation tests on the analytical softmax gradient computation that autograd performs, for which I hope to evaluate the expected analytic gradient and compare with what libtorch is ...
user avatar
  • 24.5k
1vote
0answers
12views

Convert a tensor with type caffe2::TypeMeta to std::vector

I have an tensor with type caffe2::TypeMeta, and I need to get its value as a regular std::vector object. I know how to convert a Torch::Tensor object with a regular type to a std::vector object, but ...
user avatar
0votes
0answers
73views

libtorch initialize Adam Optimizer

I am using libtorch to implement some optimize code in c++; For some reason, I need to create a tensor that its value is between(-0.5,0.5) as a jitter for another tensor. So I implement that in this ...
user avatar
  • 11
0votes
0answers
13views

How to use Caffe2:TypeMeta

What is the usage of Caffe2:TypeMeta? I found the following description: TypeMeta is a thin class that allows us to store the type of a container such as a blob, or the data type of a tensor, with a ...
user avatar
0votes
1answer
7views

Create an instance of AdamParamState

I need to create an instance of AdamParamState. I looked through the adam.cpp code as an example, and accordingly copied the following code from there. But, with the provided headers, it still does ...
user avatar
1vote
0answers
15views

How to sync the device setting between pytorch(python) and libtorch(C++)?

There is a annoying problem when using a libtorch function in pytorch(python). The device setting in libtorch is k:CUDA, and its default meaning is CUDA:0. But when I use it in python pytorch, I want ...
user avatar
0votes
0answers
17views

Access the optimizer state_dict

In Python one can get the the underlying data of an optimizer by calling the optimizer.state_dict(). For example for the Adam optimizer, it returns the number of steps, exponential moving average of ...
user avatar
0votes
0answers
48views

How can I include a missing library to my build with cmake?

When I try to build my project it says a library is missing. I try to include the library my CMakeLists.txt I get the same LIBRARY-NOTFOUND error and a new error for trying to include it that says, ...
user avatar
0votes
0answers
48views

LIBRARY-NOTFOUND errors in my LibTorch for aarch64 cause the build to fail

I installed LibTorch to my Jetson AGX Xavier (aarch64) and I'm getting library not found errors. I downloaded pytorch by git clone from the official GitHub. Link here https://github.com/pytorch/...
user avatar
1vote
0answers
26views

Can libtorch for CUDA 11.3 work on a PC CUDA 11.5 installed?

Could anyone please tell me if libtorch for CUDA 11.3 can work on a PC in which "nvidia-smi" shows CUDA 11.5? Thank you.
user avatar
  • 11
0votes
1answer
60views

Wrong input shape error in torchscript and C++ interface

I am trying to interface libtorch and OpenCV to predict the classes using the Yolov5 model. The weight I am using is yolov5s.pt. The source code is cv::Mat image = file->input_image(); // read ...
user avatar
  • 1,255
0votes
0answers
81views

Dlls are too big. Is there a way to reduce dependencies size?

I'm using libtorch in my c++ project and some dlls are extremely big. torch_cuda_cu.dll 1374 mb. torch_cpu.dll 206 mb. Is there a way to pull needed functions from these dll to bind them to project ...
user avatar
  • 1,081
0votes
1answer
66views

Libtorch only has cmake config file but needs to build with meson

I'm trying to make a cpp project that uses libtorch (C++ distributions of pytorch) using meson build. It has one simple cpp file of about 50 lines that runs deep learning on images. First, I confirmed ...
user avatar
0votes
0answers
113views

OpenMP based extension for Pytorch with CUDA

I try to develop a pytorch extension with libtorch and OpenMP. When I test my code, it goes well in CPU model and takes about 1s to finish all operations: s = time.time() adj_matrices = ...
user avatar
0votes
0answers
172views

How to disable multithreading in PyTorch?

I am trying to ensure that a PyTorch program build in c++ uses only a single thread. The program runs on CPU. It has a fairly small model, and multi-threading doesn't help and actually causes problems ...
user avatar
  • 2,465
0votes
0answers
117views

Google Colab: Nvidia-Smi and Libtorch not compatible anymore

The problem is new and has never happened before, so there might have been an update of the nvidia driver or libtorch. Problem: I am using Google Colab for additional GPU and want to install a ...
user avatar
0votes
0answers
32views

Libtorch c++ train model on cloud TPU

I'm trying to run PyTorch on TPU's. However I am unable to determine how to get a compilation with the XLA Device.The PyTorch precompiled versions don't have XLA and the from source instructions don't ...
user avatar
1vote
0answers
35views

How to set libtorch in QT environment(My system: win10, qt5.14,) [closed]

How to set QT when using libtorch in QT environment? My system: win10, qt5.14,
user avatar
1vote
1answer
201views

How to input an Int argument to the forward function of torch::jit::script::Module

I converted nn.Module with torch.jit.script and saved it in .pt format. The forward function in that module has an Int argument. def forward(self, x: Tensor, id : int) -> Tensor: print(...
user avatar
  • 11
0votes
0answers
36views

[libtorch][torch.jit.script][input dynamic shape]Error in loading “. pt” file on C + +: index out of range

Because it is the company’s internal code, I can’t disclose it.I can only briefly describe the phenomenon: I’m trying to deploy a model, but its input contains dynamic dimensions: it works normally ...
user avatar
0votes
0answers
62views

libtorch throws c10::error after build on Windows 10 (VS2019)

I've tried to build libtorch on Windows 10 using VS 2019 without CUDA and Python. Independent if I compile it with or without MKL, a simple test program crashes directly after start. After building ...
user avatar
  • 1,413
-1votes
1answer
92views

Distributing CUDA runtime to customers but it's too big

At my company, we are building software that we need to push to customers when we update software (It's being pushed to custom hardware). We have a GPU on that custom hardware that is fixed, but ...
user avatar
  • 2,181
0votes
0answers
136views

Compile libtorch with g++ on windows?

I want to compile libtorch on windows using g++. Is this currently possible? I have currently downloaded the latest version of libtorch and I am trying to compile the following code: #include <...
user avatar
0votes
0answers
129views

Cause of cmake build error finding g++.exe files using Windows and Mingw (Libtorch Installation)?

Following the guidelines found on https://pytorch.org/cppdocs/installing.html, I am trying to install Libtorch. I am on Windows and using MinGW to get the compiler. I followed the instructions as well ...
user avatar
  • 25
0votes
1answer
60views

How to use collate_fn in LibTorch

I'm trying to implement an image based regression using a CNN in libtorch. The problem is, that my images got different sizes, which will cause an Exception batching the images. First things first, I ...
user avatar
  • 778
0votes
0answers
47views

Torchlib C++ Conv2D not working as intended

I have a kernel of size [3,3] and an image of size [B, 3, H, W] I want to apply the same kernel in parallel across those 3 channels. They do not share data across channels This is my code auto ...
user avatar
  • 2,181
0votes
1answer
103views

Difference In the output image when using traced model(.pt) with C++ and OpenCV

I have retrained the model based on EnlightenGAN. Further I have traced the model in order to execute it in a C++ application using libTorch v1.6. However, I am getting slightly different results as ...
user avatar
1vote
1answer
131views

Convert at::Tensor to double in C++ when using LibTorch (PyTorch)

In the following code, I want to compare the loss (data type at::Tensor) with a lossThreshold (data type double). I want to convert loss to double before making that comparison. How do I do it? int ...
user avatar
  • 139
0votes
0answers
117views

Python with C++: CUDA, cuSPARSE compilation gives an undefined symbol error

My goal is to run a Python function calling C++/CUDA functions, which use cuBLAS and cuSPARSE. First, I compile a custom library using setuptools with no errors. Then, I run a python script that ...
user avatar
1vote
1answer
47views

LibTorch and OpenCV Libs not working in same cmakelist file

cmake_minimum_required(VERSION 3.1 FATAL_ERROR) project(Detect) #set(Torch "/home/somnath/libtorch/share/cmake/Torch") find_package(Torch REQUIRED) find_package(OpenCV REQUIRED) message(...
user avatar
2votes
0answers
619views

'torch/torch.h' file not found in header file

I'm new in Linux C++ programming. I have to use libtorch (pytorch C++ version), but I kept struggling with C++ and cmake problems. These problems really make me mad, and I need some help. Here is a ...
user avatar
  • 89
0votes
0answers
41views

LNK2019 in qmlcache_loader.obj when using QtCreator + msvc2017 to compile QML+opencv+libtorch project

I'm trying to combine two project (QML widow project and OpenCV+Libtorch project) in QtCreator. Funny that I can run QML project properly in QtCreator by MSVC2017x64Release, and run OpenCV+libTorch ...
user avatar
0votes
0answers
53views

Using Libtorch with Pybind + Module Extension

I wrote a custom module extension in C++, and compiled it with Pybind. However, when I load it in Python i get a missing symbol error: _ZNK5torch8autograd4Node4nameB5cxx11Ev // Inherit from Function ...
user avatar
  • 2,181
0votes
0answers
36views

Custom Libtorch Function to pybind?

I see the following tutorial: https://pytorch.org/tutorials/advanced/cpp_autograd.html And it shows me how to setup my own module for a certain function in C++. But it does not tell me how exactly to ...
user avatar
  • 2,181

15 30 50 per page
1
2 3 4 5