-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathESRGAN.cpp
44 lines (33 loc) · 1.1 KB
/
ESRGAN.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "ESRGAN.h"
using namespace Axodox::Infrastructure;
using namespace Ort;
using namespace std;
namespace Axodox::MachineLearning
{
ESRGAN::ESRGAN(OnnxEnvironment& environment, const std::string& ModelPath) :
_environment(environment),
_session(environment->CreateSession(ModelPath))
{
auto metadata = OnnxModelMetadata::Create(_environment, _session);
_session.Evict();
_logger.log(log_severity::information, "Loaded.");
_isUsingFloat16 = false;
}
Tensor ESRGAN::Upscale(const Tensor& ImageChunk, Threading::async_operation_source* async)
{
//Bind values
IoBinding bindings{ _session };
bindings.BindInput("input_img", ImageChunk.ToOrtValue());
bindings.BindOutput("upscaled", _environment->MemoryInfo());
//Run inference
_session.Run({}, bindings);
//Get result
auto outputValues = bindings.GetOutputValues();
auto result = Tensor::FromOrtValue(outputValues[0]).ToSingle();
return result;
}
void ESRGAN::Evict()
{
_session.Evict();
}
}