diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-11 23:13:43 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-11 23:13:43 +0100 |
| commit | 8ff8c56cd68d9e785cf6cb36ce1fc2bdc54ac15a (patch) | |
| tree | 09f44369f1926a8315c7d06ce050cd51d49c91a6 /tools/cnn_test.cc | |
| parent | 3530fcd7414ea24c8916adc1e490f71c02ac96f1 (diff) | |
fix: CNN bias accumulation and output format improvements
- Fix bias division bug: divide by num_positions to compensate for
shader loop accumulation (affects all layers)
- train_cnn.py: Save RGBA output preserving alpha channel from input
- Add --debug-hex flag to both tools for pixel-level debugging
- Remove sRGB/linear_png debug code from cnn_test
- Regenerate weights with corrected bias export
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/cnn_test.cc')
| -rw-r--r-- | tools/cnn_test.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/cnn_test.cc b/tools/cnn_test.cc index fa4394f..59f1d22 100644 --- a/tools/cnn_test.cc +++ b/tools/cnn_test.cc @@ -43,6 +43,7 @@ struct Args { bool output_png = true; // Default to PNG const char* save_intermediates = nullptr; int num_layers = 3; // Default to 3 layers + bool debug_hex = false; // Print first 8 pixels as hex }; // Parse command-line arguments @@ -80,6 +81,8 @@ static bool parse_args(int argc, char** argv, Args* args) { fprintf(stderr, "Error: layers must be in range [1, 10]\n"); return false; } + } else if (strcmp(argv[i], "--debug-hex") == 0) { + args->debug_hex = true; } else if (strcmp(argv[i], "--help") == 0) { return false; } else { @@ -99,6 +102,7 @@ static void print_usage(const char* prog) { fprintf(stderr, " --format ppm|png Output format (default: png)\n"); fprintf(stderr, " --layers N Number of CNN layers (1-10, default: 3)\n"); fprintf(stderr, " --save-intermediates DIR Save intermediate layers to directory\n"); + fprintf(stderr, " --debug-hex Print first 8 pixels as hex (debug)\n"); fprintf(stderr, " --help Show this help\n"); } @@ -437,6 +441,18 @@ int main(int argc, char** argv) { printf("Reading pixels from GPU...\n"); std::vector<uint8_t> pixels = rt.read_pixels(); + // Debug: print first 8 pixels as hex + if (args.debug_hex && !pixels.empty()) { + printf("First 8 pixels (BGRA hex):\n"); + for (int i = 0; i < 8 && i < width * height; ++i) { + const uint8_t b = pixels[i * 4 + 0]; + const uint8_t g = pixels[i * 4 + 1]; + const uint8_t r = pixels[i * 4 + 2]; + const uint8_t a = pixels[i * 4 + 3]; + printf(" [%d] 0x%02X%02X%02X%02X (RGBA)\n", i, r, g, b, a); + } + } + if (pixels.empty()) { fprintf(stderr, "Error: GPU readback failed\n"); wgpuTextureViewRelease(intermediate_views[0]); @@ -513,6 +529,18 @@ int main(int argc, char** argv) { std::vector<uint8_t> pixels = texture_readback_fp16_to_u8( device, queue, intermediate_textures[dst_idx], width, height); + // Debug: print first 8 pixels as hex + if (args.debug_hex && !pixels.empty()) { + printf("Layer %d first 8 pixels (BGRA hex):\n", layer); + for (int i = 0; i < 8 && i < width * height; ++i) { + const uint8_t b = pixels[i * 4 + 0]; + const uint8_t g = pixels[i * 4 + 1]; + const uint8_t r = pixels[i * 4 + 2]; + const uint8_t a = pixels[i * 4 + 3]; + printf(" [%d] 0x%02X%02X%02X%02X (RGBA)\n", i, r, g, b, a); + } + } + if (!pixels.empty()) { save_png(layer_path, pixels, width, height); } else { |
