our_knp/cats-dogs/test_features.py
int 8f43927575 Initial import: KNP experiments (examples, viz, cats-dogs, reports)
examples/ is based on KasperskyLab/knp at 55470ed6 with local changes
to the mnist-learn altai/blifat models, cuda-backend CMake and model_loader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 18:17:15 +03:00

16 lines
808 B
Python

"""Checks of descriptor geometry and edge-orientation behavior."""
import numpy as np
from features import descriptor
black = np.zeros((1, 3, 32, 32), dtype=np.uint8)
assert descriptor(black).shape == (1, 2048)
assert not descriptor(black).any()
vertical = np.broadcast_to(np.arange(32, dtype=np.uint8)[None, None, None, :] * 8, (1, 3, 32, 32))
horizontal = vertical.transpose(0, 1, 3, 2)
v, h = descriptor(vertical), descriptor(horizontal)
assert v.any() and h.any() and not np.array_equal(v, h)
assert (v[:, 1764:] == 0).all()
assert (descriptor(vertical, hybrid=True)[:, 1940:] == 0).all()
assert np.array_equal(v, descriptor(vertical.copy()))
assert (np.count_nonzero(descriptor(vertical, sparse=True), axis=1) <= 256).all()
print('Feature geometry, orientation, padding and determinism checks passed')