divideconcept / PyTorch-libtorch-U-Net

A customizable 1D/2D U-Net model for libtorch (PyTorch C++ UNet)
MIT License
26 stars 4 forks source link

Is have example on a real corpus? #3

Open faranaziz opened 3 years ago

faranaziz commented 3 years ago

Dear team, thanks you for great project! I try write data loader in C++ for training, but not much success. Did you try this code on an open source DB?

divideconcept commented 3 years ago

Hi, I would not waste to much time with the C++ dataset loader and would instead write my own C++ tensor loading routine. There's a very useful function in libtorch : torch::from_blob(). It allows you to load any C++ array into a PyTorch tensor. It works like this: torch::from_blob(pointerToFloatDataArray,{dimension1,dimension2,...});

faranaziz commented 3 years ago

OK, Thanks. You use it to load PNG / JPEG images that you first read into a C++ array?

divideconcept commented 3 years ago

I use it with spectrograms data but yes that's the same principle. If you want to use it with pictures, you would have to load your png/jpeg images into c++ memory arrays (using functions not provided with libtorch) and then upload those arrays to pytorch tensors using torch::from_blob.

Pseudo-code for one image would be something like that: char* rgbArray=loadImage(...); torch::Tensor imgTensor = torch::from_blob(rgbArray, {channels, width, height}, torch::kFloat);

faranaziz commented 3 years ago

Thanks! You generate the spectrograms offline using Python (npy) and then read them from C++?

divideconcept commented 3 years ago

I generate spectrograms in real time directly in C++. I've created this library for my software SpectraLayers.

faranaziz commented 3 years ago

Library looks amazing. Does it only work as a plug-in?

faranaziz commented 3 years ago

And you use U-net for process spectograms?

divideconcept commented 3 years ago

If you're referring to SpectraLayers, it's both a plugin and a stand-alone application. I indeed use U-Net for several spectrogram processing (for most AI-driven processes, actually).

faranaziz commented 3 years ago

Yes, I register on steinberg but no can download. Will try again later.

divideconcept commented 3 years ago

You can download SpectraLayers directly from here: https://www.steinberg.net/en/support/downloads/downloads_spectralayers_7.html

faranaziz commented 3 years ago

Thanks! How did you read a wav file into a torch::tensor? Using any third party? Thanks.