refactor: add type parameter to layer inputs

This commit is contained in:
2026-10-25 15:55:07 +01:00
parent aa438bfac7
commit 490661ebc0
6 changed files with 72 additions and 56 deletions
+6 -6
View File
@@ -11,7 +11,7 @@
#include <random>
#include <vector>
using network_type = cenet::network<cenet::tensor_input<1, 28, 28>,
using network_type = cenet::network<cenet::tensor_input<float, 1, 28, 28>,
cenet::conv2d_layer<8, 3, 1, 1>,
cenet::relu_layer,
cenet::maxpool_layer<>,
@@ -25,8 +25,8 @@ using network_type = cenet::network<cenet::tensor_input<1, 28, 28>,
static std::uniform_real_distribution<> dist(-1, 1);
struct data {
cenet::tensor<double, 1, 28, 28> xs;
cenet::mat<1, 10> ys;
cenet::tensor<float, 1, 28, 28> xs;
cenet::mat<1, 10, float> ys;
};
using dataset = std::vector<data>;
@@ -81,7 +81,7 @@ static dataset load_dataset(const char* labelsPath, const char* imagesPath) {
std::uint8_t pixel = 0;
images.read(reinterpret_cast<char*>(&pixel), sizeof(pixel));
set[i].xs[0][row][col] = static_cast<double>(pixel) / 255.0;
set[i].xs[0][row][col] = static_cast<float>(pixel) / 255.0F;
}
}
@@ -157,8 +157,8 @@ int main(void) {
const auto& output = mnistNet->feed(validationSet[i].xs);
for (std::size_t j = 0; j < 10; ++j) {
double diff = output.get()[0][j] - validationSet[i].ys[0][j];
totalLoss += diff * diff;
float diff = output.get()[0][j] - validationSet[i].ys[0][j];
totalLoss += diff * diff;
}
if (col_largest_idx(output.get()[0]) == col_largest_idx(validationSet[i].ys[0])) ++hits;