-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nbeats): make nbeats able to handle signals that are more than 1D feat(nbeats): expose nbeats net definition in api
- Loading branch information
Showing
15 changed files
with
1,289 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,6 @@ | |
os.remove("predict/"+f) | ||
os.rmdir("predict") | ||
|
||
|
||
os.mkdir("train") | ||
os.mkdir("test") | ||
os.mkdir("predict") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef NATIVE_H | ||
#define NATIVE_H | ||
|
||
#include "native_net.h" | ||
#include "native_factory.h" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef NATIVE_FACTORY_H | ||
#define NATIVE_FACTORY_H | ||
|
||
#include "native_net.h" | ||
#include "./templates/nbeats.h" | ||
#include "../torchinputconns.h" | ||
#include "apidata.h" | ||
|
||
namespace dd | ||
{ | ||
class NativeFactory | ||
{ | ||
public: | ||
template <class TInputConnectorStrategy> | ||
static NativeModule *from_template(const std::string tdef, | ||
const APIData template_params, | ||
const TInputConnectorStrategy &inputc) | ||
{ | ||
(void)(tdef); | ||
(void)(template_params); | ||
(void)(inputc); | ||
return nullptr; | ||
} | ||
|
||
static bool valid_template_def(std::string tdef) | ||
{ | ||
if (tdef.find("nbeats") != std::string::npos) | ||
return true; | ||
return false; | ||
} | ||
|
||
static bool is_timeserie(std::string tdef) | ||
{ | ||
if (tdef.find("nbeats") != std::string::npos) | ||
return true; | ||
return false; | ||
} | ||
}; | ||
|
||
template <> | ||
NativeModule *NativeFactory::from_template<CSVTSTorchInputFileConn>( | ||
const std::string tdef, const APIData template_params, | ||
const CSVTSTorchInputFileConn &inputc) | ||
{ | ||
if (tdef.find("nbeats") != std::string::npos) | ||
{ | ||
std::vector<std::string> p = template_params.get("template_params") | ||
.get<std::vector<std::string>>(); | ||
return new NBeats(inputc, p); | ||
} | ||
else | ||
return nullptr; | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#ifndef NATIVE_NET_H | ||
#define NATIVE_NET_H | ||
|
||
#include "torch/torch.h" | ||
|
||
namespace dd | ||
{ | ||
|
||
class NativeModule : public torch::nn::Module | ||
{ | ||
public: | ||
virtual torch::Tensor forward(torch::Tensor x) = 0; | ||
virtual ~NativeModule() | ||
{ | ||
} | ||
/** | ||
* \brief see torch::module::to | ||
* @param device cpu / gpu | ||
* @param non_blocking | ||
*/ | ||
virtual void to(torch::Device device, bool non_blocking = false) | ||
{ | ||
torch::nn::Module::to(device, non_blocking); | ||
_device = device; | ||
} | ||
|
||
/** | ||
* \brief see torch::module::to | ||
* @param dtype : torch::kFloat32 or torch::kFloat64 | ||
* @param non_blocking | ||
*/ | ||
virtual void to(torch::Dtype dtype, bool non_blocking = false) | ||
{ | ||
torch::nn::Module::to(dtype, non_blocking); | ||
_dtype = dtype; | ||
} | ||
|
||
/** | ||
* \brief see torch::module::to | ||
* @param device cpu / gpu | ||
* @param dtype : torch::kFloat32 or torch::kFloat64 | ||
* @param non_blocking | ||
*/ | ||
virtual void to(torch::Device device, torch::Dtype dtype, | ||
bool non_blocking = false) | ||
{ | ||
torch::nn::Module::to(device, dtype, non_blocking); | ||
_device = device; | ||
_dtype = dtype; | ||
} | ||
|
||
virtual torch::Tensor cleanup_output(torch::Tensor output) | ||
{ | ||
return output; | ||
} | ||
|
||
virtual torch::Tensor loss(std::string loss, torch::Tensor input, | ||
torch::Tensor output, torch::Tensor target) | ||
= 0; | ||
|
||
virtual void update_input_connector(TorchInputInterface &inputc) | ||
{ | ||
(void)(inputc); | ||
} | ||
|
||
protected: | ||
torch::Dtype _dtype | ||
= torch::kFloat32; /**< type of data stored in tensors */ | ||
torch::Device _device | ||
= torch::DeviceType::CPU; /**< device to compute on */ | ||
}; | ||
} | ||
|
||
#endif |
Oops, something went wrong.