-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
36 lines (28 loc) · 1015 Bytes
/
main.cpp
File metadata and controls
36 lines (28 loc) · 1015 Bytes
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
#include <chrono>
#include <fstream>
#include <iostream>
#include "Functions/loss.h"
#include "Functions/math_utils.h"
#include "Functions/nn_utils.h"
#include "Tensor/Tensor.h"
#include "Layers/BaseLayer.h"
#include "Layers/Kernels/x86/nn_kernel_cpu.h"
#include "Models/Sequential.h"
#include "Modules/Linear.h"
#include "Modules/ReLu.h"
#include "Modules/Loss/MSELoss.h"
#include "Optimizers/BaseOptimizer.h"
using namespace cortex;
int main() {
Tensor input({1, 12}, dtype::f32, DeviceType::cpu, true);
// input.initialize_with({2.0, 1.0, 0.1, 0.5, 2.0, 1.0});
input.initialize_with({-0.1875, 0.8026, 0.4352, 2.2096, 0.5503, 0.9852, 0.9854, 0.1866, -0.7313, -0.1727, -0.6427, 1.6189});
Tensor label({1, 12}, dtype::f32, DeviceType::cpu, true);
label.zeros();
label.at({0, 3}) = 1.0;
auto output = FCrossEntropyLoss(label, input);
output.backward();
std::cout << output.to_string() << std::endl;
std::cout << input.grad()->to_string() << std::endl;
return 0;
}