#include <iostream>
#include <opencv2/opencv.hpp>
#include <torch/torch.h>
#include <dirent.h>
#include <torch/script.h>
Go to the source code of this file.
|
torch::Tensor | read_data (std::string location, int resize) |
| Function to return image read at location given as type torch::Tensor. More...
|
|
torch::Tensor | read_label (int label) |
| Function to return label from int (0, 1 for binary and 0, 1, ..., n-1 for n-class classification) as type torch::Tensor. More...
|
|
std::vector< torch::Tensor > | process_images (std::vector< std::string > list_images, int resize) |
| Function returns vector of tensors (images) read from the list of images in a folder. More...
|
|
std::vector< torch::Tensor > | process_labels (std::vector< int > list_labels) |
| Function returns vector of tensors (labels) read from the list of labels. More...
|
|
std::pair< std::vector< std::string >, std::vector< int > > | load_data_from_folder (std::vector< std::string > folders_name) |
| Function to load data from given folder(s) name(s) (folders_name) Returns pair of vectors of string (image locations) and int (respective labels) More...
|
|
template<typename Dataloader > |
void | train (torch::jit::script::Module net, torch::nn::Linear lin, Dataloader &data_loader, torch::optim::Optimizer &optimizer, size_t dataset_size) |
| Function to train the network on train data. More...
|
|
template<typename Dataloader > |
void | test (torch::jit::script::Module network, torch::nn::Linear lin, Dataloader &loader, size_t data_size) |
| Function to test the network on test data. More...
|
|
◆ load_data_from_folder()
std::pair<std::vector<std::string>, std::vector<int> > load_data_from_folder |
( |
std::vector< std::string > |
folders_name | ) |
|
Function to load data from given folder(s) name(s) (folders_name) Returns pair of vectors of string (image locations) and int (respective labels)
Arguments:
- folders_name (std::vector<std::string> type) - name of folders as a vector to load data from
◆ process_images()
std::vector<torch::Tensor> process_images |
( |
std::vector< std::string > |
list_images, |
|
|
int |
resize = 224 |
|
) |
| |
Arguments:
- list_images (std::vector<std::string> type) - list of image paths in a folder to be read
- resize (int type) - argument for resizing each image
◆ process_labels()
std::vector<torch::Tensor> process_labels |
( |
std::vector< int > |
list_labels | ) |
|
Arguments:
- list_labels (std::vector<int> list_labels) -
◆ read_data()
torch::Tensor read_data |
( |
std::string |
location, |
|
|
int |
resize = 224 |
|
) |
| |
Function to return image read at location given as type torch::Tensor.
Arguments:
- location (std::string type) - required to load image from the location
- resize (int type) - required to resize an image
◆ read_label()
torch::Tensor read_label |
( |
int |
label | ) |
|
Arguments:
- label (int type) - required to convert int to tensor
◆ test()
template<typename Dataloader >
void test |
( |
torch::jit::script::Module |
network, |
|
|
torch::nn::Linear |
lin, |
|
|
Dataloader & |
loader, |
|
|
size_t |
data_size |
|
) |
| |
◆ train()
template<typename Dataloader >
void train |
( |
torch::jit::script::Module |
net, |
|
|
torch::nn::Linear |
lin, |
|
|
Dataloader & |
data_loader, |
|
|
torch::optim::Optimizer & |
optimizer, |
|
|
size_t |
dataset_size |
|
) |
| |