38static double max_abs_diff(
const float *a,
const float *b,
size_t count)
41 for(
size_t i = 0;
i < count;
i++)
43 const double d =
fabs((
double)a[
i] - b[
i]);
49static float *
read_f32(
const char *dir,
const char *
name,
size_t count)
59 float *buf =
malloc(count *
sizeof(
float));
60 const size_t got = buf ?
fread(buf,
sizeof(
float), count,
f) : 0;
75 fprintf(
stderr,
"usage: %s <model.anselnn> <fixture-dir> [N]\n", argv[0]);
78 const int n =
argc > 3 ?
atoi(argv[3]) : 96;
91 const size_t plane = (size_t)
n *
n;
94 float *
out =
calloc(plane,
sizeof(
float));
106 float *base =
read_f32(argv[2],
"fixture-base-planes.f32", plane * 5);
117 printf(
"binning contract: max abs err %.3g (tolerance 1e-6)\n",
bin_err);
131 printf(
"coarse stage parity: max abs err %.3g (tolerance 2e-4)\n",
c_err);
157 printf(
"end-to-end parity: max abs err %.3g (tolerance 5e-4)\n",
e2e_err);
182 const double ms = (
t1.tv_sec -
t0.tv_sec) * 1
e3 + (
t1.tv_nsec -
t0.tv_nsec) / 1
e6;
186 for(
size_t i = 0;
i < plane;
i++)
198 printf(
"parity vs torch: max abs err %.3g (at %zu: %.6f vs %.6f), rms %.3g | %.1f ms for %dx%d\n",
max_abs,
static dt_aligned_pixel_t rgb
const dt_colormatrix_t dt_aligned_pixel_t out
void dt_nn_model_free(dt_nn_model_t *m)
int dt_nn_model_in_channels(const dt_nn_model_t *m)
int dt_nn_model_coarse_in_channels(const dt_nn_model_t *m)
size_t dt_nn_unet_scratch_bytes(const dt_nn_model_t *m, int width, int height)
int dt_nn_unet_apply_stage(const dt_nn_model_t *m, int stage, const float *in, float *out, int width, int height, int apply_residual)
dt_nn_model_t * dt_nn_model_load(const char *path, char *err, size_t err_len)
__DT_CLONE_TARGETS__ void dt_nn_upsample_nearest(const float *in, int ch, int w, int h, int factor, float *out)
int dt_nn_model_coarse_out_channels(const dt_nn_model_t *m)
int dt_nn_model_alignment(const dt_nn_model_t *m)
int dt_nn_unet_apply(const dt_nn_model_t *m, const float *in, float *out, int width, int height)
__DT_CLONE_TARGETS__ void dt_nn_bin_planes(const float *planes, int pw, int ph, int bin, float *out_rgb, float *out_cnt)
int dt_nn_model_bin(const dt_nn_model_t *m, const int is_xtrans)
int dt_nn_model_out_channels(const dt_nn_model_t *m)
static float * read_f32(const char *dir, const char *name, size_t count)
static double max_abs_diff(const float *a, const float *b, size_t count)