src.tests.spconv3d_pwise_classif_save_load_test

Classes

SpConv3DPwiseClassifSaveLoadTest()

class src.tests.spconv3d_pwise_classif_save_load_test.SpConv3DPwiseClassifSaveLoadTest
Author:

Alberto M. Esmoris Pena

State-dict round-trip test for SpConv3DPwiseClassif.

The architecture has a recurring class of bugs where a constructor kwarg is read from kwargs but not persisted to __getstate__ / __setstate__ — the reload path then AttributeError``s on the first ``build_output / _build_encoder_hierarchy call (missing ssc3d-specific keys in from_config; uninitialised postwrap_kernel_res when the build flag is skipped; missing layer_by_layer / spconvs_per_encoder / binary_crossentropy defaults).

This test exercises the full __getstate____setstate__ cycle on three configurations to gate the entire bug class. Each subtest:

  1. Builds an architecture instance with non-default settings.

  2. Calls __getstate__ to serialise the configuration.

  3. Builds a fresh instance with the same kwargs (so it has all attributes initialised), and calls __setstate__(state).

  4. Verifies the restored instance still has every attribute the build_* methods need.

Configurations covered:

  • residual_strategy="sharedmlp" (production smoke default).

  • residual_strategy="ssc3d" (residual-via-spconv path).

  • residual_strategy=None (no-residual fallback path).

REQUIRED_ATTRS = ('layer_by_layer', 'spconvs_per_encoder', 'binary_crossentropy', 'fnames', 'nf', 'num_classes', 'submanifold_window', 'submanifold_features', 'downsampling_window', 'upsampling_window', 'max_depth', 'residual_strategy', 'feature_dim_divisor', 'dim_transform_activation')
__init__()

Basic configuration for any VL3D test.

Parameters:

name (str) – Test name

run()

Run the test.

Returns:

True if test is successfully passed, False otherwise.

Return type:

bool

subtest_round_trip_sharedmlp()

Round-trip the production-smoke configuration.

subtest_round_trip_ssc3d()

Round-trip the residual-via-spconv (ssc3d) path.

subtest_round_trip_no_residual()

Round-trip the no-residual fallback.

subtest_keras_save_load_real_graph()

Build a real Keras model, save it to disk, reload it via DL_CUSTOM_OBJECTS, and verify that:

  • load_model does not raise “Could not locate class” for any of the custom SpConv layers (i.e., every layer name is in DL_CUSTOM_OBJECTS or globally registered via @register_keras_serializable);

  • the loaded model and the source model produce the same forward outputs on a tiny dummy batch (the full model.save keras.models.load_model round-trip — including the encoder / decoder from_config paths — is correct).

The field-level round-trip subtests above stub arch.build to a no-op, so they never exercise the Keras-side reload path; this subtest is the one that does.

subtest_refuses_loss_class_mismatch_after_build()

Post-build overwrite_compilation_args with a loss whose binary_crossentropy flag differs from the built head must raise DeepLearningException.

subtest_kwargs_mutation_before_build_caught()

Mutating arch.compilation_args BEFORE build() must update the output head size at build time (the live re-derive in build_output() picks up the new flag).

subtest_missing_fields_default()

Older state dicts may not persist layer_by_layer, spconvs_per_encoder, or binary_crossentropy; __setstate__() must default-fill these so the checkpoint still loads. Simulated by emitting a state and deleting the three keys before re-applying.