Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Update layers.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
xEricCardozo authored Oct 5, 2023
1 parent 7e7fd0e commit c3003e1
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions examples/layers.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
#include <CaberNet/CaberNet.h>

struct Encoder : public net::base::Model {
public:
Encoder() {
layers = {
new net::layer::Linear(64, 32),
new net::layer::ReLU(),
new net::layer::Linear(32, 16),
new net::layer::ReLU(),
};
}
struct Autoencoder : public net::Model<Autoencoder> {

Autoencoder() = default;

net::layer::Sequence encoder {
net::layer::Linear(784, 128, net::initializer::He),
net::layer::ReLU(),
net::layer::Linear(128, 64, net::initializer::He),
};

net::layer::Sequence decoder {
net::layer::Linear(64, 128, net::initializer::He),
net::layer::ReLU(),
net::layer::Linear(128, 784, net::initializer::He),
net::layer::LogSoftmax(1/*axis*/)
};

net::Tensor forward(net::Tensor x) {
return layers.forward(x);
x = encoder(x);
x = decoder(x);
return x;
}

net::layer::Sequence layers;
};


int main() {
Encoder encoder;
net::Tensor input({256, 64}); input.fill(net::initializer::He);
net::Tensor output = encoder.forward(input);
output.perform();
for(auto element : output) std::cout << element;
}
Autoencoder model;
net::Tensor x({1, 784}); x.fill(net::initializer::He);
net::Tensor y = model(x);
y.perform();
std::cout << y;
}

0 comments on commit c3003e1

Please sign in to comment.