'Try to Implement Multi Target C++ Regression using Pytorch
I tried to implement C+ Pytorch which is multiple target, my input dims (features) is 5 and output (label) is 4. I've changed the output vector to 4 in regression.cpp
auto output_tensors = torch::from_blob(outputs.data(), {int(outputs.size()), 4});
auto input_tensors = torch::from_blob(inputs.data(), {int(outputs.size()), int(inputs.size()/outputs.size())});
However, I made some errors on utils.h to push csv row to features and label
CSVRow row;
// Read and throw away the first row.
file >> row;
while (file >> row) {
features.emplace_back();
for (std::size_t loop = 0;loop < row.size()-4; ++loop) {
features.back().emplace_back(row[loop]);
}
features.back() = normalize_feature(features.back());
// Push final column to label vector
// label.push_back(row[row.size()-1]);
label.emplace_back();
for (std::size_t loop = row.size()-3;loop < row.size()+1; ++loop) {
label.back().emplace_back(row[loop]);
}
label.back() = normalize_feature(label.back());
}
// Flatten features vectors to 1D
std::vector<float> inputs = features[0];
int64_t total = std::accumulate(std::begin(features) + 1, std::end(features), 0UL, [](std::size_t s, std::vector<float> const& v){return s + v.size();});
inputs.reserve(total);
for (std::size_t i = 1; i < features.size(); i++) {
inputs.insert(inputs.end(), features[i].begin(), features[i].end());
}
for (std::size_t i = 1; i < label.size(); i++) {
inputs.insert(inputs.end(), label[i].begin(), label[i].end());
}
return std::make_pair(inputs, label);
}
Need advise, Thank you all!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
